python-poetry / tomlkit

Style-preserving TOML library for Python
MIT License
693 stars 98 forks source link

Failed to delete an item of OutOfOrderTableProxy #383

Open ninoseki opened 1 month ago

ninoseki commented 1 month ago

Hello, first of all, thanks for creating a great library.

I noticed there is a glitch while dealing with OutOfOrderTableProxy. I cannot delete a key via pop.

import tomlkit

text = """
[tool.poetry]
name = "dummy"
version = "0.0.0"
description = ""
authors = []
readme = "README.md"

[tool.poetry-dynamic-versioning]
enable = true

[[tool.poetry.source]]
name = "foo"
url = ""

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
ignore_missing_imports = true
"""

doc = tomlkit.parse(text)
tool = doc["tool"]

print(type(tool)) # <class 'tomlkit.container.OutOfOrderTableProxy'>
print(tool.keys()) # KeysView({'poetry': {'source': [{'name': 'foo', 'url': ''}]}, 'poetry-dynamic-versioning': {'enable': True}, 'mypy': {'ignore_missing_imports': True}})

tool.pop("poetry") # tomlkit.exceptions.NonExistentKey: 'Key "poetry" does not exist.'

(Tested with v0.13.2)

Am I misusing something? Or is this a bug in OutOfOrderTableProxy's __delitem__ method?