Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9102429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:22:58+00:00 2026-06-17T01:22:58+00:00

class Foo(object): __slots__ = (‘a’,) class Bar(Foo): @property def a(self): return super(Bar, self).a super(Bar,

  • 0
class Foo(object):
    __slots__ = ('a',)

class Bar(Foo):
    @property
    def a(self):
        return super(Bar, self).a

 super(Bar, Bar()).a = 4

If I’m using this code, this doesn’t work:

>>> super(Bar, Bar()).a = 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'super' object has no attribute 'a'

Why?

According to the python docs, __slots__ are implemented :

__slots__ are implemented at the class level by creating descriptors (Implementing Descriptors) for each variable name. As a result, class
attributes cannot be used to set default values for instance variables
defined by __slots__; otherwise, the class attribute would overwrite
the descriptor assignment.

But descriptors can cope with inheritance (at least if written in pure python).

Does anyone get know, why this is not working with __slots__?

Edit: It seems like descriptors are generally not working with super(), if you’re trying to write (read works, though). So my question would rather be: Why are descriptors read-only, if invoked with super()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:22:59+00:00Added an answer on June 17, 2026 at 1:22 am

    super() doesn’t return the descriptor, it returns the result of getting the descriptor. It doesn’t return functions either, it returns the bound method; functions act as descriptors too, and their .__get__() method returns a method.

    Because there is no a defined on the instance, there is no value and the descriptor .__get__() raises an AttributeError.

    Things work if you define a on instances of Foo:

    class Foo(object):
        __slots__ = ('a',)
        def __init__(self):
            self.a = 'spam'
    

    So, accessing a __slots__ descriptor without a value raises an AttributeError:

    >>> class Foo(object):
    ...     __slots__ = ('a',)
    ... 
    >>> Foo.a
    <member 'a' of 'Foo' objects>
    >>> Foo().a
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: a
    >>> Foo.a.__get__(Foo(), Foo)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: a
    

    but give the instance a value, and the AttributeError goes away:

    >>> class Foo(object):
    ...     __slots__ = ('a',)
    ...     def __init__(self):
    ...         self.a = 'spam'
    ... 
    >>> Foo.a.__get__(Foo(), Foo)
    'spam'
    

    Now super() can find the result of the descriptor just fine (demonstrating with a different attribute name to not clobber self.a):

    >>> class Bar(Foo):
    ...     __slots__ = ('b',)
    ...     @property
    ...     def b(self):
    ...         return super(Bar, self).a
    ... 
    >>> Bar().a
    'spam'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have this: class foo(object): @property def bar(self): return 0 f = foo()
I have the following structure: class foo(object): class bar(object): def __init__(self, parent): self._parent=parent #this
I have following code: class Foo(object): def __init__(self): baz=self.bar(10) @staticmethod def bar(n): if n==0:
Consider the following Python (3.x) code: class Foo(object): def bar(self): pass foo = Foo()
E.g. is this possible? class Foo(object): class Meta: pass class Bar(Foo): def __init__(self): #
Class Bar inherits from Foo: class Foo(object): def foo_meth_1(self): return 'foometh1' def foo_meth_2(self): return
Consider the following python code: class Foo(object): def __init__(self, value): self._value = value @property
For example, suppose I have the code: class Foo(object): def bar(self, x): '''blah blah
If I have the following code: class Foo(object): bar = 1 def bah(self): print(bar)
Given is the following example: class Foo(object): def __init__(self, value=0): self.value=value def __int__(self): return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.