Skip to content

Make SkipTest.__init__ reason positional-only#15703

Merged
JelleZijlstra merged 1 commit intopython:mainfrom
adamtheturtle:fix/skiptest-init-positional-only
May 6, 2026
Merged

Make SkipTest.__init__ reason positional-only#15703
JelleZijlstra merged 1 commit intopython:mainfrom
adamtheturtle:fix/skiptest-init-positional-only

Conversation

@adamtheturtle
Copy link
Copy Markdown
Contributor

SkipTest(reason="x") type-checks under the current stub but raises TypeError at runtime, because SkipTest doesn't override __init__ and so inherits BaseException.__init__(self, *args), where *args is positional-only.

from unittest import SkipTest

SkipTest(reason="x")
# mypy/pyright: ok ; runtime: TypeError: SkipTest() takes no keyword arguments

SkipTest has never defined its own __init__ on any 3.x version:

>>> "__init__" in SkipTest.__dict__
False
>>> SkipTest.__init__
<slot wrapper '__init__' of 'BaseException' objects>

So the override at stdlib/unittest/case.pyi:57 narrows the inherited variadic to one argument but drops the positional-only marker, which makes the stub admit calls the runtime rejects.

Adding , / keeps the documented "one reason string" narrowing while bringing the call shape back in line with the runtime.

SkipTest does not override __init__ on any 3.x Python; it inherits
BaseException.__init__(self, *args), where *args is positional-only
at runtime. Without the / marker, the stub claims SkipTest(reason='x')
is valid, but it raises TypeError at runtime.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit d541d5a into python:main May 6, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants