Skip to content

1.15.0 regression: list.append false positive with Signals enum #18628

Open
@sobolevn

Description

@sobolevn

This code:

import signal
signals = []
if hasattr(signal, 'SIGALRM'):
    signals.append(signal.SIGALRM)
if hasattr(signal, 'SIGUSR1'):
    signals.append(signal.SIGUSR1)

Produces:

ex.py:7: error: Argument 1 to "append" of "list" has incompatible type "Literal[Signals.SIGUSR1]"; expected "Literal[Signals.SIGALRM]"  [arg-type]

Source: https://github.com/python/typeshed/blob/main/stdlib/signal.pyi

SIGALRM: Signals
SIGUSR1: Signals

It is a regression of 1.15.0, before this code was correct: https://mypy-play.net/?mypy=1.14.1&python=3.12&gist=24f0696ba047856ad7d932f4a7f25ec4
I don't see a reason, why two enum membres cannot be appended to a single list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions