On 25.03.20 00:20, John Snow wrote: > Representing nested, recursive data structures in mypy is notoriously > difficult; the best we can reliably do right now is denote the atom > types as "Any" while describing the general shape of the data. > > Regardless, this fully annotates the log() function. > > Typing notes: > > TypeVar is a Type variable that can optionally be constrained by a > sequence of possible types. This variable is bound per-invocation such > that the signature for filter=() requires that its callables take e.g. a > str and return a str.
So it works like a generic, except that its declaration isn’t part of and thus local to the function. Interesting. Not sure if I like it, but, well, it’s Python. (Seems to me on the same level of “Interesting” as the “Don’t use an empty list as a default argument” thing.[1]) > Signed-off-by: John Snow <js...@redhat.com> > --- > tests/qemu-iotests/iotests.py | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) Haha. I can’t help but find it funny how my “I won’t complain, but I feel like some people might want this to be two patches” led to this “If I’m going to make a dedicated patch for this, I might as well go all the way” patch. It’s quite cool. Reviewed-by: Max Reitz <mre...@redhat.com> [1] I just read an article on that thing again (empty lists as default argument), which claims that this is in fact a very useful feature of Python. This makes me want to go on another rant, but I’ve learned enough restraint by now not to.
signature.asc
Description: OpenPGP digital signature