Skip to content

Potential Redundant issubclass type checks that are always True #144302

@rc4typecheck

Description

@rc4typecheck

When statically analyzing and manually reviewing the code, I noticed a potential logic redundancy in /Lib/test/test_typechecks.py as follows:

def testSubclassBehavior(self):
    self.assertEqual(issubclass(SubInt, Integer), True)
    self.assertEqual(issubclass(SubInt, (Integer,)), True)
    self.assertEqual(issubclass(SubInt, SubInt), True)
    ......

The check 'issubclass(SubInt, Integer)' is always True, as SubInt is explicitly a subtype of Integer. And The check 'issubclass(SubInt, SubInt)' is indeed a self-check, which will always evaluate to True as any class is considered a subclass of itself.

There are several similar subclass self-checking cases in /Lib/test/test_isinstance.py:

self.assertEqual(True, issubclass(Super, Super))
self.assertEqual(True, issubclass(Child, Child))
self.assertEqual(True, issubclass(AbstractSuper, AbstractSuper))
self.assertEqual(True, issubclass(AbstractChild, AbstractChild))

I am not sure whether the code is intentional or it is an issue warranting a refactoring or fixing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtestsTests in the Lib/test dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions