Skip to content

Import cycle with type aliasing causes invalid "Invalid type" #5275

Closed

Description

@emmatyping

Running stub checks with typeshed at fb92ee8 on master yielded the following:

[ethanhs@towerofart mypy]$ pytest -k testsamples
============================= test session starts ==============================
platform linux -- Python 3.6.5, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /home/ethanhs/mypy, inifile: pytest.ini
plugins: xdist-1.22.2, forked-0.2, cov-2.5.1
gw0 [2] / gw1 [2] / gw2 [2] / gw3 [2] / gw4 [2] / gw5 [2] / gw6 [2] / gw7 [2]
scheduling tests via LoadScheduling
.F                                                                       [100%]
=================================== FAILURES ===================================
___________________________ SamplesSuite.test_stubs ____________________________
[gw2] linux -- Python 3.6.5 /usr/bin/python
Sample check failed
----------------------------- Captured stdout call -----------------------------
typeshed/third_party/2and3/click/core.pyi:337: error: Invalid type "click.types._ConvertibleType"
typeshed/third_party/2and3/click/core.pyi:416: error: Invalid type "click.types._ConvertibleType"
===================== 1 failed, 1 passed in 13.15 seconds ======================

Ivan pointed out there is an import cycle, and it seems the cycle and type aliasing is giving mypy trouble.

Activity

  1. emmatyping commented on Jun 26, 2018

    @emmatyping
    MemberAuthor

    Okay I have a minimal repro:

    # a.pyi
    from b import Parameter
    
    class _ParamType:
        p: Parameter
    
    _ConvertibleType = _ParamType
    
    def convert_type(ty: _ConvertibleType):
        ...
    
    # b.pyi
    from a import _ConvertibleType
    
    class Parameter:
        type: _ConvertibleType  # error: Invalid type "a._ConvertibleType
    

    running mypy a.pyi (0.610 and master).

  2. ilevkivskyi commented on Jun 26, 2018

    @ilevkivskyi
    Member

    Great! It is much easier to fix when there is a repro. I raise priority to high since the problems with import cycles can be quite annoying.

  3. self-assigned this
    on Jun 26, 2018
  4. added a commit that references this issue on Sep 21, 2018
    792bcdc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions