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

compat: move check for closure cellvar update wrapper function #1092

Merged
merged 8 commits into from Feb 27, 2023
Merged

compat: move check for closure cellvar update wrapper function #1092

merged 8 commits into from Feb 27, 2023

Conversation

torque
Copy link
Contributor

@torque torque commented Jan 28, 2023

This sanity checking code ended up getting decoupled from the old implementation in a18b395 when a new, much simpler method was added. This check can fail spuriously in certain environments where it doesn't even need to be run because the newer approach is used.

This is noticeable when using python scripts compiled by nuitka. Since next-gen attrs uses slots on everything by default, the use of this fixup function is now pervasive, as well.

Here's the simplest reproduction I came up with (tested on Python 3.10.9 and nuitka 1.4)

# problem.py

# pip install attrs nuitka ordered-set
# nuitka3 --standalone --onefile problem.py
# running `python problem.py` without this patch succeeds
# running nuitka's output `problem.bin` without this patch fails. With this patch it succeeds.

import attrs

@attrs.define
class Parent:
    a: int

    def __attrs_post_init__(self):
        assert self.__class__ is Child, f"{self.__class__} is not {Child} ({id(self.__class__)}, {id(Child)})"

@attrs.define
class Child(Parent):
    b: float

    def __attrs_post_init__(self):
        assert __class__ is Child, f"{__class__} is not {Child} ({id(__class__)}, {id(Child)})"

        super().__attrs_post_init__()


Child(a=1, b=0.0)

Because nuitka compiles the python code to C, I guess it loses the introspection through the __code__ attribute, which is why the sanity check causes a problem. Fortunately, that's apparently entirely unneeded with any python version 3.8 or above.

(Annotated) Pull Request Check List

  • Added tests for changed code.

    I am not sure how to reasonably add a test case for this in-tree because my reproduction requires a heavyweight external process (compiling with nuitka).

  • Updated documentation for changed code.

    the changed code is an internal function with minimal documentation. There doesn't seem to be anything to add here

  • Changes (and possible deprecations) have news fragments in changelog.d.

This sanity checking code ended up getting decoupled from the old
implementation in a18b395 when a new,
much simpler method was added. This check can fail spuriously in
certain environments where it doesn't even need to be run because the
newer approach is used.

This is noticeable when using python scripts compiled by nuitka. Since
next-gen attrs uses slots on everything by default, the use of this
fixup function is now pervasive, as well.
@hynek hynek added this to the 23.1.0 milestone Feb 2, 2023
@hynek hynek merged commit b950cb8 into python-attrs:main Feb 27, 2023
@hynek
Copy link
Member

hynek commented Feb 27, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants