Skip to content

gh-128615: Cover pickling of ParamSpecArgs and ParamSpecKwargs #128616

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 1 commit into from
Jan 8, 2025
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
12 changes: 12 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5182,6 +5182,18 @@ class C(B[int]):
x = pickle.loads(z)
self.assertEqual(s, x)

# Test ParamSpec args and kwargs
global PP
Copy link
Member

Choose a reason for hiding this comment

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

could this be combined into the global statement at the top of the function? (global C, PP)

Copy link
Member Author

Choose a reason for hiding this comment

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

It feel more readable to have this name defined as global near the place where this is needed.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough, I don't feel strongly :)

PP = ParamSpec('PP')
for thing in [PP.args, PP.kwargs]:
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(thing=thing, proto=proto):
self.assertEqual(
pickle.loads(pickle.dumps(thing, proto)),
thing,
)
del PP
Copy link
Member

Choose a reason for hiding this comment

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

should this be some sort of context manager so that PP is del'd from the global namespace even if an exception in the for loop leads to the test terminating early?

should we also del the C name, which is declared as global on the first line of this function?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are multiple places where this pattern is used. I think that it should be fine, because the only problem that I can think of is that PP will be reported as changed by refleak. So, not a big deal in case of a failure.

But, this can be refactored in the future, if desired.


def test_copy_and_deepcopy(self):
T = TypeVar('T')
class Node(Generic[T]): ...
Expand Down
Loading