diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 3d4961e6e7d7dd..9b5c6333bfb1e4 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -29,7 +29,7 @@ from collections.abc import Callable from types import FunctionType, NoneType -from typing import Any, Final, NamedTuple, NoReturn, Literal, overload +from typing import TYPE_CHECKING, Any, Final, NamedTuple, NoReturn, Literal, overload # TODO: # @@ -2554,17 +2554,24 @@ def get_displayname(self, i): class LandMine: # try to access any - def __init__(self, message): + def __init__(self, message: str) -> None: self.__message__ = message - def __repr__(self): + def __repr__(self) -> str: return '" - def __getattribute__(self, name): - if name in ('__repr__', '__message__'): - return super().__getattribute__(name) - # raise RuntimeError(repr(name)) - fail("Stepped on a land mine, trying to access attribute " + repr(name) + ":\n" + self.__message__) + # Type checkers wouldn't check attribute access on instances of this class properly + # if they saw it had a __getattribute__ method, + # so pretend to type checkers that the __getattribute__ method doesn't exist + if not TYPE_CHECKING: + def __getattribute__(self, name): + if name in ('__repr__', '__message__'): + return super().__getattribute__(name) + # raise RuntimeError(repr(name)) + fail( + f"Stepped on a land mine, trying to access attribute " + f"{name!r}:\n{self.__message__}" + ) def add_c_converter(f, name=None):