-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-118761: Improve import time of tomllib
#128907
base: main
Are you sure you want to change the base?
Conversation
def load(fp: BinaryIO, /, *, parse_float: ParseFloat = float) -> dict[str, Any]: | ||
def load(fp: IO[bytes], /, *, parse_float: ParseFloat = float) -> dict[str, Any]: |
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.
I think that this should technically be a protocol similar to typeshed's SupportsRead
. But for a slightly more radical proposal, would you support removing all the type annotations from tomllib
? The ones in typeshed are used by all of the type checkers, and there's a risk of going out of sync, or unhelpful 'improvements' to adjust the (unused) type hints in Lib/tomllib
.
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.
I think that this should technically be a protocol similar to typeshed's SupportsRead.
This is true. I changed this annotation because the the diff I was porting included an updated from typing import
line that uses IO
not BinaryIO
. A trade-off was made choosing this annotation, and so far nobody complained about it.
But for a slightly more radical proposal, would you support removing all the type annotations from tomllib?
I wouldn't support it, at least not before Python 3.10 EOL date. Type annotations were inherited from Tomli, and having them here makes diffs smaller and easier to work with -> syncing changes such as this PR is a bit easier for me.
That said, no big deal for me. If folks want to remove the annotations, I'd be fine with it.
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.
Fair enough -- I'd remove them personally, but I'm not the maintainer of tomllib
and being able to easily synchronise updates is a good reason -- we might re-visit in a couple of years!
IO[bytes]
is probably fine for now the given this.
cc @encukou who added the module in Python 3.11 (PEP 680). |
This is a port of two commits in Tomli repository (the diff of these commits being hukkin/tomli@42a570d...1da01ef).
This removes runtime overhead of
string
,typing
, andtomllib._types
imports fromimport tomllib
.main
branchPR branch