-
-
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
New-style classes for python2.7 #2147
Comments
Why would it break 2.6 compatibility? |
we would mainly break behaiviour compatibility, i propose we wed this out while introducing attrs |
New style classes have been introduced a long time ago; I remember using new-style classes was the recommendation for all objects at the time when I started learning Python, and that was in Python 2.4. This document says new-style classes were introduced in New-style classes affect mainly very special use-cases (like
But I don't know currently how it would break compatibility with 2.6... @nolar do you have any exmaples or references on how changing that would break things in 2.6 but not in 2.7? Having said that, I'm not opposed to the idea at all, it will make the behavior in Python 2 and 3 more consistent; I never worried about this before because the differences are very subtle and I didn't think they mattered on how pytest uses its objects. If we decide to change this, it must be done in the |
I'm not sure we need to tie one change to the other. Changing to new-style classes is just a matter of a simple find/replace and checking if all tests pass. 😁 |
Sorry, that was my mistake. I've misunderstood the sentence "New-style classes has been integrated into Python 2.7 and old-style classes has been removed in Python 3" at https://www.python.org/doc/newstyle/. If the new-style classes are there since 2.2, then backward compatibility will not be broken. |
@nolar would you like to contribute a PR? |
Hi Guys! Have one question about inheritance from Should It be also changed? Or there is a 'special' logic behind this? Thanks! |
@MichalTHEDUDE we dont patch vendored code, a pr to pluggy is welcome tho |
Okay, so I can cover all of discrepancies.
IMO in terms of |
@RonnyPfannschmidt @MichalTHEDUDE made that issue for you. |
@MichalTHEDUDE IMHO, it makes sense to do it for all classes in docs and tests, except all |
@tgoodlet so the same changes in @The-Compiler I will make it for everything. And about What do you think? PS. I also don't see any reasons this can't be done this week ;). |
Good point! |
New-style classes implemented for python 2.7 - #2147
Unfortunately we noticed that this might break user's expectations (#2398), so we are backing off this change for now until we can properly follow our deprecation policy in order to introduce this again. |
The problem:
Pytest uses old-style classes everywhere. E.g.,
This causes unexpected behaviour in some cases. For example, when trying to get an item from a mark,
AttributeError
is raised (as in the old-style classes) instead ofTypeError
(as in the new-style classes).The old-style classes are long deprecated, and the modern libraries & young developers do not expect this weird behaviour in their code anymore. This causes errors when trying to integrate pytest with other libraries & frameworks. For instance, in Jinja template engine (pallets/jinja#631); but there may be other cases.
The solution:
It would be nice if all classes would be new-style classes, i.e. explicitly inheriting from
object
:Possible problems:
This will probably break the compatibility with python < 2.7 (officially 2.6+ is declared for pytest).
Also, in python3, the no-braces syntax is a new normal (again), but causes the new-style classes with implicit inheritance from
object
. The 2.7's new-style syntax is supported.So, explicit mentioning of
(object)
may be of use for python2.7 only. Hence, it should be discussed is it worth changing the code for this case.Notes:
Python 2.7.10.
pytest==3.0.3
The text was updated successfully, but these errors were encountered: