Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylsp_document_symbols raising TypeError from os.path.samefile #30

Closed
douglasdavis opened this issue May 11, 2021 · 2 comments · Fixed by #31
Closed

pylsp_document_symbols raising TypeError from os.path.samefile #30

douglasdavis opened this issue May 11, 2021 · 2 comments · Fixed by #31
Milestone

Comments

@douglasdavis
Copy link
Contributor

It looks like

try:
docismodule = os.path.samefile(document.path, d.module_path)
except AttributeError:
# Python 2 on Windows has no .samefile, but then these are
# strings for sure
docismodule = document.path == d.module_path
should perhaps look for a TypeError or check for Nones before calling samefile? I'm making this guess passed on the following traceback:

Traceback (most recent call last):
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pylsp_jsonrpc/endpoint.py", line 116, in consume
    self._handle_request(message['id'], message['method'], message.get('params'))
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pylsp_jsonrpc/endpoint.py", line 185, in _handle_request
    handler_result = handler(params)
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pylsp_jsonrpc/dispatchers.py", line 25, in handler
    return method(**(params or {}))
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pylsp/python_lsp.py", line 334, in m_text_document__document_symbol
    return self.document_symbols(textDocument['uri'])
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pylsp/python_lsp.py", line 250, in document_symbols
    return flatten(self._hook('pylsp_document_symbols', doc_uri))
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pylsp/python_lsp.py", line 155, in _hook
    return hook_handlers(config=self.config, workspace=workspace, document=doc, **kwargs)
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/manager.py", line 337, in traced_hookexec
    return outcome.get_result()
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/callers.py", line 52, in from_call
    result = func()
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/manager.py", line 335, in <lambda>
    outcome = _Result.from_call(lambda: oldcall(hook, hook_impls, kwargs))
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/ddavis/.pyenv/versions/3.9.5/envs/dask-dev/lib/python3.9/site-packages/pylsp/plugins/symbols.py", line 42, in pylsp_document_symbols
    docismodule = os.path.samefile(document.path, d.module_path)
  File "/Users/ddavis/.pyenv/versions/3.9.5/lib/python3.9/genericpath.py", line 101, in samefile
    s2 = os.stat(f2)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
@ccordoba12
Copy link
Member

I think catching TypeError is better here because it'd cover the case in which document.path, d.module_path are both None.

Could you create a PR for it? Thanks!

@douglasdavis
Copy link
Contributor Author

Sure! Just opened one.

@andfoy andfoy added this to the v1.1.0 milestone May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants