|
From: | John Snow |
Subject: | Re: [PULL 3/5] qemu-iotests: 300: Add test case for modifying persistence of bitmap |
Date: | Mon, 15 Feb 2021 14:00:23 -0500 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 |
On 2/15/21 1:25 PM, Eric Blake wrote:
-BlockBitmapMapping = List[Dict[str, Union[str, List[Dict[str, str]]]]] +BlockBitmapMapping = List[Dict[str, + Union[str, + List[Dict[str, + Union[str, Dict[str, bool]]]]]]]
That looks *very* beefy.Is the Union because that union is valid for every key, or because every key has a potentially different value that is specific to that key?
if it's the latter, I'd ditch the Union and just go with: Dict[str, object], or Dict[str, Any]object: will allow any type, but keeps strict checking enabled. If you try to use that value later on without a cast, mypy will warn you if you are using it in a manner not guaranteed by the "object" type. Can be useful if you are passing values to a function that already does RTTI to determine behavior.
Any: Also allows any type, but enables gradual typing. If you later "assume" the type of this value, mypy will say nothing. Can be useful when you've just got a job to do and the right tool would have been a recursive type or a TypedDict (unavailable in Python 3.6.)
--js
[Prev in Thread] | Current Thread | [Next in Thread] |