-
Notifications
You must be signed in to change notification settings - Fork 888
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
Alert the user if they are using an unbound class methods to add_view
#1498
Conversation
Can you fix the example above such that it shows a "normal" signature for the |
Other than that, LGTM. |
@tseaver The |
Ah, you mean in the test? Yes, I'd neglected to think about the "passed to |
@tseaver Yeah, the example in my comment was an error, I fixed that. But the test should be accurate |
This worries me. In Python3 unbound methods do not exist, so when you do |
@mmerickel Thats the inconsistent API part of Pyramid I was talking about. If you use I've updated the test to blow up on py3x but the only way I can think to fix it will only work in Python 3.3+, Python 3.1 and 3.2 wont work. So this might be something we can't do since Python3x doesn't have the feature that Python2x does |
Interesting, I have no idea why coverage dropped there. Those lines are all marked |
@tseaver @mmerickel Rather than trying to support this (since getting the class of a class function is pretty much impossible in py3), I decided to just raise a cleaner exception so that it is obvious that you are using the API wrong:
|
add_view
add_view
|
||
if not is_bound and inspect.isroutine(fn): | ||
spec = inspect.getargspec(fn) | ||
has_self = len(spec.args) > 0 and spec.args[0] == 'self' |
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.
Assuming they use the convention of "self" as the first method argument and that they never accidentally use it on something else. I'm all in favor of better feedback so long as it doesn't break someone's valid code. This is probably esoteric enough to not matter but I had to bring it up. Thoughts?
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.
It's interesting that you brought this up, because when i first read over this code I had the same question, but I let it go because I thought that if someone isn't using self
, they are writing very unpythonic code...
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.
Yeah, and they will just continue getting the existing poor behavior if they don't use self
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.
We can't try and save the user from themselves every time. I think with the fixes you (@sontek) added we have already helped out 95% of the people that might make a mistake, for the rest we will get a ticket or someone asking for help on IRC.
👍 |
@sontek can you merge master into this so I can hit the little green button? |
…_class_method_directly Conflicts: pyramid/compat.py
@mmerickel Its merged with master now |
Not a fan of you slowly pep-8ing the code in these PRs, but thanks anyway! |
Alert the user if they are using an unbound class methods to `add_view`
All of the extra whitespace changes are noise and make it difficult to see the meat in the changeset. |
This prevents the following from giving an unrecognizable error:
Before this PR you would get the exception: