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
mypy is not able to infer that d["k"] is an int. We've been using mypy for the few months and this is really painful, since it's a very common programming pattern.
The text was updated successfully, but these errors were encountered:
I don't think I have ever seen this. (And we have several million lines of Python code.) Have you tried collections.defaultdict?
In any case this is very low priority, since it is already unsafe, and using type binder on function calls feels even worse. Maybe we should just close this?
Special casing dict.get seems conceptually not terrible, at least if this idiom turns out to be more common than we think now. But I agree that we don't have enough evidence to say that this is a widespread idiom.
This can be worked around using a cast, but then the assignment in the example needs to be written as d["k"] = cast(int, d["k"]) + 1 which is pretty verbose.
In this code:
mypy is smart enough to understand to infer that x is of type int in the last line. However is this example:
mypy is not able to infer that d["k"] is an int. We've been using mypy for the few months and this is really painful, since it's a very common programming pattern.
The text was updated successfully, but these errors were encountered: