Skip to content

List concatenation involving subclasses (zmypy differs from mypy) #201

@efroemling

Description

@efroemling

I stumbled across this case where zmypy gets different results than mypy:

class A:
    pass

class B(A):
    pass

# Mypy/Pyrefly allows this, but zmypy does not:
objs: list[A] = [A()] + [B()]

# Interestingly zmypy infers objs2 to be a list[A] here;
# it only errors if we annotate it as such.
objs2 = [A()] + [B()]
reveal_type(objs2)
% mypy test.py 
test.py:14: note: Revealed type is "builtins.list[test.A]"
Success: no issues found in 1 source file

% zmypy test.py
test.py:9: error: Unsupported operand types for + ("list[A]" and "list[B]")  [operator]
test.py:14: note: Revealed type is "builtins.list[test.A]"
Found 1 errors in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions