Skip to content

Prefer __new__ over __init__ for determining callable type of a class #5647

Open

Description

@msullivan

#5642 made __new__ chosen in more situations but __init__ is still chosen when
one class defines both. The difficulty is that typeshed has a bunch of dodgy __new__
annotations that need to be cleaned up first.

Activity

  1. hauntsaninja commented on Feb 25, 2020

    @hauntsaninja
    Collaborator

    Here's an example (simplified from a post in the gitter today) where we get a terrible error message because IntEnum subclasses int.

    ~/delete λ cat test34.py
    from enum import IntEnum
    
    IntEnum("Fruit", "Apple Pear")
    ~/delete λ mypy test34.py
    test34.py:3: error: No overload variant of "IntEnum" matches argument types "str", "str"
    test34.py:3: note: Possible overload variant:
    test34.py:3: note:     def IntEnum(self, x: Union[str, bytes, bytearray], base: int) -> IntEnum
    test34.py:3: note:     <1 more non-matching overload not shown>
    Found 1 error in 1 file (checked 1 source file)
    

    Curious if you remember what the problematic typeshed __new__s are?

  2. added 3 commits that reference this issue on Nov 3, 2024
    ce89220
    5a40f11
    ee93b0b
  3. added a commit that references this issue on Dec 27, 2024
    137dd74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions