-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
#7963 causes a serious regression
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
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong