bpo-43988: Add test.support.check_disallow_instantiation() (GH-25757) · python/cpython@4f72526 (original) (raw)

`@@ -40,6 +40,7 @@

`

40

40

`"requires_IEEE_754", "requires_zlib",

`

41

41

`"anticipate_failure", "load_package_tests", "detect_api_mismatch",

`

42

42

`"check__all__", "skip_if_buggy_ucrt_strfptime",

`

``

43

`+

"check_disallow_instantiation",

`

43

44

`# sys

`

44

45

`"is_jython", "is_android", "check_impl_detail", "unix_shell",

`

45

46

`"setswitchinterval",

`

`@@ -1982,3 +1983,13 @@ def skip_if_broken_multiprocessing_synchronize():

`

1982

1983

`synchronize.Lock(ctx=None)

`

1983

1984

`except OSError as exc:

`

1984

1985

`raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")

`

``

1986

+

``

1987

+

``

1988

`+

def check_disallow_instantiation(testcase, tp, *args, **kwds):

`

``

1989

`+

"""

`

``

1990

`+

Helper for testing types with the Py_TPFLAGS_DISALLOW_INSTANTIATION flag.

`

``

1991

+

``

1992

`+

See bpo-43916.

`

``

1993

`+

"""

`

``

1994

`+

msg = f"cannot create '{tp.module}.{tp.name}' instances"

`

``

1995

`+

testcase.assertRaisesRegex(TypeError, msg, tp, *args, **kwds)

`