gh-145478: Implement frozendict into functools.partial#145960
gh-145478: Implement frozendict into functools.partial#145960brijkapadia wants to merge 6 commits into
frozendict into functools.partial#145960Conversation
|
cc @encukou since you originally suggested this change. |
Sorry, something went wrong.
|
Most of the test errors are due to problems with pickling the |
Sorry, something went wrong.
|
Update: I realized that the simplest solution would be for |
Sorry, something went wrong.
|
Sorry for the delay. Seeing the PR, I realized it's a backwards incompatible change, since >>> import functools
>>> p = functools.partial(print)
>>> p.keywords['sep'] = '::'
>>> p('a', 'b')
a::bIt would be good to deprecate this first, but that looks like a lot of extra work :/ @vstinner, do you know of more cases where it would be good to replace |
Sorry, something went wrong.
How would you implement such deprecation period? In the documentation only? There are many dictionaries in the stdlib which should not be modified but are declared as mutable dict ( So far, if I recall correctly, only two changes (gh-144909 and gh-144910) were merged to replace There is also gh-144904 which replaced Another example is gh-144906 which proposed converting By the way, the SC decision includes:
|
Sorry, something went wrong.
I was thinking of a new mapping class that warns when mutated.
Yes, but when approval is given, we need to honor the backwards compatibility policy. |
Sorry, something went wrong.
Okay, I will defer to your judgment on whatever makes the most sense. Additionally, this PR also enforces that the keywords for the |
Sorry, something went wrong.
Yeah, but since you can't call functions with non-string keywords, I see this as erroring out earlier. |
Sorry, something went wrong.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
|
@encukou do you think it is still worth deprecating this feature? |
Sorry, something went wrong.
|
That depends -- mainly on how many other cases would use the deprecation. It's probably not worth the trouble for this case only. |
Sorry, something went wrong.
|
Okay, I'll close this then |
Sorry, something went wrong.
Changes:
partial.__setstate__takes any dict for keywords and checks keywords to make sure that they are stringsfrozendict(rather than adict)frozendictdoes not work for these lower numbed protocolsfrozendictforpartialobjectin functools module #145478📚 Documentation preview 📚: https://cpython-previews--145960.org.readthedocs.build/