Skip to content

regression: assignment of 'builtins.type' now type-inferred as 'builtins.object' #9476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huguesb opened this issue Sep 24, 2020 · 1 comment · Fixed by #9481
Closed

regression: assignment of 'builtins.type' now type-inferred as 'builtins.object' #9476

huguesb opened this issue Sep 24, 2020 · 1 comment · Fixed by #9481
Assignees
Labels
bug mypy got something wrong

Comments

@huguesb
Copy link
Contributor

huguesb commented Sep 24, 2020

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
@huguesb huguesb added the bug mypy got something wrong label Sep 24, 2020
@gvanrossum
Copy link
Member

@TH3CHARLie Can you look into this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants