diff --git a/stdlib/_decimal.pyi b/stdlib/_decimal.pyi index 9fcc08dbb..cdd0268a1 100644 --- a/stdlib/_decimal.pyi +++ b/stdlib/_decimal.pyi @@ -17,20 +17,13 @@ from decimal import ( Rounded as Rounded, Subnormal as Subnormal, Underflow as Underflow, + _ContextManager, ) -from types import TracebackType from typing import Final from typing_extensions import TypeAlias _TrapType: TypeAlias = type[DecimalException] -class _ContextManager: - new_context: Context - saved_context: Context - def __init__(self, new_context: Context) -> None: ... - def __enter__(self) -> Context: ... - def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... - __version__: Final[str] __libmpdec_version__: Final[str] diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index 3da75ec19..7f8708a02 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -24,7 +24,8 @@ from _decimal import ( setcontext as setcontext, ) from collections.abc import Container, Sequence -from typing import Any, ClassVar, Literal, NamedTuple, overload +from types import TracebackType +from typing import Any, ClassVar, Literal, NamedTuple, final, overload, type_check_only from typing_extensions import Self, TypeAlias _Decimal: TypeAlias = Decimal | int @@ -35,6 +36,14 @@ _TrapType: TypeAlias = type[DecimalException] # At runtime, these classes are implemented in C as part of "_decimal". # However, they consider themselves to live in "decimal", so we'll put them here. +# This type isn't exposed at runtime. It calls itself decimal.ContextManager +@final +@type_check_only +class _ContextManager: + def __init__(self, new_context: Context) -> None: ... + def __enter__(self) -> Context: ... + def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... + class DecimalTuple(NamedTuple): sign: int digits: tuple[int, ...]