Closed
Description
Please provide more information to help us understand the issue:
- Problem
- I am using code to access module level variables through an alternative reference created on import time following this recipe.
mypy
reports an error on this, which I believe may be unnecessary.
- I am using code to access module level variables through an alternative reference created on import time following this recipe.
- Are you reporting a bug, or opening a feature request?
- Bug
- Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to simplify your case to a minimal repro.
# a.py
import sys
this = sys.modules[__name__]
this.serializable_classes = {} # a.py:15: error: Module has no attribute "serializable_classes"
setattr(this, "serializable_classes", {}) # alternative without mypy error
- What is the actual behavior/output?
error: Module has no attribute "serializable_classes"
- What is the behavior/output you expect?
- No error. It seems
mypy
applies rules for accessing a name from a module, while it really is an assignment. Why would the previous presence of a variable name in a module namespace matter under these circumstances?
- No error. It seems
- What are the versions of mypy and Python you are using?
$ tox -e mypy
mypy installed: mypackage==0.0.1,mypy==0.711,mypy-extensions==0.4.1,typed-ast==1.4.0
mypy run-test-pre: PYTHONHASHSEED='349'
mypy run-test: commands[0] | python --version
Python 3.7.3
- What are the mypy flags you are using? (For example --strict-optional)
# mypy.ini
[mypy]
warn_return_any = True
warn_unused_configs = True
# and some import ignores below
- Possibly relates issues
Metadata
Metadata
Assignees
Labels
No labels