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

  • Home
  • SEARCH
  • 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 8596855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:46:49+00:00 2026-06-12T00:46:49+00:00

To the question: Why can’t descriptors be instance attributes? it has been answered that:

  • 0

To the question:

Why can’t descriptors be instance attributes?

it has been answered that:

descriptor objects needs to live in the class, not in the instance

because that is the way that the __getattribute__ is implemented.

A simple example. Consider a descriptor:

class Prop(object):

    def __get__(self, obj, objtype=None):
        if obj is None:
            return self
        return obj._value * obj._multiplier

    def __set__(self, obj, value):
        if obj is None:
            return self
        obj._value = value

class Obj(object):

    val = Prop()

    def __init__(self):
        self._value = 1
        self._multiplier = 0

Consider the case in which each obj has multiple Prop: I would need to use unique names to identify the values and multipliers (Like here. Having a per instance descriptor object would allow to store the _multiplier (and the _value) in the descriptor itself, simplifying a few things.

To implement per instance descriptor attributes you need to either:

  1. create a per instance class See here
  2. override __getattribute__ See here

I am aware that similar questions have been raised before, but I have not found a real explanation:

  1. Why Python is designed this way?
  2. What is the suggested way to store information that the descriptor needs but is per instance?
  • 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-12T00:46:50+00:00Added an answer on June 12, 2026 at 12:46 am

    Plenty of advanced functionality only works when defined on a class rather than an instance; all of the special methods, for example. As well as making code evaluation more efficient, this makes clear the separation between instances and types which otherwise would tend to collapse (because of course all types are objects).

    I’m not sure how recommended this is, but you could in the instance store a mapping from descriptor instance to attribute value:

    class Prop(object):
         def __get__(self, obj, objtype=None):
            if obj is None:
                return self
            return obj._value * obj._multiplier[self]
    
        def __set__(self, obj, value):
            if obj is None:
                return self
            obj._value = value
    
    class Obj(object):
        val = Prop()
    
        def __init__(self):
            self._value = 1
            self._multiplier = {Obj.val: 0}
    

    This has obvious advantages over the other two suggested options:

    1. per-instance classes break object orientation and increase memory usage;
    2. overriding __getattribute__ is inefficient (as all attribute access must go through the overridden special method) and is fragile.

    As an alternative, you could use a proxy property:

    class PerInstancePropertyProxy(object):
        def __init__(self, prop):
            self.prop = prop
        def __get__(self, instance, owner):
            if instance is None:
                return self
            return instance.__dict__[self.prop].__get__(instance, owner)
        def __set__(self, instance, value):
            instance.__dict__[self.prop].__set__(instance, value)
    class Prop(object):
        def __init__(self, value, multiplier):
            self.value = value
            self.multiplier = multiplier
        def __get__(self, instance, owner):
            if instance is None:
                return self
            return self.value * self.multiplier
        def __set__(self, instance, value):
            self.value = value
    class Obj(object):
        val = PerInstancePropertyProxy('val')
        def __init__(self):
            self.__dict__['val'] = Prop(1.0, 10.0)
        def prop(self, attr_name):
            return self.__dict__[attr_name]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question Can I build a image database/library that has an e-commerce style checkout system
Question Can I style just a part of a single character? Meaning CSS attributes
I know this question can be answered by searching in google. But I have
Question: Can CMake generate build scripts that do not, in any way, use CMake?
Question: Can I override default functions in Javascript? Background: After figuring out that I
Th question: Can I re-use RadioButton objects over and over again in an child
Question: Can system internal process or module be described as an actor that performs
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
My question: Can I simply ignore all of that nonsense of static, media, collectstatic
Question Can anyone recommend a library for Ocaml that offers an actor-based concurrency model

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.