Skip to content

Remove ParamSpec for SupportsReplace #12410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 14, 2024
Merged
Changes from all commits
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
9 changes: 4 additions & 5 deletions stdlib/copy.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import sys
from typing import Any, Protocol, TypeVar
from typing_extensions import ParamSpec, Self
from typing_extensions import Self

__all__ = ["Error", "copy", "deepcopy"]

_T = TypeVar("_T")
_SR = TypeVar("_SR", bound=_SupportsReplace[Any])
_P = ParamSpec("_P")
_SR = TypeVar("_SR", bound=_SupportsReplace)

class _SupportsReplace(Protocol[_P]):
class _SupportsReplace(Protocol):
# In reality doesn't support args, but there's no other great way to express this.
def __replace__(self, *args: _P.args, **kwargs: _P.kwargs) -> Self: ...
def __replace__(self, *args: Any, **kwargs: Any) -> Self: ...
Comment on lines +10 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Can't add this as suggestion.)

class _SupportsReplace(Protocol):
    def __replace__(self, **changes: Any) -> Self: ...  # changes as passed to replace()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look back at the old PR, this doesn't work, since type-checkers will complain if the implementation does have **kwargs, as opposed to supporting any amount of variable key word arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srittau Just wanted to follow up on this.


# None in CPython but non-None in Jython
PyStringMap: Any
Expand Down
Loading