Skip to content

_overload_dummy raises NotImplementedError, not RuntimeError#98351

Merged
JelleZijlstra merged 1 commit intopython:mainfrom
sobolevn:use-more-precise-exception-in-test-typing
Oct 20, 2022
Merged

_overload_dummy raises NotImplementedError, not RuntimeError#98351
JelleZijlstra merged 1 commit intopython:mainfrom
sobolevn:use-more-precise-exception-in-test-typing

Conversation

@sobolevn
Copy link
Member

Source:

cpython/Lib/typing.py

Lines 2536 to 2542 in eae7dad

def _overload_dummy(*args, **kwds):
"""Helper for @overload to raise when called."""
raise NotImplementedError(
"You should not call an overloaded function. "
"A series of @overload-decorated functions "
"outside a stub module should always be followed "
"by an implementation that is not @overload-ed.")

I've found this while looking for implicit abstract classes / methods in CPython.

Test was checking for RuntimeError, it is technically correct:

>>> NotImplementedError.__mro__
(<class 'NotImplementedError'>, <class 'RuntimeError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>)

But, we can be more precise. It is a good thing.
I am going to skip creating an issue for this, it is like a typo-fix :)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip issue skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants