Description
|
def _import_tomllib(): |
|
try: |
|
import tomllib # type: ignore |
|
|
|
return tomllib |
|
except ImportError: |
|
pass |
|
|
|
try: |
|
import tomli # type: ignore |
|
|
|
return tomli |
|
except ImportError: |
|
raise ImportError( |
|
"`msgspec.toml.decode` requires `tomli` be installed.\n\n" |
|
"Please either `pip` or `conda` install it as follows:\n\n" |
|
" $ python -m pip install tomli # using pip\n" |
|
" $ conda install tomli # or using conda" |
|
) from None |
|
|
|
|
|
def _import_tomli_w(): |
|
try: |
|
import tomli_w # type: ignore |
|
|
|
return tomli_w |
|
except ImportError: |
|
raise ImportError( |
|
"`msgspec.toml.encode` requires `tomli_w` be installed.\n\n" |
|
"Please either `pip` or `conda` install it as follows:\n\n" |
|
" $ python -m pip install tomli_w # using pip\n" |
|
" $ conda install tomli_w # or using conda" |
|
) from None |
|
[project.optional-dependencies] |
|
toml = [ |
|
"tomli ; python_version < '3.11'", |
|
"tomli_w", |
Currently, if Python version >= 3.11, tomli dependency is not installed, and in Python 3.15, TOML 1.1 will be the default instead of TOML 1.0 in versions 3.11–3.14; this may change the behavior of the code in the future, for example, it might prevent an error from being raised in tests
We should do something like this and update the installation instructions to include the option to select the desired version of the optional dependency:
# TOML v1.0 : https://toml.io/en/v1.0.0
toml_1 = [
"tomli >= 2.2 , < 2.4"
"tomli-w >= 1.2.0",
]
# TOML v1.1 : https://toml.io/en/v1.1.0
toml_1_1 = [
"tomli >= 2.4.1",
"tomli-w >= 1.2.0",
]
Description
msgspec/src/msgspec/toml.py
Lines 26 to 58 in e1c6f23
msgspec/pyproject.toml
Lines 45 to 48 in e1c6f23
Currently, if Python version >= 3.11,
tomlidependency is not installed, and in Python 3.15, TOML 1.1 will be the default instead of TOML 1.0 in versions 3.11–3.14; this may change the behavior of the code in the future, for example, it might prevent an error from being raised in testsWe should do something like this and update the installation instructions to include the option to select the desired version of the optional dependency: