You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a python module A imports a namedtuple type from another module B, calling textDocument/documentSymbol on A will cause pylsp_document_symbols to throw a TypeError:
TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'NoneType'
Steps to reproduce
Set up a python workspace with the files a.py and b.py as follows
WARNING - pylsp.config.config - Failed to load hook pylsp_document_symbols: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'NoneType'
Traceback (most recent call last):
File "/home/ksmai/dev/pylsp-repro-namedtuple/.venv/lib/python3.12/site-packages/pylsp/config/config.py", line 39, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksmai/dev/pylsp-repro-namedtuple/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 480, in traced_hookexec
return outcome.get_result()
^^^^^^^^^^^^^^^^^^^^
File "/home/ksmai/dev/pylsp-repro-namedtuple/.venv/lib/python3.12/site-packages/pluggy/_result.py", line 100, in get_result
raise exc.with_traceback(exc.__traceback__)
File "/home/ksmai/dev/pylsp-repro-namedtuple/.venv/lib/python3.12/site-packages/pluggy/_result.py", line 62, in from_call
result = func()
^^^^^^
File "/home/ksmai/dev/pylsp-repro-namedtuple/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 477, in <lambda>
lambda: oldcall(hook_name, hook_impls, caller_kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksmai/dev/pylsp-repro-namedtuple/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "/home/ksmai/dev/pylsp-repro-namedtuple/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksmai/dev/pylsp-repro-namedtuple/.venv/lib/python3.12/site-packages/pylsp/plugins/symbols.py", line 88, in pylsp_document_symbols
if _include_def(d) and Path(document.path) == Path(d.module_path):
^^^^^^^^^^^^^^^^^^^
File "/home/ksmai/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/lib/python3.12/pathlib.py", line 1162, in __init__
super().__init__(*args)
File "/home/ksmai/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/lib/python3.12/pathlib.py", line 373, in __init__
raise TypeError(
TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'NoneType'
If a.py imports b_symbol instead of MyNamedTuple from b.py, pylsp will correctly return a_symbol in its response. In addition, textDocument/documentSymbol works correctly in b.py regardless of what is being imported into a.py.
The full code for reproducing the issue can also be found in this repository.
python version: 3.12.9
pylsp version: v1.12.2
The text was updated successfully, but these errors were encountered:
ksmai
changed the title
pylsp_document_symbols fails when the document imports a namedtuple from another module
pylsp_document_symbols throws type error when there is an import for a namedtuple type
Apr 27, 2025
ksmai
changed the title
pylsp_document_symbols throws type error when there is an import for a namedtuple type
pylsp_document_symbols throws TypeError when there is an import for a namedtuple type
Apr 27, 2025
ksmai
changed the title
pylsp_document_symbols throws TypeError when there is an import for a namedtuple type
textDocument/documentSymbol causes pylsp_document_symbols to throw a TypeError when there is an import for a namedtuple type
Apr 27, 2025
When a python module A imports a
namedtuple
type from another module B, callingtextDocument/documentSymbol
on A will causepylsp_document_symbols
to throw aTypeError
:Steps to reproduce
Set up a python workspace with the files
a.py
andb.py
as followsa.py
b.py
Start pylsp with
pylsp --verbose
Send these two messages to pylsp
LSP messages
Actual result
An error occurs and no results are returned
Error logs
LSP response
Expected result
pylsp should return
a_symbol
LSP response
Additional information
If
a.py
importsb_symbol
instead ofMyNamedTuple
fromb.py
, pylsp will correctly returna_symbol
in its response. In addition,textDocument/documentSymbol
works correctly inb.py
regardless of what is being imported intoa.py
.The full code for reproducing the issue can also be found in this repository.
python version: 3.12.9
pylsp version: v1.12.2
The text was updated successfully, but these errors were encountered: