Skip to content

Remove old-style classes from tests #99430

Closed
@sobolevn

Description

@sobolevn

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.

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions