Skip to content

bug: from_json seems to be broken #407

@mnesarco

Description

@mnesarco

Description of the bug

loading from generated json fails

To Reproduce

mod = loader.load("path/to/x")
s = mod.as_json()
back = Module.from_json(s)

Full traceback

Traceback (most recent call last):
  File "_devel/projects/Marz/FreeCAD/fcdocs/extractor.py", line 46, in <module>
    extract(Path("___fc_root___"), [], Path("FreeCAD.json"))
  File "_devel/projects/Marz/FreeCAD/fcdocs/extractor.py", line 32, in extract
    x = Object.from_json(fc.as_json())
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "_devel/projects/Marz/FreeCAD/fcdocs/.venv/lib/python3.11/site-packages/griffe/_internal/mixins.py", line 247, in from_json
    obj = json.loads(json_string, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "_.local/share/uv/python/cpython-3.11.13-linux-x86_64-gnu/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "_.local/share/uv/python/cpython-3.11.13-linux-x86_64-gnu/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "_.local/share/uv/python/cpython-3.11.13-linux-x86_64-gnu/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "_devel/projects/Marz/FreeCAD/fcdocs/.venv/lib/python3.11/site-packages/griffe/_internal/encoders.py", line 367, in json_decoder
    return _loader_map[kind](obj_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "_devel/projects/Marz/FreeCAD/fcdocs/.venv/lib/python3.11/site-packages/griffe/_internal/encoders.py", line 197, in _load_module
    filepath=Path(obj_dict["filepath"]) if "filepath" in obj_dict else None,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "_.local/share/uv/python/cpython-3.11.13-linux-x86_64-gnu/lib/python3.11/pathlib.py", line 871, in __new__
    self = cls._from_parts(args)
           ^^^^^^^^^^^^^^^^^^^^^
  File "_.local/share/uv/python/cpython-3.11.13-linux-x86_64-gnu/lib/python3.11/pathlib.py", line 509, in _from_parts
    drv, root, parts = self._parse_args(args)
                       ^^^^^^^^^^^^^^^^^^^^^^
  File "_.local/share/uv/python/cpython-3.11.13-linux-x86_64-gnu/lib/python3.11/pathlib.py", line 493, in _parse_args
    a = os.fspath(a)
        ^^^^^^^^^^^^
TypeError: expected str, bytes or os.PathLike object, not list

Expected behavior

must load the Module back as griffe object.

Environment information

- __System__: Linux-6.14.0-29-generic-x86_64-with-glibc2.39
- __Python__: cpython 3.11.13 (.venv/bin/python3)
- __Environment variables__:
- __Installed packages__:
  - `griffe` v1.14.0

PASTE MARKDOWN OUTPUT HERE

Additional context

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions