Skip to content

Remove old-style classes from tests #99430

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

Closed
6 of 7 tasks
sobolevn opened this issue Nov 13, 2022 · 0 comments
Closed
6 of 7 tasks

Remove old-style classes from tests #99430

sobolevn opened this issue Nov 13, 2022 · 0 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Nov 13, 2022

There are some cases inside tests when old-style classes are used together with new-style classes.
I think these cases should be removed, because there are no old-style classes anymore and we just have useless logic duplication in tests.

I've found several cases:

  • cpython/Lib/test/test_descr.py

    Lines 3264 to 3265 in 57be545

    class OldClass:
    __doc__ = DocDescr()
  • class s1:
    def __repr__(self):
    return '\\n'
    class s2:
    def __repr__(self):
    return '\\n'
    (it is actually duplicated after u prefix removal, but is very similar and should also be removed)
  • class A_new(object):
    "A new-style class."
    def A_method(self):
    "Method defined in A."
    def AB_method(self):
    "Method defined in A and B."
    def AC_method(self):
    "Method defined in A and C."
    def AD_method(self):
    "Method defined in A and D."
    def ABC_method(self):
    "Method defined in A, B and C."
    def ABD_method(self):
    "Method defined in A, B and D."
    def ACD_method(self):
    "Method defined in A, C and D."
    def ABCD_method(self):
    "Method defined in A, B, C and D."
    def A_classmethod(cls, x):
    "A class method defined in A."
    A_classmethod = classmethod(A_classmethod)
    def A_staticmethod():
    "A static method defined in A."
    A_staticmethod = staticmethod(A_staticmethod)
    def _getx(self):
    "A property getter function."
    def _setx(self, value):
    "A property setter function."
    def _delx(self):
    "A property deleter function."
    A_property = property(fdel=_delx, fget=_getx, fset=_setx,
    doc="A sample property defined in A.")
    A_int_alias = int
  • class Classic:
    pass
    class NewStyle(object):
    pass
    def f():
    pass
    class WithMetaclass(metaclass=abc.ABCMeta):
    pass
    tests = [None, ..., NotImplemented,
    42, 2**100, 3.14, True, False, 1j,
    "hello", "hello\u1234", f.__code__,
    b"world", bytes(range(256)), range(10), slice(1, 10, 2),
    NewStyle, Classic, max, WithMetaclass, property()]
  • class Classic:
    pass
    class NewStyle(object):
    pass
    def f():
    pass
    tests = [None, 42, 2**100, 3.14, True, False, 1j,
    "hello", "hello\u1234", f.__code__,
    NewStyle, range(10), Classic, max, property()]
  • cpython/Lib/test/test_gc.py

    Lines 546 to 547 in 57be545

    # boom__new and boom2_new are exactly like boom and boom2, except use
    # new-style classes.
  • class old_style_class():
    pass
    class new_style_class(object):
    pass
    (we should probably keep this one, because it tests more complex mechanics than one class possibly can)

I will send a PR.

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Nov 13, 2022
@sobolevn sobolevn self-assigned this Nov 13, 2022
sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 13, 2022
gpshead pushed a commit that referenced this issue Nov 13, 2022
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this issue Feb 11, 2024
…pythonGH-99432)

python 1 & 2 were a loong time ago.
(cherry picked from commit d329f85)

Co-authored-by: Nikita Sobolev <[email protected]>
serhiy-storchaka added a commit that referenced this issue Feb 11, 2024
…9432) (GH-115298)

python 1 & 2 were a loong time ago.
(cherry picked from commit d329f85)

Co-authored-by: Nikita Sobolev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant