-
Notifications
You must be signed in to change notification settings - Fork 89
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
TypeError: Object of type '<class 'pathlib.PosixPath'>' cannot be converted by tosexp
.
#348
Comments
I tried using the git version of sexpdata, and I get Traceback (most recent call last):
File "/Users/aaronmeurer/Documents/python-epc/epc/handler.py", line 238, in _handle
(name, uid, args) = unpack_message(sexp)
File "/Users/aaronmeurer/Documents/python-epc/epc/handler.py", line 87, in unpack_message
return (data[0].value(), data[1], data[2:])
AttributeError: 'Symbol' object has no attribute 'value' This also happens with the git version of python-epc. |
Apparently sexpdata removed |
@cfroehli @immerrr #354 probably fixed the problem in my first comment (I haven't checked yet), but what about #348 (comment)? Does python-epc need to be updated? |
@asmeurer oh, sorry, I didn't mean to close this. Do you have a repro for the issue? |
I think it was coming from using the git version of sexpdata and a goto-definition. I'll need to check the latest version of emacs-jedi later to see if I can still reproduce it. |
I've been using the git versions of python-epc, emacs-jedi (before the fix from #354), and sexpdata with the following patch: diff --git a/sexpdata.py b/sexpdata.py
index c4c6ce2..1f1da1b 100644
--- a/sexpdata.py
+++ b/sexpdata.py
@@ -81,6 +81,8 @@ from collections import namedtuple, Iterable, Mapping
from itertools import chain
from string import whitespace
+import pathlib
+
BRACKETS = {'(': ')', '[': ']'}
@@ -402,6 +404,16 @@ def _(obj, str_as='string', **kwds):
else:
raise ValueError('str_as={0!r} is not valid'.format(str_as))
+@tosexp.register(pathlib.PosixPath)
+def _(obj, str_as='string', **kwds):
+ kwds['str_as'] = str_as
+ if str_as == 'symbol':
+ return str(obj)
+ elif str_as == 'string':
+ return tosexp(String(str(obj)))
+ else:
+ raise ValueError('str_as={0!r} is not valid'.format(str_as))
+
@tosexp.register(type(None))
def _(obj, none_as='()', **kwds):
@@ -421,6 +433,9 @@ def _(obj, **kwds):
class String(unicode):
+ def value(self):
+ return unicode(self)
+
def __eq__(self, other):
"""
>>> from itertools import permutations The last change is something that should be fixed in python-epc, not sexpdata, but it should give an idea of what is broken. At a glance, the pathlib thing might be relevant to upstream into sexpdata, assuming it is still a concern. |
Yeah, I think it should be possible to fix this if we discover where does |
The pathlib instance I've spotted was the d.module_path attribute, sent to emacs via the definition_to_xxx method (helpers building the required dict to be answer the deferred call). I've forced a str there so a basic string is passed back to emacs instead of the pathlib instance (jediepcserver.py lines 350 & 360). We may prefer a call to unicode though (just be careful in case of python2 interpreter as str/unicode semantic changed). |
@cfroehli thank you! I think it should be fine to return a native |
@cfroehli I didn't get any errors with pathlib so I assume calling |
@asmeurer out of curiosity, why didn't you add your patch as PR to https://github.com/jd-boyd/sexpdata ? |
The upstream bug has been fixed, so this should be closed: jd-boyd/sexpdata#36 |
I tried using emacs-jedi against the git version of jedi, and I am getting this error doing a goto-definition:
I think Jedi is switching to use pathlib everywhere.
If you don't use the master version of Jedi, you get some other pathlib related errors, which have been fixed in the dev version of jedi.
The text was updated successfully, but these errors were encountered: