Skip to content

Incorrect instantiation of incomplete ABC subclass in test_collections::validate_abstract_methods` #137463

@guilhermeleobas

Description

@guilhermeleobas

Bug report

Bug description:

The test for missing abstract methods in validate_abstract_methods incorrectly attempted to instantiate the generated class C with an argument (C(name)), which always raises a TypeError: C() takes no arguments. Although the test originally passes, it passes for the wrong reason.

def validate_abstract_methods(self, abc, *names):
methodstubs = dict.fromkeys(names, lambda s, *args: 0)
# everything should work will all required methods are present
C = type('C', (abc,), methodstubs)
C()
# instantiation should fail if a required method is missing
for name in names:
stubs = methodstubs.copy()
del stubs[name]
C = type('C', (abc,), stubs)
self.assertRaises(TypeError, C, name)

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtestsTests 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