Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

property decorators use sys.settrace(probeFunc) #32

Closed
GoogleCodeExporter opened this issue Sep 1, 2015 · 7 comments
Closed

property decorators use sys.settrace(probeFunc) #32

GoogleCodeExporter opened this issue Sep 1, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

Happy New Year!

Currently visvis code can not be debugged using the eclipse pydev debugger 
because of the custom property decorators that use sys.settrace.   There is a 
builtin property decorator, but I have not tested it yet with pydev.  

Have you considered using the builtin property decorator?


Original issue reported on code.google.com by geith.gm...@gmail.com on 2 Jan 2012 at 6:16

@GoogleCodeExporter
Copy link
Author

Happy new year Keith! 

Yes, I have considered that, but the builtin decorator with support for a 
setter is only supported from Python v2.6. That's why I've used a custom one 
(based on a decorator made by someone else. 

Also, we have the PropWithDraw decorator which is very convenient, although it 
might
be possible to implement something like that with the builtin property.

I don't like to replace the decorator with the builtin one until 2.6 is more 
mainstraim. And that might be a while; there are still a lot of people 
depending on Python 2.4. 

The only solution I can imagine is to replace it with a custom decorator that 
does not use sys.settrace. 

Original comment by almar.klein@gmail.com on 3 Jan 2012 at 7:20

@GoogleCodeExporter
Copy link
Author

I think, though I haven't tried, that you can use properties with setters in 
2.4, but you have to use the x = property(...) syntax.  This would mean quite a 
bit of rewriting, but I see no fundamental problem with this.  Alternatively, 
it's got to be possible to write a property decorator for 2.4 that would 
provide the capabilities of 2.6, since those are just syntactic sugar.  But 
again, every property would need to be rewritten.

This comment [http://code.activestate.com/recipes/410698/#c6] provides a way to 
do properties much like the current method in visvis, but without messing 
around with sys.settrace().  It would require a bit of boilerplate to be added 
to each property (explicitly labeling the docstring and adding the return 
locals() statement), but this might be accomplished with a clever sed script.

Original comment by rschr...@gmail.com on 18 Jan 2012 at 3:12

@GoogleCodeExporter
Copy link
Author

Mmm, I'm getting more convinced that we should remove the settrace stuff. It 
just isn't right to use it.

I looked at the link you send. I like the metaclass thing, but find the use of 
it (making a class definition to define a property) a bit too strange ...

I like the simple property where you have to return locals() at the end. It 
would be nice if that was not necessary, but I don't think it's possible 
(except with using settrace). It is very easy to make it use the docstring 
though! This means we only have to add "return locals()" at every property. 
That's not too bad. If you're ok with this change, I can do it tonight.

def newProp( fcn ):
    D = fcn()
    if not 'doc' in D:
        D['doc'] = fcn.__doc__
    return property( **D )


class Example(object):

    @newProp
    def myattr():
        """This is the doc string."""

        def fget(self):
            return self._value

        def fset(self, value):
            self._value = value

        def fdel(self):
            del self._value

        return locals()

Original comment by almar.klein@gmail.com on 18 Jan 2012 at 4:17

@GoogleCodeExporter
Copy link
Author

I knew there had to be a way to get the docstring easily, but I was wasting my 
time trying to convince locals() to return it instead of just reading it from 
the function itself.

The settrace method always made me a bit nervous, since I didn't know what it 
did.  I like this method better, although the need to return locals() is a bit 
annoying.  In the definition of newProp, we may want to check that D has no 
keys besides fget, fset, fdel, and doc.  I don't have a clear use case when 
this would happen, but it's not impossible that we'd want a helper function is 
a property somewhere.

Original comment by rschr...@gmail.com on 18 Jan 2012 at 9:21

@GoogleCodeExporter
Copy link
Author

I know a use case: someone accidentally typed the function name wrong, for 
instance "getf" instead of "fget". Would be nice to help the user point out 
what is wrong, instead of getting some weird error about keyword args :)

In theory, you could do a lot with this simple approach. You could define other 
functions or data besides fget, fset and fdel. I have no idea why, but it can 
be pretty powerful. But anyway, lets just limit to fget,fset,fdel and doc for 
now...

Original comment by almar.klein@gmail.com on 18 Jan 2012 at 10:12

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision c96c5f8b1db9.

Original comment by almar.klein@gmail.com on 19 Jan 2012 at 11:30

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Thank You, Thank You, Thank You!

I just pulled this and tested it in Eclipse with the pydev debugger.  It works 
great!

-Keith

Original comment by geith.gm...@gmail.com on 21 Jan 2012 at 2:42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant