datatree icon indicating copy to clipboard operation
datatree copied to clipboard

Allow passing os.PathLike as an alternative to strings to represent node paths

Open TomNicholas opened this issue 7 months ago • 1 comments

Broadens the types that getitem and setitem methods accept to include anything that follows the os.PathLike protocol.

It's possible there are some additional edge cases here that we should forbid, such as passing a Windows-style path.

  • [x] Closes part of #281
  • [ ] Tests added
  • [ ] Passes pre-commit run --all-files
  • [ ] ~~New functions/methods are listed in api.rst~~
  • [x] Changes are summarized in docs/source/whats-new.rst

TomNicholas avatar Nov 27 '23 15:11 TomNicholas

The only reason I haven't merged this is that I can't see what mypy's problem with this is:

datatree/mapping.py:245: error: Argument 1 to "from_dict" of "DataTree" has incompatible type "dict[str, Any | None]"; expected "MutableMapping[str | PathLike[Any], Any | DataTree[Any] | None]"  [arg-type]
Found 1 error in 1 file (checked 25 source files)

TomNicholas avatar Dec 03 '23 18:12 TomNicholas