Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update builds signature inspection for python 3.11.4 change #497

Merged
merged 2 commits into from
Jun 30, 2023

Conversation

rsokl
Copy link
Contributor

@rsokl rsokl commented Jun 30, 2023

python/cpython#105080 updates the behavior of inspect.signature to walk through a class' mro in search of its signature, rather than just defer to the most recent definition of __new__.

This PR updates the signature inspection logic of builds to match this new behavior of inspect.signature across all versions of Python. I.e. this effectively serves as a backport.

Here is an example that exhibits this change in behavior:

class A:
    def __new__(cls, a: int):
        return object.__new__(cls)

class B(A):
    def __init__(self, b: float):  ...

class C(B):
    ...

Before:

The signature of A.__new__ was preferred over that of B.__init__ even though the latter is closer to C in the inheritance hierarchy.

>>> import inspect
>>> from hydra_zen import inspect
>>> inspect.signature(builds(c, populate_full_signature=True))
<Signature (a: int) -> None>

After:

C's signature is that of B.__init__

>>> import inspect
>>> from hydra_zen import inspect
>>> inspect.signature(builds(c, populate_full_signature=True))
<Signature (b: float) -> None>

…4 compat-breaking change to inspect.signature
@rsokl rsokl added this to the v0.11.0 milestone Jun 30, 2023
@rsokl
Copy link
Contributor Author

rsokl commented Jun 30, 2023

Merging with failures caused by a separate compatibility issue with the latest numpy

@rsokl rsokl merged commit aa93d44 into main Jun 30, 2023
@rsokl rsokl deleted the patch-inspect branch June 30, 2023 15:07
@rsokl rsokl added the deprecation A compatibility-breaking change label Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation A compatibility-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant