Skip to content

Commit beadec8

Browse files
committed
tomlkit 0.15.0
1 parent c04069d commit beadec8

18 files changed

Lines changed: 100 additions & 174 deletions

File tree

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies = [
2121
"requests-toolbelt (>=1.0.0,<2.0.0)",
2222
"shellingham (>=1.5,<2.0)",
2323
"tomli (>=2.0.1,<3.0.0) ; python_version < '3.11'",
24-
"tomlkit (>=0.11.4,<1.0.0)",
24+
"tomlkit (>=0.15.0,<1.0.0)",
2525
# trove-classifiers uses calver, so version is unclamped
2626
"trove-classifiers (>=2022.5.19)",
2727
"virtualenv (>=20.26.6)",

src/poetry/config/file_config_source.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def get_property(self, key: str | Sequence[str]) -> Any:
4848
config = config[sub_key]
4949

5050
def add_property(self, key: str | Sequence[str], value: Any) -> None:
51-
with self.secure() as toml:
52-
config: dict[str, Any] = toml
51+
with self.secure() as config:
5352
keys = split_key(key)
5453

5554
for i, sub_key in enumerate(keys):
@@ -63,8 +62,7 @@ def add_property(self, key: str | Sequence[str], value: Any) -> None:
6362
config = config[sub_key]
6463

6564
def remove_property(self, key: str | Sequence[str]) -> None:
66-
with self.secure() as toml:
67-
config: dict[str, Any] = toml
65+
with self.secure() as config:
6866
keys = split_key(key)
6967

7068
# Descend to the leaf, recording the (parent, key) at each step.

src/poetry/console/commands/add.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from packaging.utils import canonicalize_name
1313
from poetry.core.packages.dependency import Dependency
1414
from poetry.core.packages.dependency_group import MAIN_GROUP
15-
from tomlkit.toml_document import TOMLDocument
1615

1716
from poetry.console.commands.init import InitCommand
1817
from poetry.console.commands.installer_command import InstallerCommand
@@ -148,9 +147,7 @@ def handle(self) -> int:
148147
if optional and group != MAIN_GROUP:
149148
raise ValueError("You can only add optional dependencies to the main group")
150149

151-
# tomlkit types are awkward to work with, treat content as a mostly untyped
152-
# dictionary.
153-
content: dict[str, Any] = self.poetry.file.read()
150+
content = self.poetry.file.read()
154151
project_content = content.get("project", table())
155152
poetry_content = content.get("tool", {}).get("poetry", table())
156153
groups_content = content.get("dependency-groups", {})
@@ -413,7 +410,6 @@ def handle(self) -> int:
413410
status = self.installer.run()
414411

415412
if status == 0 and not self.option("dry-run"):
416-
assert isinstance(content, TOMLDocument)
417413
self.poetry.file.write(content)
418414

419415
return status

src/poetry/console/commands/remove.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from packaging.utils import canonicalize_name
1010
from poetry.core.packages.dependency import Dependency
1111
from poetry.core.packages.dependency_group import MAIN_GROUP
12-
from tomlkit.toml_document import TOMLDocument
1312

1413
from poetry.console.commands.installer_command import InstallerCommand
1514

@@ -63,7 +62,7 @@ def handle(self) -> int:
6362
else:
6463
group = self.option("group", self.default_group)
6564

66-
content: dict[str, Any] = self.poetry.file.read()
65+
content = self.poetry.file.read()
6766
project_content = content.get("project", {})
6867
groups_content = content.get("dependency-groups", {})
6968
poetry_content = content.get("tool", {}).get("poetry", {})
@@ -179,7 +178,6 @@ def handle(self) -> int:
179178
status = self.installer.run()
180179

181180
if not self.option("dry-run") and status == 0:
182-
assert isinstance(content, TOMLDocument)
183181
self.poetry.file.write(content)
184182

185183
return status

src/poetry/console/commands/self/self_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ def generate_system_pyproject(self) -> None:
8787
package.python_versions = ".".join(str(v) for v in self.env.version_info[:3])
8888

8989
content = Factory.create_legacy_pyproject_from_package(package=package)
90-
content["tool"]["poetry"]["package-mode"] = False # type: ignore[index]
90+
content["tool"]["poetry"]["package-mode"] = False
9191

9292
for key in preserved:
93-
content["tool"]["poetry"][key] = preserved[key] # type: ignore[index]
93+
content["tool"]["poetry"][key] = preserved[key]
9494

9595
if preserved_groups:
9696
content["dependency-groups"] = preserved_groups

src/poetry/console/commands/source/add.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from typing import TYPE_CHECKING
4-
from typing import Any
54
from typing import ClassVar
65

76
from cleo.helpers import argument
@@ -106,9 +105,7 @@ def handle(self) -> int:
106105
)
107106
return 1
108107

109-
# tomlkit types are awkward to work with, treat content as a mostly untyped
110-
# dictionary.
111-
content: dict[str, Any] = self.poetry.pyproject.data
108+
content = self.poetry.pyproject.data
112109
if "tool" not in content:
113110
content["tool"] = table()
114111
if "poetry" not in content["tool"]:

src/poetry/console/commands/version.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from __future__ import annotations
22

33
from typing import TYPE_CHECKING
4-
from typing import Any
54
from typing import ClassVar
65

76
from cleo.helpers import argument
87
from cleo.helpers import option
98
from poetry.core.version.exceptions import InvalidVersionError
10-
from tomlkit.toml_document import TOMLDocument
119

1210
from poetry.console.commands.command import Command
1311

@@ -68,15 +66,14 @@ def handle(self) -> int:
6866
)
6967

7068
if not self.option("dry-run"):
71-
content: dict[str, Any] = self.poetry.file.read()
69+
content = self.poetry.file.read()
7270
project_content = content.get("project", {})
7371
if "version" in project_content:
7472
project_content["version"] = version.text
7573
poetry_content = content.get("tool", {}).get("poetry", {})
7674
if "version" in poetry_content:
7775
poetry_content["version"] = version.text
7876

79-
assert isinstance(content, TOMLDocument)
8077
self.poetry.file.write(content)
8178
else:
8279
if self.option("short"):

src/poetry/factory.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from typing import TYPE_CHECKING
88
from typing import Any
9-
from typing import cast
109

1110
from cleo.io.null_io import NullIO
1211
from packaging.utils import NormalizedName
@@ -254,7 +253,7 @@ def create_legacy_pyproject_from_package(cls, package: Package) -> TOMLDocument:
254253

255254
from poetry.utils.dependency_specification import dependency_to_specification
256255

257-
pyproject: dict[str, Any] = tomlkit.document()
256+
pyproject = tomlkit.document()
258257

259258
pyproject["tool"] = tomlkit.table(is_super_table=True)
260259

@@ -350,8 +349,6 @@ def create_legacy_pyproject_from_package(cls, package: Package) -> TOMLDocument:
350349
if extras_section:
351350
content["extras"] = extras_section
352351

353-
pyproject = cast("TOMLDocument", pyproject)
354-
355352
return pyproject
356353

357354
@classmethod

src/poetry/layouts/layout.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from tomlkit import inline_table
1414
from tomlkit import loads
1515
from tomlkit import table
16-
from tomlkit.toml_document import TOMLDocument
1716

1817
from poetry.factory import Factory
1918
from poetry.pyproject.toml import PyProjectTOML
@@ -23,6 +22,7 @@
2322
from collections.abc import Mapping
2423

2524
from tomlkit.items import InlineTable
25+
from tomlkit.toml_document import TOMLDocument
2626

2727

2828
POETRY_DEFAULT = """\
@@ -141,7 +141,7 @@ def generate_project_content(
141141
) -> TOMLDocument:
142142
template = POETRY_DEFAULT
143143

144-
content: dict[str, Any] = loads(template)
144+
content = loads(template)
145145

146146
project_content = content["project"]
147147
project_content["name"] = self._project
@@ -212,7 +212,6 @@ def generate_project_content(
212212
build_system.add("requires", ["poetry-core" + build_system_version])
213213
build_system.add("build-backend", "poetry.core.masonry.api")
214214

215-
assert isinstance(content, TOMLDocument)
216215
content.add("build-system", build_system)
217216

218217
return content

0 commit comments

Comments
 (0)