Skip to content
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

import of constraints fails if done before subtypes #6329

Closed
SpamapS opened this issue Feb 4, 2019 · 3 comments
Closed

import of constraints fails if done before subtypes #6329

SpamapS opened this issue Feb 4, 2019 · 3 comments
Labels
priority-2-low refactoring Changing mypy's internals

Comments

@SpamapS
Copy link

SpamapS commented Feb 4, 2019

  • 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.
import mypy.constraints
  • What is the actual behavior/output?
(mypy) clint@clint-ThinkPad-X1-Carbon-6th:~$ pip install mypy
Collecting mypy
  Downloading https://files.pythonhosted.org/packages/fc/4b/b2376fffd1416b76da0708dd8c8ab46c80cd2364c42212059587ae92f1d8/mypy-0.660-py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 11.5MB/s 
Collecting mypy-extensions<0.5.0,>=0.4.0 (from mypy)
  Using cached https://files.pythonhosted.org/packages/4d/72/8d54e2b296631b9b14961d583e56e90d9d7fba8a240d5ce7f1113cc5e887/mypy_extensions-0.4.1-py2.py3-none-any.whl
Collecting typed-ast<1.3.0,>=1.2.0 (from mypy)
  Downloading https://files.pythonhosted.org/packages/52/6c/57ecbb2ecb80274b7f2b7f95d0937de310aa2e66839d7ae9436881525b23/typed_ast-1.2.0-cp36-cp36m-manylinux1_x86_64.whl (724kB)
    100% |████████████████████████████████| 727kB 10.9MB/s 
Installing collected packages: mypy-extensions, typed-ast, mypy
Successfully installed mypy-0.660 mypy-extensions-0.4.1 typed-ast-1.2.0
(mypy) clint@clint-ThinkPad-X1-Carbon-6th:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mypy.constraints
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/clint/v/mypy/lib/python3.6/site-packages/mypy/constraints.py", line 11, in <module>
    import mypy.subtypes
  File "/home/clint/v/mypy/lib/python3.6/site-packages/mypy/subtypes.py", line 971, in <module>
    return_constraint_direction: int = mypy.constraints.SUBTYPE_OF,
AttributeError: module 'mypy' has no attribute 'constraints'
>>> 
  • What is the behavior/output you expect?

imports of public modules should not cause AttributeErrors.

  • What are the versions of mypy and Python you are using?

mypy 0.660
python 3.6.7

Do you see the same issue after installing mypy from Git master?

No

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mypy.constraints
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/clint/src/misc/mypy/mypy/constraints.py", line 11, in <module>
    import mypy.subtypes
  File "/home/clint/src/misc/mypy/mypy/subtypes.py", line 971, in <module>
    return_constraint_direction: int = mypy.constraints.SUBTYPE_OF,
AttributeError: module 'mypy' has no attribute 'constraints'
>>> 
@SpamapS
Copy link
Author

SpamapS commented Feb 4, 2019

Note that with git installed, the mypy_django_plugin still fails because of the missing constraints module:

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mypy.checker import TypeChecker
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/clint/src/misc/mypy/mypy/checker.py", line 39, in <module>
    import mypy.checkexpr
  File "/home/clint/src/misc/mypy/mypy/checkexpr.py", line 45, in <module>
    from mypy.infer import infer_type_arguments, infer_function_type_arguments
  File "/home/clint/src/misc/mypy/mypy/infer.py", line 5, in <module>
    from mypy.constraints import infer_constraints, infer_constraints_for_callable
  File "/home/clint/src/misc/mypy/mypy/constraints.py", line 11, in <module>
    import mypy.subtypes
  File "/home/clint/src/misc/mypy/mypy/subtypes.py", line 971, in <module>
    return_constraint_direction: int = mypy.constraints.SUBTYPE_OF,
AttributeError: module 'mypy' has no attribute 'constraints'

@ilevkivskyi
Copy link
Member

Unfortunately, mypy has a bunch of import cycles. It is however not easy to fix, so your best bet is to move the import to function level.

@ilevkivskyi ilevkivskyi added refactoring Changing mypy's internals priority-2-low labels Feb 5, 2019
@SpamapS
Copy link
Author

SpamapS commented Feb 5, 2019

Thanks, the mypy_django_plugin had a new release yesterday that actually worked around this. :-P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-2-low refactoring Changing mypy's internals
Projects
None yet
Development

No branches or pull requests

2 participants