Skip to content

Support chained assignment for type aliases #12995

@agryman

Description

@agryman

I'm running mypy 0.950. I found a problem when I upgraded from SymPy 1.9 to SymPy 1.10.1. Both versions contain the following chained type assignments:

Matrix = MutableMatrix = MutableDenseMatrix

This caused a problem in SymPy 1.10.1 because they enabled mypy type checking in that version.

This problem can easily be recreated in a simple file, see attached.

------- begin ---------
class A:
pass

a: A = A()

B = A

b: B = B()

D = C = A

c: C = C()
d: D = D()
-------- end --------

mypy reports the following errors:

$mypy bug_mypy_chained.py
bug_mypy_chained.py:16: error: Variable "bug_mypy_chained.C" is not valid as a type
bug_mypy_chained.py:16: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
bug_mypy_chained.py:17: error: Variable "bug_mypy_chained.D" is not valid as a type
bug_mypy_chained.py:17: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
Found 2 errors in 1 file (checked 1 source file)

bug_mypy_chained.py.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions