Skip to content

Adding the TOML version to the optional dependencies #1120

Description

@chirizxc

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

msgspec/pyproject.toml

Lines 45 to 48 in e1c6f23

[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",
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions