You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe this signature is improperly restrictive. Consider this code:
parameters = dict(
map(str.strip, p.split('=', 1)) if '=' in p else (p.strip(), None)
for p in encoded_parameters.split(';')
) if encoded_parameters else {} # type: Dict
This is perfectly valid and works well. The code in the dict constructor doesn't actually require the iterable argument to contain two-tuples. It merely requires the iterable argument to contain values that can be unpacked each into exactly two values. (It's for k, v in iterable: ...). It can be a tuple, a list, or any iterable. However, my static type checker (mypy) complains that the types are incompatible (says it must be an iterable of Tuple[Any, Any]).
I'm not, however, certain what the ideal signature would be. Unfortunately, there's no Unpackable type. Some possible options:
Unfortunately I don't think that there is anything that typeshed can do at the moment. Type checkers can not assert that map() returns an iterable with at least two items of the correct type. I have opened discussion about this in python/typing#592.
The
dict
type has several supported constructor signatures. The one in question is this:I believe this signature is improperly restrictive. Consider this code:
This is perfectly valid and works well. The code in the
dict
constructor doesn't actually require the iterable argument to contain two-tuples. It merely requires the iterable argument to contain values that can be unpacked each into exactly two values. (It'sfor k, v in iterable: ...
). It can be a tuple, a list, or any iterable. However, my static type checker (mypy) complains that the types are incompatible (says it must be an iterable ofTuple[Any, Any]
).I'm not, however, certain what the ideal signature would be. Unfortunately, there's no
Unpackable
type. Some possible options:Thoughts?
The text was updated successfully, but these errors were encountered: