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

Any snippet using python-args-to-docstring returns Wrong type argument: listp #505

Open
quazgar opened this issue Oct 17, 2024 · 2 comments · May be fixed by #509
Open

Any snippet using python-args-to-docstring returns Wrong type argument: listp #505

quazgar opened this issue Oct 17, 2024 · 2 comments · May be fixed by #509

Comments

@quazgar
Copy link
Contributor

quazgar commented Oct 17, 2024

Maybe issue #1200 from yasnippet rather belongs here? Possibly introduced by #465,

Expanding e.g. function_docstring and tabbing the cursor to args, shows error Wrong type argument: listp
[...]

I can reproduce this with plain Emacs:

def fd(foo):
    """
    Wrong type argument: listp, "foo"
    """

def fdn(bar):
    """

    Wrong type argument: listp, "bar"
    """ 
  • GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.16.0) of 2024-07-22, modified by Debian
  • yasnippet: 20241013.1557
  • yasnippet-snippets: 20241014.949
@quazgar
Copy link
Contributor Author

quazgar commented Nov 4, 2024

Simple test (after loading the definitions python-args-to-docstring and python-split-args in .yas-setup.el):

(let ((yas-text "foo"))
  (python-args-to-docstring))

Output:

Debugger entered--Lisp error: (wrong-type-argument listp "foo")
  nth(0 "foo")
  (length (nth 0 x))
  (closure (t) (x) (length (nth 0 x)))("foo")
  mapcar((closure (t) (x) (length (nth 0 x))) ("foo" "bar"))
  (apply 'max (mapcar #'(lambda (x) (length (nth 0 x))) args))
  (if args (apply 'max (mapcar #'(lambda (x) (length (nth 0 x))) args)) 0)
  (let* ((indent (concat "\n" (make-string (current-column) 32))) (args (python-split-args yas-text)) (max-len (if args (apply 'max (mapcar #'(lambda ... ...) args)) 0)) (formatted-args (mapconcat #'(lambda (x) (concat (nth 0 x) (make-string ... 32) " -- " (if ... ...))) args indent))) (if (string= formatted-args "") nil (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent)))
  python-args-to-docstring()
  (let* ((yas-text "foo: str, bar: int = 3")) (python-args-to-docstring))
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  command-execute(eval-last-sexp)

@quazgar
Copy link
Contributor Author

quazgar commented Nov 4, 2024

As a quick bugfix, this snippet works:

(defun python-split-args (arg-string)
  "Split a python argument string ARG-STRING into a list ((name), ...) of argument names."
  (mapcar 'list
          (mapcar (lambda (x)
            (when (string-match python-split-arg-arg-regex x)
              (match-string-no-properties 1 x)))
          (split-string arg-string python-split-arg-separator t))))

It does not keep the default values or types, though.

quazgar pushed a commit to quazgar/yasnippet-snippets that referenced this issue Nov 4, 2024
This should fix AndreaCrotti#505 "Any snippet using python-args-to-docstring returns Wrong type argument: listp"
and also adds type hints to the docstring again.
quazgar pushed a commit to quazgar/yasnippet-snippets that referenced this issue Nov 4, 2024
This should fix AndreaCrotti#505 "Any snippet using python-args-to-docstring returns Wrong type argument: listp"
and also adds type hints to the docstring again.
@quazgar quazgar linked a pull request Nov 4, 2024 that will close this issue
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.

1 participant