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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:20:12+00:00 2026-05-14T06:20:12+00:00

I’ve inherited some python code that contains a rather cryptic decorator. This decorator sets

  • 0

I’ve inherited some python code that contains a rather cryptic decorator. This decorator sets properties in classes all over the project. The problem is that this I have traced my debugging problems to this decorator. Seems it “fubars” all debuggers I’ve tried and trying to speed up the code with psyco breaks everthing. (Seems psyco and this decorator dont play nice). I think it would be best to change it.

def Property(function):
    """Allow readable properties"""
    keys = 'fget', 'fset', 'fdel'
    func_locals = {'doc':function.__doc__}
    def probeFunc(frame, event, arg):
        if event == 'return':
            locals = frame.f_locals
            func_locals.update(dict((k,locals.get(k)) for k in keys))
            sys.settrace(None)
        return probeFunc
    sys.settrace(probeFunc)
    function()
    return property(**func_locals)

Used like so:

class A(object):
    @Property
    def prop():
        def fget(self):
            return self.__prop
        def fset(self, value):
            self.__prop = value
    ... ect

The errors I get say the problems are because of sys.settrace. (Perhaps this is abuse of settrace ?)

My question: Is the same decorator achievable without sys.settrace. If not I’m in for some heavy rewrites.

  • 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-14T06:20:13+00:00Added an answer on May 14, 2026 at 6:20 am

    The same thing? No. You can’t do what that decorator does without magic like sys.settrace. (It technically doesn’t have to be sys.settrace, but using something else — like bytecode rewriting — wouldn’t be an improvement.) You can make it a lot simpler by doing, for example:

    def Property(f):  
        fget, fset, fdel = f()
        fdoc = f.__doc__
        return property(fget, fset, fdel, fdoc)
    
    class Foo(object):
        @Property
        def myprop():
            "Property docstring"
            def fget(self):  
                return 'fget' 
            def fset(self, x):
                pass
            def fdel(self):
                pass
            return fget, fset, fdel
    

    In Python 2.6 and later you can use a slightly different decorator, though:

    def Property(cls):
        fget = cls.__dict__.get('fget')
        fset = cls.__dict__.get('fset')
        fdel = cls.__dict__.get('fdel')
        fdoc = cls.__doc__
        return property(fget, fset, fdel, fdoc)
    

    And you would use it like so:

    class Foo(object):
        @Property
        class myprop(object):
            "Property docstring"
            def fget(self):
                return 'fget'
            def fset(self, x):
                pass
            def fdel(self):
                pass
    

    However, a more idiomatic way of doing this in Python 2.6 and later is like so:

    class Foo(object):
        @property
        def myprop(self):
            "Property docstring"
            return 'fget'
        @myprop.setter
        def myprop(self, x):
                pass
        @myprop.deleter
        def myprop(self):
                pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 432k
  • Answers 432k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you use the putExtras(Bundle) method of the Intent Bundle extras… May 15, 2026 at 2:32 pm
  • Editorial Team
    Editorial Team added an answer Check your migration files to see if the constraint was… May 15, 2026 at 2:32 pm
  • Editorial Team
    Editorial Team added an answer Assuming you want counts in descending order and titles ascending:… May 15, 2026 at 2:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.