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

__setitem__ for __dict__ ignored #40821

Closed
vdanilov mannequin opened this issue Aug 25, 2004 · 3 comments
Closed

__setitem__ for __dict__ ignored #40821

vdanilov mannequin opened this issue Aug 25, 2004 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@vdanilov
Copy link
Mannequin

vdanilov mannequin commented Aug 25, 2004

BPO 1015792
Nosy @rhettinger
Files
  • test.py: Example
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2004-08-26.04:43:27.000>
    created_at = <Date 2004-08-25.05:50:00.000>
    labels = ['interpreter-core']
    title = '__setitem__ for __dict__ ignored'
    updated_at = <Date 2004-08-26.04:43:27.000>
    user = 'https://bugs.python.org/vdanilov'

    bugs.python.org fields:

    activity = <Date 2004-08-26.04:43:27.000>
    actor = 'nnorwitz'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2004-08-25.05:50:00.000>
    creator = 'vdanilov'
    dependencies = []
    files = ['1382']
    hgrepos = []
    issue_num = 1015792
    keywords = []
    message_count = 3.0
    messages = ['22207', '22208', '22209']
    nosy_count = 3.0
    nosy_names = ['nnorwitz', 'rhettinger', 'vdanilov']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1015792'
    versions = ['Python 2.3']

    @vdanilov
    Copy link
    Mannequin Author

    vdanilov mannequin commented Aug 25, 2004

    In python 2.3.3 this code cause assertion:

    class d(dict):
        _is_setted = None
        def __setitem__(self, k, v):
            self._is_setted = 1
     
    class test:
        def __init__(self):
            self.__dict__ = d()
             
    t = test()
    t.x = 2
    assert t.__dict__._is_setted == 1, 'no `__setitem__` calls'

    @vdanilov vdanilov mannequin closed this as completed Aug 25, 2004
    @vdanilov vdanilov mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Aug 25, 2004
    @vdanilov vdanilov mannequin closed this as completed Aug 25, 2004
    @vdanilov vdanilov mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Aug 25, 2004
    @rhettinger
    Copy link
    Contributor

    Logged In: YES
    user_id=80475

    Underneath the hood, test's setattr is accessing the
    dictionary directly instead of going through its __setattr__
    slot.

    While this one is fixable, I'm not sure it's really a bug.
    There are no documentation promises that things like setattr
    won't make direct accesses to the underlying dictionary.
    Python's implementation has tons of direct access code --
    the reasons include clarity, speed, avoidance of hard to
    debug code paths, or just not having been looked at in this way.

    In any case, I would not have expected old style classes
    like 'test' to know about new style subclasses.

    For the use cases modeled after the OP's code, overiding
    setattr in 'test' is likely the way to go.

    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Aug 26, 2004

    Logged In: YES
    user_id=33168

    I agree with Raymond. I think this pretty much the design
    and should not be fixed. Therefore, I'm closing this report.

    Viktor, if you disagree, you might try discussing this on
    comp.lang.python or brining up this issue on python-dev.
    Feel free to comment here if you would like clarifications.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant