Skip to content

deprecated raises spurious TypeError on classes which define only __new__ #192

@TeamSpen210

Description

@TeamSpen210

If @deprecated is applied to a class which defines __new__ but not __init__, it applies this check from object.__new__(), causing a TypeError from code that otherwise works fine:

from typing_extensions import deprecated
  
@deprecated("something")
class OnlyHasNew:
     def __new__(cls, a: int, b: float) -> 'OnlyHasNew':
        obj = object.__new__(cls)
        obj.a = a
        obj.b = b
        return obj

OnlyHasNew(1, 2)  # TypeError: OnlyHasNew() takes no arguments

It seems like that check should be moved into the else: branch there. I originally found this when trying to deprecate a NamedTuple class, which is potentially a more likely way to run into this issue.

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