get_name() changes to handle class property case #3

Closed
wants to merge 4 commits into
from

Projects

None yet

2 participants

@abendig
abendig commented May 17, 2014

The get_name() code resulted in a RuntimeError (due to deep recursion), if the passed frame referred to a class property. The main fix was to not use getattr(), since that resulted in executing the property get code. This pull request contains the updated get_name() as well as two new test cases.

@shakefu shakefu commented on the diff May 18, 2014
pytool/json.py
@@ -10,7 +10,11 @@
"""
from datetime import datetime
-import simplejson as json
+try:
+ import simplejson as json
+except:
+ import json
@shakefu
shakefu May 18, 2014 Owner

Simplejson is required for Pytool. See the comment about the 'for_json()' hook on line 75.

@shakefu shakefu commented on the diff May 18, 2014
pytool/lang.py
@@ -31,10 +31,12 @@ def get_name(frame):
maybe_cls = frame.f_locals[varname]
# Get the actual method, if it exists on the class
- maybe_func = getattr(maybe_cls, frame.f_code.co_name)
@shakefu
shakefu May 18, 2014 Owner

Try replacing this line with:

maybe_func = object.__getattribute__(maybe_cls, frame.f_code.co_name)

... which should avoid recursion issues while still using the standard MRO.

@shakefu shakefu added a commit that referenced this pull request Aug 4, 2015
@shakefu Add test cases and fix from #3. 7730d42
@shakefu
Owner
shakefu commented Aug 4, 2015

Apparently this languished for over a year. These test cases and the fix are added.

@shakefu shakefu closed this Aug 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment