-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Issue1035 getattr #1121
Issue1035 getattr #1121
Conversation
Looks good to me, thanks! Guess that's a good reason to build/test the 2.8.2 release again 😉 Could you also add an entry about this to the |
@@ -43,6 +44,19 @@ def _format_args(func): | |||
def _format_args(func): | |||
return inspect.formatargspec(*inspect.getargspec(func)) | |||
|
|||
class _GotAllAttrs(): |
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.
can we have a python version specific constant
CLASS_TYPES = ...
and just always implement isclass with a note to drop the implementation after python2.6 is dropped?
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.
That'd probably be (type, types.ClassType)
for Python2 and type
for Python 3. I'm fine with both solutions.
This didn't make it into 2.8.2, sorry - let's just do a 2.8.3 soon-ish instead of further delaying it 😉 |
c229c15
to
785f2a7
Compare
Changelog updated after confirming gitiquette. Still want to replace the capability test with a version test @RonnyPfannschmidt ? Also, should we assess usage of |
My preference is A check for the python version or unconditional implementation since that's simpler code |
Perhaps it would be better to only re-implement if sys.version_info[:2] == (2, 6):
def isclass(object):
"""Return true if the object is a class. Overrides inspect.isclass for python 2.6
because it will return True for objects which always return something
on __getattr__ calls (see #1035).
Backport of https://hg.python.org/cpython/rev/35bf8f7a8edc
"""
return isinstance(object, (type, types.ClassType)) This would make it obvious that it could be removed once |
+1 @nicoddemus Support py26 without affecting other versions. |
@nicoddemus sounds good 👍, we still might need to check other codepaths in pylib (afair it also uses isclass somewhere in py.code) |
785f2a7
to
5c8b292
Compare
5c8b292
to
88c8dd9
Compare
PR updated based on @nicoddemus's suggestion. |
@@ -43,6 +44,14 @@ def _format_args(func): | |||
def _format_args(func): | |||
return inspect.formatargspec(*inspect.getargspec(func)) | |||
|
|||
if sys.version_info[:2] == (2, 6): |
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.
@RonnyPfannschmidt @hpk42 how about creating a _pytest._compat
module to host this kind of "compatibility workaround" into a single place? There are other cases through the code where we do stuff differently based on python version. This would make simpler to remove code once support for a python version is dropped.
(this is out of the scope of this PR, just thought I would take this opportunity to mention it)
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.
good idea, please open a issue :)
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.
Cool: #1125
Thanks @tomviner! 😄 |
Fix for #1035
Have confirmed the test fails on Python 2.6 without the fix.
Appreciate feedback as to whether the python.py bit should be tidied away into a function?