python-poetry / tomlkit

Style-preserving TOML library for Python
MIT License
699 stars 100 forks source link

fix: mypy errors when using tomlkit to modify toml document #356

Closed waketzheng closed 5 months ago

waketzheng commented 5 months ago

Fixes #326

waketzheng commented 5 months ago

Mini demo to check result:

from pathlib import Path
import tomlkit

doc = tomlkit.parse(Path('pyproject.toml').read_text())
poetry_conf = doc['tool']['poetry']
print(poetry_conf)
poetry_conf['version'] = '0'
frostming commented 5 months ago

But that is not right, you can't assume an abitrary item is a table.

You can't make that assumption in vanilla python either:

doc: dict[str, Any] = get_data()
print(doc['tool']['abc'])  # what type is doc['tool']?

Instead, you have to tell the typechecker the type information.