mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-07-09 18:09:17 +08:00
Refine the copy._SupportsReplace.__replace__ signature (#14786)
This commit is contained in:
+6
-6
@@ -1,16 +1,15 @@
|
||||
import sys
|
||||
from typing import Any, Protocol, TypeVar, type_check_only
|
||||
from typing_extensions import Self
|
||||
|
||||
__all__ = ["Error", "copy", "deepcopy"]
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_SR = TypeVar("_SR", bound=_SupportsReplace)
|
||||
_RT_co = TypeVar("_RT_co", covariant=True)
|
||||
|
||||
@type_check_only
|
||||
class _SupportsReplace(Protocol):
|
||||
# In reality doesn't support args, but there's no other great way to express this.
|
||||
def __replace__(self, *args: Any, **kwargs: Any) -> Self: ...
|
||||
class _SupportsReplace(Protocol[_RT_co]):
|
||||
# In reality doesn't support args, but there's no great way to express this.
|
||||
def __replace__(self, /, *_: Any, **changes: Any) -> _RT_co: ...
|
||||
|
||||
# None in CPython but non-None in Jython
|
||||
PyStringMap: Any
|
||||
@@ -21,7 +20,8 @@ def copy(x: _T) -> _T: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
__all__ += ["replace"]
|
||||
def replace(obj: _SR, /, **changes: Any) -> _SR: ...
|
||||
# The types accepted by `**changes` match those of `obj.__replace__`.
|
||||
def replace(obj: _SupportsReplace[_RT_co], /, **changes: Any) -> _RT_co: ...
|
||||
|
||||
class Error(Exception): ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user