You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allowing typing.NoReturn as a return hint for __init__ methods #10342
Many projects using Boost.Python will employ its option to define classes exported to Python which aren't meant to be instantiated directly in Python, but rather via helper functions/methods, and attempts to instantiate these classes directly in Python will look like the above. These are created by defining a boost::python::class with boost::python::no_init, and interfacing with the Python API typically looks like the following:
>>>importMyBoostPythonModule# A binary library>>>>>># The final ancestor is `builtins.object`, just like standard Python classes.>>># Verify that this is `True`>>>MyBoostPythonModule.MyNoInitClass.__mro__
(MyBoostPythonModule.MyNoInitClass, Boost.Python.instance, object)
>>>MyBoostPythonModule.MyNoInitClass.__mro__[-1] isobjectTrue>>>>>># Bad attempt at instantiation>>># See https://github.com/boostorg/python/blob/f5d14ef15e98838b3cf18692d46c481287ed50d0/src/object/class.cpp#L656-L674>>>MyBoostPythonModule.MyNoInitClass()
Traceback (mostrecentcalllast):
...
RuntimeError: ThisclasscannotbeinstantiatedfromPython>>>>>># Example instance-getting function>>> type(MyBoostPythonModule.GetMyNoInitClass).__mro__
(Boost.Python.function, object)
>>>MyBoostPythonModule.GetMyNoInitClass() # OK<MyBoostPythonModule.MyNoInitClassat0x7fc56b2f25d0>
Having the ability to define stub classes which look like
changed the title [-]Allowing `typing.NoReturn` as the return hint for `__init__` methods[/-][+]Allowing `typing.NoReturn` as a return hint for `__init__` methods[/+]on Apr 20, 2021
This also recently came up in python/typeshed#5137 (comment). Annotating __init__ as NoReturn seems like a reasonable way to indicate that a class cannot be instantiated.
Activity
[-]Allowing `typing.NoReturn` as the return hint for `__init__` methods[/-][+]Allowing `typing.NoReturn` as a return hint for `__init__` methods[/+]JelleZijlstra commentedon Apr 20, 2021
This also recently came up in python/typeshed#5137 (comment). Annotating
__init__asNoReturnseems like a reasonable way to indicate that a class cannot be instantiated.AlexWaygood commentedon Aug 25, 2022
Implemented in #13480 🎉