Skip to content

Signature for weakref __new__ incorrect? #9712

@alicederyn

Description

@alicederyn

The signature for weakref.ReferenceType.__new__ seems to be saying the arguments can be named:

def __new__(cls, o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...

If I try doing the following:

from weakref import ref

class Foo:
  pass

def callback(_):
  print("Deleted")

x = Foo()
y = ref(x, callback=callback)

pyright and mypy both seem happy with this, but in both Python 3.9 and 3.11 I get:

TypeError: ref() takes no keyword arguments

Should the parameters be renamed to __o and __callback to indicate they are positional-only?

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