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

Inconsistent results with super and __getattribute__ #39013

Closed
grodr mannequin opened this issue Aug 5, 2003 · 3 comments
Closed

Inconsistent results with super and __getattribute__ #39013

grodr mannequin opened this issue Aug 5, 2003 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@grodr
Copy link
Mannequin

grodr mannequin commented Aug 5, 2003

BPO 783528
Nosy @devdanzin
Superseder
  • bpo-14965: super() and property inheritance behavior
  • Files
  • OP_example.py: OP's example, cleaned up
  • 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 2013-02-24.01:08:24.952>
    created_at = <Date 2003-08-05.14:19:12.000>
    labels = ['interpreter-core', 'type-bug']
    title = 'Inconsistent results with super and __getattribute__'
    updated_at = <Date 2013-02-24.01:08:24.951>
    user = 'https://bugs.python.org/grodr'

    bugs.python.org fields:

    activity = <Date 2013-02-24.01:08:24.951>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-02-24.01:08:24.952>
    closer = 'r.david.murray'
    components = ['Interpreter Core']
    creation = <Date 2003-08-05.14:19:12.000>
    creator = 'grodr'
    dependencies = []
    files = ['13063']
    hgrepos = []
    issue_num = 783528
    keywords = []
    message_count = 3.0
    messages = ['60365', '81870', '114254']
    nosy_count = 3.0
    nosy_names = ['grodr', 'ajaksu2', 'BreamoreBoy']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '14965'
    type = 'behavior'
    url = 'https://bugs.python.org/issue783528'
    versions = ['Python 2.7']

    @grodr
    Copy link
    Mannequin Author

    grodr mannequin commented Aug 5, 2003

    Consider the following scenario of property overriding:

    >>> class Test(object):
    ... 	def __init__(self, n):
    ... 		self.__n = n
    ... 	#Properties.
    ... 	def __get_n(self):
    ... 		return self.__n
    ... 	def __set_n(self, n):
    ... 		self.__n = n
    ... 	n = property(__get_n, __set_n)
    ... 	
    >>> a = Test(42)
    >>> a.n
    42
    >>> a.n = 32
    >>> a.n
    32

    Now, let us override the n property:

    >>> class Test2(Test):
    ... 	def __init__(self, n):
    ... 		super(Test2, self).__init__(n)
    ... 	#Properties.
    ... 	def __get_n(self):
    ... 		return "got ya!"
    ... 	def __set_n(self, value):
    ... 		print "No way, jose!"
    ... 	n = property(__get_n, __set_n)
    ... 
    >>> a = Test2(42)
    >>> a.n
    'got ya!'
    >>> a.n = 0
    No way, jose!
    >>> a.n
    'got ya!'
    >>> super(Test2, a).n
    42

    So far so good, super is working well with properties. But
    now consider the following inconsistencies:

    >>> super(Test2, a).__getattribute__('n')
    'got ya!'
    >>> super(Test2, a).n
    42

    Also:

    >>> super(Test, Test2).__getattribute__('n')
    <property object at 0x01103300>
    >>> super(Test, Test2).__getattribute__('n').__get__(a)
    'got ya!'
    >>> super(Test, Test2).n
    Traceback (most recent call last):
      File "<interactive input>", line 1, in ?
    AttributeError: 'super' object has no attribute 'n'

    The last one is particularly damaging, because:

    >>> super(Test2, a).n = 32
    Traceback (most recent call last):
      File "<interactive input>", line 1, in ?
    AttributeError: 'super' object has no attribute 'n'

    I think the above should work, but whatever’s the
    answer, together with the super(Test, Test2) odd
    results it does make impossible using super and setting
    properties together.

    Tested with the latest Python 2.3 in win2k.

    With my best regards,
    G. Rodrigues

    P.S: bug 729913 talks of similar issues at the end: super
    does not seem to intercept special methods.

    @grodr grodr mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Aug 5, 2003
    @devdanzin
    Copy link
    Mannequin

    devdanzin mannequin commented Feb 13, 2009

    Same behavior, is this a real issue?

    Current exception:
    TypeError: 'super' object has only read-only attributes (assign to .n)

    @devdanzin devdanzin mannequin added the type-bug An unexpected behavior, bug, or error label Feb 13, 2009
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Aug 18, 2010

    Closed as no response to msg81870.

    @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) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant