-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bc26deb
Add support for passing unbound class methods to `add_view`
sontek 4a7029f
Raise errors if unbound methods are passed in
sontek 6d46761
Don't need im_self
sontek 03a0d79
Clean up compat tests
sontek ce7c06a
Merge branch 'master' of https://github.com/Pylons/pyramid into allow…
sontek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Raise errors if unbound methods are passed in
- Loading branch information
commit 4a7029f6b313b65ba94d0726042ea3adbad38e81
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import unittest | ||
|
||
class TestUnboundMethods(unittest.TestCase): | ||
def test_old_style_bound(self): | ||
from pyramid.compat import is_unbound_method | ||
|
||
class OldStyle: | ||
def run(self): | ||
return 'OK' | ||
|
||
self.assertFalse(is_unbound_method(OldStyle().run)) | ||
|
||
def test_new_style_bound(self): | ||
from pyramid.compat import is_unbound_method | ||
|
||
class NewStyle(object): | ||
def run(self): | ||
return 'OK' | ||
|
||
self.assertFalse(is_unbound_method(NewStyle().run)) | ||
|
||
def test_old_style_unbound(self): | ||
from pyramid.compat import is_unbound_method | ||
|
||
class OldStyle: | ||
def run(self): | ||
return 'OK' | ||
|
||
self.assertTrue(is_unbound_method(OldStyle.run)) | ||
|
||
def test_new_style_unbound(self): | ||
from pyramid.compat import is_unbound_method | ||
|
||
class NewStyle(object): | ||
def run(self): | ||
return 'OK' | ||
|
||
self.assertTrue(is_unbound_method(NewStyle.run)) | ||
|
||
def test_normal_func_unbound(self): | ||
from pyramid.compat import is_unbound_method | ||
|
||
def func(): | ||
return 'OK' | ||
|
||
self.assertFalse(is_unbound_method(func)) |
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.
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.