Skip to content

gh-147991: Speed up tomllib import time#147992

Draft
vstinner wants to merge 1 commit intopython:mainfrom
vstinner:lazy_tomllib
Draft

gh-147991: Speed up tomllib import time#147992
vstinner wants to merge 1 commit intopython:mainfrom
vstinner:lazy_tomllib

Conversation

@vstinner
Copy link
Copy Markdown
Member

@vstinner vstinner commented Apr 2, 2026

Defer regular expressions import until the first datetime, localtime or non-trivial number (other that just decimal digits) is met.

Defer regular expressions import until the first datetime, localtime
or non-trivial number (other that just decimal digits) is met.
@vstinner
Copy link
Copy Markdown
Member Author

vstinner commented Apr 2, 2026

It might be interesting to replace from types import MappingProxyType with built-in frozendict. But currently, the GitHub Action CI runs mypy with Python 3.12 which doesn't have frozendict.

Copy link
Copy Markdown
Member Author

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

I marked added constants and functions as private by adding _ prefix. I'm not sure if it's needed, all other _parser APIs are "public" (no underscore prefix).


from ._types import Key, ParseFloat, Pos

_REGEX_IMPORTED = True
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I disabled the optimization when mypy runs, because I failed to fix mypy otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant