diff --git a/pyproject_toml_builder.py b/pyproject_toml_builder.py index 125f94c..081b94c 100644 --- a/pyproject_toml_builder.py +++ b/pyproject_toml_builder.py @@ -47,7 +47,16 @@ class NoDotsDict(dict): - """A custom dictionary class that disallows keys with dots ('.').""" + """A custom dictionary class that disallows keys with dots ('.'). + + Dots have a special meaning in TOML, so a key like `[a.b.c]` in a + `dict` would be dict["a"]["b"]["c"] but NOT dict["a.b.c"]. To avoid + this pitfall, we can disallow dots all together. + + There are situations where a dotted key could be useful, like + `["127.0.0.1"] = "value"`. In this case, this the dict key is "127.0.0.1" + (and is not a nesting of subdicts). + """ def __setitem__(self, key, value): if "." in key: diff --git a/tests/test_pyproject_toml_builder.py b/tests/test_pyproject_toml_builder.py index 6ab4985..17f57a0 100644 --- a/tests/test_pyproject_toml_builder.py +++ b/tests/test_pyproject_toml_builder.py @@ -158,7 +158,12 @@ def assert_outputted_pyproject_toml( pyproject_toml_path: Path, expected: dict[str, Any] ) -> None: """Compare each's contents casted to a dict.""" - pyproject_toml_builder.NoDotsDict(expected) # test that we aren't using dots + + # test that we aren't using dots + no_dots = pyproject_toml_builder.NoDotsDict() + for key, value in expected.items(): + no_dots[key] = value + print() print("EXPECTED TOML OUTPUT:") print(expected)