Expected behavior:
I can write a python snippet that returns a numeric value, and that value gets printed out. Here is a convenient example.
snippet example "Copyright header" b
// TypeSafe Inc. LLC (c) `!p import datetime
snip.rv = datetime.datetime.now().year`
endsnippet
Actual behavior:
UltiSnips crashes.
An error occured. This is either a bug in UltiSnips or a bug in a
snippet definition. If you think this is a bug, please report it to
https://github.com/SirVer/ultisnips/issues/new
Please read and follow:
https://github.com/SirVer/ultisnips/blob/master/CONTRIBUTING.md#reproducing-bugs
Following is the full stack trace:
Traceback (most recent call last):
File "/src/UltiSnips/pythonx/UltiSnips/err_to_scratch_buffer.py", line 18, in wrapper
return func(self, *args, **kwds)
File "/src/UltiSnips/pythonx/UltiSnips/snippet_manager.py", line 127, in expand
if not self._try_expand():
File "/src/UltiSnips/pythonx/UltiSnips/snippet_manager.py", line 759, in _try_expand
self._do_snippet(snippet, before)
File "/src/UltiSnips/pythonx/UltiSnips/snippet_manager.py", line 712, in _do_snippet
text_before, self._visual_content, parent, start, end
File "/src/UltiSnips/pythonx/UltiSnips/snippet/definition/base.py", line 488, in launch
snippet_instance.update_textobjects(vim_helper.buf)
File "/src/UltiSnips/pythonx/UltiSnips/text_objects/snippet_instance.py", line 93, in update_textobjects
if obj._update(done, buf):
File "/src/UltiSnips/pythonx/UltiSnips/text_objects/python_code.py", line 279, in _update
self.overwrite(buf, rv)
File "/src/UltiSnips/pythonx/UltiSnips/text_objects/base.py", line 146, in overwrite
self._end = _replace_text(buf, self._start, self._end, gtext)
File "/src/UltiSnips/pythonx/UltiSnips/text_objects/base.py", line 22, in _replace_text
lines = text.split("\n")
AttributeError: 'int' object has no attribute 'split'
(Note that the actual snippet in question is one I have been using without issue for several years.)
Steps to reproduce
See branch: https://github.com/chiphogg/ultisnips/tree/chiphogg/1132/python-int-crash-repro
example snippet.Vim Version:
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 06 2019 17:31:41)
Included patches: 1-1453
UltiSnips Version:
84c84d5e64633e56c6e652c7dd6a9ca45ba9fa5a
Python inside Vim:
3.6.8 (default, Oct 7 2019, 12:59:55)
(py3 only; no py.)
Docker repo/vimrc: https://github.com/chiphogg/ultisnips/tree/chiphogg/1132/python-int-crash-repro
馃憢 @chiphogg Nice of you to come by. Still at Google?
I assume that this came with the recent removal of support for py2 - and removing the as_unicode function in some places. Should be very easy to fix and easy to work around (by just wrapping str() around the thing you assign to rv.
Hi @SirVer, good to "see" you again! :slightly_smiling_face:
I actually left Google in January of 2016. I've been at Uber ATG ever since.
@chiphogg Funny, I ended up at Lyft after my time at Google :)
On topic: I pushed a PR that should fix the issue.
Most helpful comment
@chiphogg Funny, I ended up at Lyft after my time at Google :)
On topic: I pushed a PR that should fix the issue.