-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-36778: Avoid functools in encodings.cp65001 #13110
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
Conversation
|
||
if not hasattr(codecs, 'code_page_encode'): | ||
raise LookupError("cp65001 encoding is only available on Windows") | ||
|
||
### Codec APIs | ||
|
||
encode = functools.partial(codecs.code_page_encode, 65001) | ||
_decode = functools.partial(codecs.code_page_decode, 65001) | ||
encode = lambda *args, **kw: codecs.code_page_encode(65001, *args, **kw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please measure how much overhead it adds?
Oh, my PR looks wrong. Most CP65001Test tests fail... |
I don't know if it helps, but test_startup_imports passes on IoT Core using this change with a default codepage of cp65001. So it looks like this strategy could work if there's a way to remove functools without breaking other things. |
|
Replace functools.partial() with lambda to reduce the number of imports at startup. Avoid the following imports at startup: - _collections - _functools - _heapq - _operator - collections - functools - heapq - itertools - keyword - operator - reprlib
Right. I fixed my PR with that. I also rebased my PR and added a NEWS entry. |
@serhiy-storchaka: "Could you please measure how much overhead it adds?" Benchmark in release mode:
|
I merged my PR #13230 instead. |
Replace functools.partial() with lambda to reduce the number of
imports at startup. Avoid the following imports at startup:
https://bugs.python.org/issue36778