Skip to content
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

use the standard library tomllib on sufficiently new python #2202

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

eli-schwartz
Copy link
Contributor

In python 3.11 it is no longer necessary to vendor (?) a toml implementation. The vendored one is now part of the standard library. Simply use that instead.

Benefits include:

  • micro-optimization when using the isort library API in an application that already uses tomllib, to avoid reading yet another one from on-disk
  • seamless support for automatically dropping tomli once the minimum python version is upgraded, via tools such as pyupgrade
  • distributors who patch out isort to use the system tomli, do not actually have to package tomli for versions of python that have tomllib

if sys.version_info >= (3, 11):
import tomllib
else:
from ._vendored import tomli
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
from ._vendored import tomli
from ._vendored import tomli as tomllib

this will not work.. you will probably need this to keep working with older versions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right... IIRC I started off by importing tomllib as tomli and then switched approaches (because that allows pyupgrade to drop all the compat code) but forgot to update both locations.

Will fix...

In python 3.11 it is no longer necessary to vendor (?) a toml
implementation. The vendored one is now part of the standard library.
Simply use that instead.

Benefits include:
- micro-optimization when using the isort library API in an application
  that already uses tomllib, to avoid reading yet another one from
  on-disk
- seamless support for automatically dropping tomli once the minimum
  python version is upgraded, via tools such as pyupgrade
- distributors who patch out isort to use the system tomli, do not
  actually have to package tomli for versions of python that have
  tomllib
Copy link

codecov bot commented Dec 4, 2023

Codecov Report

Merging #2202 (0c20647) into main (b67a6a5) will decrease coverage by 0.07%.
The diff coverage is 50.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2202      +/-   ##
==========================================
- Coverage   99.22%   99.15%   -0.07%     
==========================================
  Files          38       38              
  Lines        3087     3089       +2     
  Branches      747      748       +1     
==========================================
  Hits         3063     3063              
- Misses         14       15       +1     
- Partials       10       11       +1     

@staticdev staticdev merged commit f61affa into PyCQA:main Dec 4, 2023
11 of 18 checks passed
@eli-schwartz eli-schwartz deleted the tomllib branch December 4, 2023 18:04
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.

2 participants