Skip to content

Mypy complains when [] is used for __slots__ definition #10870

Open
@sobolevn

Description

@sobolevn

Bug Report

Slot definition in a form of __slots__ = [] raise an error:

ex.py:2: error: Need type annotation for "__slots__" (hint: "__slots__: List[<type>] = ...")

To Reproduce

Run mypy on this code:

class A:
    __slots__ = []

Expected Behavior
I expect it to have the same effect as:

class A:
    __slots__ = ()

and to produce no errors.
Moreover, mypy already knows that __slots__ should contain str items only as shown here:

class A:
    __slots__ = [1, 2]

Outputs:

ex.py:2: error: List item 0 has incompatible type "int"; expected "str"
ex.py:2: error: List item 1 has incompatible type "int"; expected "str"

Refs Textualize/rich#1364

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationstopic-runtime-semanticsmypy doesn't model runtime semantics correctly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy