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
Since mypy is able to infer MyAbstractType from the dictionary in the first snippet, I believe that it should be also able to infer Type[MyAbstractType] since the dictionary values are not instances but class names.
There are two potential ways to improve the situation:
Infer Type[X] as the value type instead of a callable type.
Make it possible to instantiate an abstract type object represented as a callable type.
The first option is harder to implement and is not backward compatible, so my preference would be option 2.
A potential way to implement 2 would be to only flag as errors direct calls to an ABC type object (e.g. MyAbstractType()). If the callee is any other kind of expression or a variable, mypy wouldn't complain, since it could actually be a reference to a concrete derived class at runtime.
More details about ways to implement option 2. There may be a really simple way: set the from_type_type flag to True, when computing join and meet of callables (probably unless some/all items represent an abstract class object).
This assumes both abstract and all concrete implementations are in the same model.
Has someone tried appending to the mapping?
Each concrete implementation would append itself to the mapping?
Seems like a lot of contortions to silence this error.
Note - it took a handful of searches to end up here.
Stopped at along the way... : bugs #1843, #3048, #5135, and #6586.
The above example does not pass the type check as-is.
I need to change it to pass the type check as follows:
Since mypy is able to infer
MyAbstractType
from the dictionary in the first snippet, I believe that it should be also able to inferType[MyAbstractType]
since the dictionary values are not instances but class names.My setup: Python 3.8.0 + mypy 0.750
Related issues/PRs:
The text was updated successfully, but these errors were encountered: