[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v9 08/14] iotests: touch up log function signature

From: John Snow
Subject: Re: [PATCH v9 08/14] iotests: touch up log function signature
Date: Mon, 30 Mar 2020 13:43:22 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 3/30/20 8:28 AM, Max Reitz wrote:
> 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])

Ah, right, yes -- it's a Generic. That's the word.

You can create ... generic annotations, like "T" that aren't limited to
any types at all, and use it wherever you want in subsequent
annotations. They're local to each annotation.

In this case, I limit the types of what it can be and give it a name.

>> Signed-off-by: John Snow <address@hidden>
>> ---
>>  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.

Sometimes you just know the next question is going to be "But why didn't
you annotate _THIS_ part?" and the answer "Because it's sort of fiddly
and kind of hard and I'm lazy" isn't going to fly too far...

> Reviewed-by: Max Reitz <address@hidden>
> [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.

It's absurd and should be removed from the language. What this people
actually want is the concept of a static local.

But that's a C thing, so they'll pretend they definitely don't want it
for years until they come up with a new name for it, and then it will be
OK and it will be everyone's favorite new feature.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]