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
After this commit, the use of from __future__ import annotations causes assignments of builtins.type to be typed as builtins.object, which prevents the assigned variable from being used as a callable later on
This is especially bad because the semantic analyzer is shared and does not maintain the state of __future__ flags on a per-module basis, therefore any file with that import will affect all files that are typechecked after it (which makes it hard to pinpoint in a large codebase, given the way the graph is processed...)
To Reproduce
Simple reproducer in a single file:
from __future__ import annotations
reveal_type(type)
_TYPE = type
reveal_type(_TYPE)
_TYPE('bar')
Expected Behavior
simple.py:2: note: Revealed type is 'Overload(def (o: builtins.object) -> builtins.type, def (name: builtins.str, bases: builtins.tuple[builtins.type], dict: builtins.dict[builtins.str, Any]) -> builtins.type)'
simple.py:4: note: Revealed type is 'Overload(def (o: builtins.object) -> builtins.type, def (name: builtins.str, bases: builtins.tuple[builtins.type], dict: builtins.dict[builtins.str, Any]) -> builtins.type)'
Actual Behavior
simple.py:2: note: Revealed type is 'Overload(def (o: builtins.object) -> builtins.type, def (name: builtins.str, bases: builtins.tuple[builtins.type], dict: builtins.dict[builtins.str, Any]) -> builtins.type)'
simple.py:4: note: Revealed type is 'builtins.object'
simple.py:5: error: "object" not callable
Your Environment
Mypy version used: 0.790+dev.720b77e2ded8c46b66647cdde9218769d33aec41 (or any commit thereafter)
Mypy command-line flags: --python-version 3.7
Mypy configuration options from mypy.ini (and other config files): N/A
Python version used: 3.7
Operating system and version: macOS 10.14
The text was updated successfully, but these errors were encountered:
Bug Report
#7963 causes a serious regression
After this commit, the use of
from __future__ import annotations
causes assignments ofbuiltins.type
to be typed asbuiltins.object
, which prevents the assigned variable from being used as a callable later onThis is especially bad because the semantic analyzer is shared and does not maintain the state of
__future__
flags on a per-module basis, therefore any file with that import will affect all files that are typechecked after it (which makes it hard to pinpoint in a large codebase, given the way the graph is processed...)To Reproduce
Simple reproducer in a single file:
Expected Behavior
Actual Behavior
Your Environment
--python-version 3.7
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: