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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:09:29+00:00 2026-05-13T15:09:29+00:00

The following doesn’t work for some reason: >>> class foo(object): … @property … @classmethod

  • 0

The following doesn’t work for some reason:

>>> class foo(object):
...     @property
...     @classmethod
...     def bar(cls):
...             return "asdf"
... 
>>> foo.bar
<property object at 0x1da8d0>
>>> foo.bar + '\n'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'property' and 'str'

Is there a way to do this, or is my only alternative to resort to some kind of metaclass trickery?

  • 1 1 Answer
  • 1 View
  • 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-13T15:09:30+00:00Added an answer on May 13, 2026 at 3:09 pm

    If you want the descriptor property to trigger when you get an attribute from object X, then you must put the descriptor in type(X). So if X is a class, the descriptor must go in the class’s type, also known as the class’s metaclass — no “trickery” involved, it’s just a matter of completely general rules.

    Alternatively, you might write your own special-purpose descriptor. See here for an excellent “how-to” treaty on descriptors. Edit for example:

    class classprop(object):
      def __init__(self, f):
        self.f = classmethod(f)
      def __get__(self, *a):
        return self.f.__get__(*a)()
    
    class buh(object):
      @classprop
      def bah(cls): return 23
    
    print buh.bah
    

    emits 23, as desired.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any idea why the following doesn't work? (R3) o: make object! [ foo: does
I don't understand why the following doesn't work: def foo( x ): n =
For some reason the following doesn't crash like my program does, but I'm pretty
Is there a way? The following doesn't work: var customer = constructor.Entity<Customer>(); customer.Property(c =>
Not sure why the following doesn't work. I hope somebody can shed some light.
I would like to understand why the following doesn't work: public class HelloClass {
The following doesn't work: public string foo() { using (Random myRandomChoice = new Random())
following doesn't work: <?php class test{ const t = 10; public static $y =
I was surprised to see that the following doesn't work as expected. define('CONST_TEST','Some string');
The following doesn't work... (at least not in Firefox: document.getElementById('linkid').click() is not a function)

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.