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

Confusion between class variable and instance variable when descriptor is used #1722

Open
3 tasks done
danabr opened this issue Aug 11, 2023 · 1 comment
Open
3 tasks done

Comments

@danabr
Copy link

danabr commented Aug 11, 2023

Prerequisites

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

Description

Consider the following program:

class ListDescriptor:
    def __set__(self, obj, value):
        obj.__dict__["x"] = value

class Test:
    x = ListDescriptor()

    def __init__(self):
        self.x = [1,2,3]

t = Test()
print(t.x)

The output from this program differs between CPython and IronPython.

Steps to Reproduce

  1. Run the above program

Expected behavior: Output should be [1, 2, 3].

Actual behavior: Output is <ListDescriptor object at 0x000000000000002B>.

Workarounds

You can work around this by explictly defining the __get__ method in ListDescriptor. However, we encountered this in third-party code that we would rather not modify if it could be avoided.

@slozier
Copy link
Contributor

slozier commented Aug 14, 2023

Note that there's already a test case that could be enabled which would cover this test_descr.test_set_and_no_get.

danabr added a commit to danabr/ironpython3 that referenced this issue Aug 15, 2023
This makes the first half of the test in test_descr.set_and_no_get pass.
The second part using metaclassses still fail.

I am pretty sure this is not the proper approach, but I don't know what
that would be.

See IronLanguages#1722.
danabr added a commit to danabr/ironpython3 that referenced this issue Aug 16, 2023
This makes the first half of the test in test_descr.set_and_no_get pass.
The second part using metaclasses still fails.

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

No branches or pull requests

2 participants