Skip to content

libpython-clj2.metadata/pyarglists is not returning 'defaults' #284

Closed

Description

@behrica

When using fn libpython-clj2.metadata/pyarglists the deafults are not shown, see below.
py-fn-argspec seems to find them, but then they get eaten up, to me on this line:

(map (fn [[k v]] [(symbol k) (keyword k)]))

[(symbol k) (keyword k)] seems wrong, should be: [(symbol k) (keyword v)]
but (keyword x) returns for example "nil" on true, so defaults true are lost.

I think [(symbol k) v] should work, but not sure if for all cases.

(libpython-clj2.python/from-import os fwalk)
(-> 
 (libpython-clj2.metadata/py-fn-argspec fwalk)
 (libpython-clj2.metadata/pyarglists))

;;=> [[& [{top :top, topdown :topdown, onerror :onerror, follow_symlinks :follow_symlinks, dir_fd :dir_fd}]]
;;    [& [{top :top, topdown :topdown, follow_symlinks :follow_symlinks, dir_fd :dir_fd}]]
;;    [& [{top :top, follow_symlinks :follow_symlinks, dir_fd :dir_fd}]]
;;    [& [{follow_symlinks :follow_symlinks, dir_fd :dir_fd}]]]

in python:

>>> import os
>>> help (os.fwalk)
fwalk (top='.', topdown=True, onerror=None, *, follow_symlinks=False, dir_fd=None)

Activity

  1. changed the title [-]libpython-clj2.metadata/pyarglists s not showing defaults[/-] [+]libpython-clj2.metadata/pyarglists is not returning 'defaults'[/+] on Apr 10, 2026
  2. behrica commented on Apr 10, 2026

    @behrica
    ContributorAuthor

    fixing this is more complex, defaults can be anything:

    (py/from-import numpy.random randint)
    (->
     (libpython-clj2.metadata/py-fn-argspec randint))
    
    ;;=> {:args ["self" "low" "high" "size" "dtype"],
    ;;    :varargs nil,
    ;;    :varkw nil,
    ;;    :defaults
    ;;    [nil nil {:type :type, :value #object[tech.v3.datatype.ffi.Pointer 0x7c920c7f "{:address 0x00007FFA92BD0E00 }"]}],
    ;;    :kwonlyargs [],
    ;;    :kwonlydefaults nil,
    ;;    :annotations {}}

    I solved this differently, staying on python side and taking the "str" of each parameter from 'inspect'

    (py/from-import numpy.random randint)
    (require 'libpython-clj2.require)
    (libpython-clj2.require/import-python)
    (->
     ((py/get-attr inspect "getfullargspec") randint)
     (py/get-attr "defaults")
     (py/get-item 2)
     (builtins/str)
     str)
    ;;=> "<class 'int'>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions