FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104050: Argument clinic: Add annotations to the `LandMine` class by AlexWaygood · Pull Request #104648 · python/cpython · GitHub

/ cpython Public
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
23 changes: 15 additions & 8 deletions Tools/clinic/clinic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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,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 '<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__)
# 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):
Expand Down

Back | FazBrowse Home | New Git URL