IronLanguages / IronLanguages/ironpython3

Confusion between class variable and instance variable when descriptor is used

Open
#1,722 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

confirmed
Dominant language
C#
Stars
2.8k
Forks
316
Avg merge
1d 9h
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the descriptor example from the issue and compare its output with CPython. Trace IronPython's class and instance attribute lookup for descriptors, then verify that the program prints [1, 2, 3] without requiring a get workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.