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
get_name() changes to handle class property case #3
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
78274a3
added (failing) test for get_name().
abendig c3e85cb
updated get_name() to handle properties.
abendig 5ab3e9b
added (failing) test for getlang() within class method.
abendig d4247e6
updated get_name() for test_get_name_class_method.
abendig File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
if isinstance(maybe_cls, type): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try replacing this line with:
... which should avoid recursion issues while still using the standard MRO. |
||
maybe_func = maybe_cls.__dict__[frame.f_code.co_name] | ||
else: | ||
maybe_func = maybe_cls.__class__.__dict__[frame.f_code.co_name] | ||
# If we have self, or a classmethod, we need the class name | ||
if (varname == 'self' or maybe_func.im_self == maybe_cls): | ||
if (varname in ('self', 'cls') or maybe_func.im_self == maybe_cls): | ||
cls_name = (getattr(maybe_cls, '__name__', None) | ||
or getattr(getattr(maybe_cls, '__class__', None), | ||
'__name__', None)) | ||
|
@@ -236,7 +238,7 @@ class UNSET(object): | |
>>> # Is good for checking default values | ||
>>> if {}.get('example', UNSET) is UNSET: | ||
... print "Key is missing." | ||
... | ||
... | ||
Key is missing. | ||
>>> # Has no length | ||
>>> len(UNSET) | ||
|
@@ -285,7 +287,7 @@ class Namespace(object): | |
>>> # Namespaces are iterable | ||
>>> for name, value in myns: | ||
... print name, value | ||
... | ||
... | ||
hello world | ||
example.value True | ||
>>> # Namespaces that are empty evaluate as False | ||
|
@@ -300,7 +302,7 @@ class Namespace(object): | |
>>> class MyDescriptor(object): | ||
... def __get__(self, instance, owner): | ||
... return 'Hello World' | ||
... | ||
... | ||
>>> myns.descriptor = MyDescriptor() | ||
>>> myns.descriptor | ||
'Hello World' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplejson is required for Pytool. See the comment about the 'for_json()' hook on line 75.