Bug report
Bug description:
_get_protocol_attrs and _proto_hook in Lib/typing.py unconditionally swallow failures from base.__annotations__ access like this:
try:
annotations = base.__annotations__
except Exception:
annotations = annotationlib.get_annotations(...)
import typing
class BrokenMeta(type):
def __getattribute__(cls, name):
if name == '__annotations__':
raise RuntimeError('simulated unrelated bug')
return super().__getattribute__(name)
class Base(metaclass=BrokenMeta):
pass
print(typing._get_protocol_attrs(Base))
This looks intended to only handle AttributeError (no annotations) or NameError (undefined name during deferred evaluation), but except Exception is far too broad and also swallows genuine, unrelated bugs. _proto_hook reproduces the same way through issubclass().
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
_get_protocol_attrsand_proto_hookinLib/typing.pyunconditionally swallow failures frombase.__annotations__access like this:This looks intended to only handle
AttributeError(no annotations) orNameError(undefined name during deferred evaluation), butexcept Exceptionis far too broad and also swallows genuine, unrelated bugs._proto_hookreproduces the same way throughissubclass().CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs