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: Add type annotations to sentinels in Argument Clinic
  • Loading branch information
erlend-aasland committed May 17, 2023
commit 3b12493e01d29daccff0f06aa037f77080fa77a4
27 changes: 11 additions & 16 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import contextlib
import copy
import cpp
import enum
import functools
import hashlib
import inspect
Expand All @@ -28,7 +29,7 @@

from collections.abc import Callable
from types import FunctionType, NoneType
from typing import Any, NamedTuple, NoReturn, Literal, overload
from typing import Any, Final, NamedTuple, NoReturn, Literal, overload

# TODO:
#
Expand Down Expand Up @@ -58,25 +59,19 @@
"return_value",
}

class Unspecified:
def __repr__(self) -> str:
return '<Unspecified>'

unspecified = Unspecified()

class Sentinels(enum.Enum):
unspecified = "unspecified"
NULL = "null"
unknown = "unknown"

class Null:
def __repr__(self) -> str:
return '<Null>'

NULL = Null()
return f"<{self.value.capitalize()}>"


class Unknown:
def __repr__(self) -> str:
return '<Unknown>'

unknown = Unknown()
unspecified: Final = Sentinels.unspecified
NULL: Final = Sentinels.NULL
unknown: Final = Sentinels.unknown

sig_end_marker = '--'

Expand Down Expand Up @@ -2690,7 +2685,7 @@ def __init__(self,
*, # Keyword only args:
c_default: str | None = None,
py_default: str | None = None,
annotation: str | Unspecified = unspecified,
annotation: str | Literal[Sentinels.unspecified] = unspecified,
unused: bool = False,
**kwargs
):
Expand Down