Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-104050: Argument clinic: Add annotations to the LandMine class
  • Loading branch information
AlexWaygood committed May 19, 2023
commit 5b0a76bede0b49fd8926607e648fcc539b98cde0
20 changes: 12 additions & 8 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand Down Expand Up @@ -2554,17 +2554,21 @@ 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 '<LandMine ' + repr(self.__message__) + ">"

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__)
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):
Expand Down