Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
New-style classes for python2.7 #2147
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,
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.
It would be nice if all classes would be new-style classes, i.e. explicitly inheriting from
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
So, explicit mentioning of
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.
referenced this issue
Jan 9, 2017
Hi Guys! Have one question about inheritance from
Should It be also changed? Or there is a 'special' logic behind this?
@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 ;).