[Top][All Lists]

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

Re: [PATCH 13/37] qapi/common.py: add notational type hints

From: John Snow
Subject: Re: [PATCH 13/37] qapi/common.py: add notational type hints
Date: Thu, 17 Sep 2020 16:06:27 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 9/17/20 2:18 PM, John Snow wrote:
Your type hint adds a restriction that wasn't there before.

Is there a better way?

I've settled on using the `object` type for now, which is slightly more restrictive than `Any`.

`Any` and `object` both allow any type of argument, but `Any` effectively creates a gradually typed boundary in which you are implicitly casting to whatever typed boundary it enters next.

`object` is an explicit cast to the most abstracted type; any further usage that is not supported the base object will be rejected.

This is nice, because if someone adds a call at or below the mcgen level, mypy will certainly complain that they are assuming too much about the type -- and they would be!

The rest of my series will now take this approach: prefer `object` to `Any`.


reply via email to

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