Skip to content
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

Merged
merged 2 commits into from
Oct 9, 2015
Merged

Issue1035 getattr #1121

merged 2 commits into from
Oct 9, 2015

Conversation

tomviner
Copy link
Contributor

@tomviner tomviner commented Oct 7, 2015

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?

@The-Compiler
Copy link
Member

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 CHANGELOG please?

@@ -43,6 +44,19 @@ def _format_args(func):
def _format_args(func):
return inspect.formatargspec(*inspect.getargspec(func))

class _GotAllAttrs():
Copy link
Member

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?

Copy link
Member

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.

@The-Compiler
Copy link
Member

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 😉

jantman added a commit to jantman/awslimitchecker that referenced this pull request Oct 8, 2015
@tomviner tomviner force-pushed the issue1035-getattr branch 2 times, most recently from c229c15 to 785f2a7 Compare October 8, 2015 18:09
@tomviner
Copy link
Contributor Author

tomviner commented Oct 8, 2015

Changelog updated after confirming gitiquette. Still want to replace the capability test with a version test @RonnyPfannschmidt ?

Also, should we assess usage of inspect.isclass outside python.py, in case the Python 2.6 bug is waiting to cause issues for people implementing __getattr__?

@RonnyPfannschmidt
Copy link
Member

My preference is A check for the python version or unconditional implementation since that's simpler code

@nicoddemus
Copy link
Member

Perhaps it would be better to only re-implement isclass on py26?

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 py26 support is dropped, plus it will have the benefit of not having the chance to introduce collateral side-effects in other Python versions. 😄

@tomviner
Copy link
Contributor Author

tomviner commented Oct 9, 2015

+1 @nicoddemus Support py26 without affecting other versions.

@RonnyPfannschmidt
Copy link
Member

@nicoddemus sounds good 👍, we still might need to check other codepaths in pylib (afair it also uses isclass somewhere in py.code)

@tomviner
Copy link
Contributor Author

tomviner commented Oct 9, 2015

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):
Copy link
Member

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)

Copy link
Member

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 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool: #1125

nicoddemus added a commit that referenced this pull request Oct 9, 2015
@nicoddemus nicoddemus merged commit b052bec into pytest-dev:master Oct 9, 2015
@nicoddemus
Copy link
Member

Thanks @tomviner! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants