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 7007687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:38:22+00:00 2026-05-27T21:38:22+00:00

Why does the __get__ method in a python descriptor accept the owner class as

  • 0

Why does the __get__ method in a python descriptor accept the owner class as it’s third argument? Can you give an example of it’s use?

The first argument (self) is self evident, the second (instances) makes sense in the context of the typically shown descriptor pattern (ex to follow), but I’ve never really seen the third (owner) used. Can someone explain what the use case is for it?

Just by way of reference and facilitating answers this is the typical use of descriptors I’ve seen:

class Container(object):
    class ExampleDescriptor(object):
        def __get__(self, instance, owner):
            return instance._name 
        def __set__(self, instance, value):
            instance._name = value
    managed_attr = ExampleDescriptor()

Given that instance.__class__ is available all I can think of is that explicitly passing the class has something to do with directly accessing the descriptor from the class instead of an instances (ex Container.managed_attr). Even so I’m not clear on what one would do in __get__ in this situation.

  • 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-05-27T21:38:23+00:00Added an answer on May 27, 2026 at 9:38 pm

    owner is used when the attribute is accessed from the class instead of an instance of the class, in which case instance will be None.

    In your example attempting something like print(Container.managed_attr) would fail because instance is None so instance._name would raise an AttributeError.

    You could improve this behavior by checking to see if instance is None, and it may be useful for logging or raising a more helpful exception to know which class the descriptor belongs to, hence the owner attribute. For example:

            def __get__(self, instance, owner):
                if instance is None:
                    # special handling for Customer.managed_attr
                else:
                    return instance._name 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use a class instance variable as an argument for a method
Does the method get called with a null value or does it give a
Assume you define a class, which has a method which does some complicated processing:
I have a Python 3 class method for rescaling values that looks like this:
What functionality does the yield keyword in Python provide? For example, I'm trying to
In Python, I'm trying to run a method in a class and I get
The Python documentation for unittest implies that the assertRaises() method can be used as
Possible Duplicate: Why does defining getitem on a class make it iterable in python?
Does anyone know why I get undefined method `my_method' for #<MyController:0x1043a7410> when I call
When a .Net service crashes, does the ServiceBase.OnStop method get called? Will the service

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.