Skip to content

Commit

Permalink
add test; minor wording improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pfackeldey committed Dec 18, 2024
1 parent 9d82766 commit b4853d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/awkward/_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def to_dict(self):
return _unfreeze_attrs(self._data)


def _enforce_str_key(attr: Any) -> str:
if not isinstance(attr, str):
raise TypeError(f"'attrs' keys must be strings: {attr!r}")
return attr
def _enforce_str_key(key: Any) -> str:
if not isinstance(key, str):
raise TypeError(f"'attrs' keys must be strings, got: {key!r}")
return key


def _freeze_attrs(attrs: Mapping[str, Any]) -> Mapping[str, Any]:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_3350_enforce_attrs_string_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE
# ruff: noqa: E402

from __future__ import annotations

import pytest
import awkward as ak


def test():
arr = ak.Array([1])

with pytest.raises(
TypeError,
match="'attrs' keys must be strings, got: 1",
):
arr.attrs[1] = "foo"

0 comments on commit b4853d0

Please sign in to comment.