Skip to content

Commit 6fb4f8e

Browse files
committed
Add hooks for all py macros (py. py.. py.- py* py**)
1 parent 36e4677 commit 6fb4f8e

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

resources/clj-kondo.exports/clj-python/libpython-clj/config.edn

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
libpython-clj2.require/require-python
1313
hooks.libpython-clj.require.require-python/require-python
1414

15-
libpython-clj2.python/py..
16-
hooks.libpython-clj.python.py-dot-dot/py..
1715
libpython-clj2.python/py.
18-
hooks.libpython-clj.python.py-dot-dot/py..}}
16+
hooks.libpython-clj.python.py-macros/py-macro
17+
libpython-clj2.python/py..
18+
hooks.libpython-clj.python.py-macros/py-macro
19+
libpython-clj2.python/py.-
20+
hooks.libpython-clj.python.py-macros/py-macro
21+
libpython-clj2.python/py*
22+
hooks.libpython-clj.python.py-macros/py-macro
23+
libpython-clj2.python/py**
24+
hooks.libpython-clj.python.py-macros/py-macro}}
1925

2026
:linters
2127
{:unresolved-namespace

resources/clj-kondo.exports/clj-python/libpython-clj/hooks/libpython_clj/python/py_dot_dot.clj

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(ns hooks.libpython-clj.python.py-macros
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn py-macro
5+
"Transform py macros to just evaluate the object, ignoring method/attribute symbols.
6+
(py. obj method arg) -> obj
7+
(py.. obj method1 method2) -> obj
8+
(py.- obj attr) -> obj
9+
(py* callable args) -> callable
10+
(py** callable args kwargs) -> callable"
11+
[{:keys [node]}]
12+
(let [children (:children node)
13+
obj-node (second children)]
14+
(if obj-node
15+
{:node obj-node}
16+
{:node (api/token-node nil)})))
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
(ns clj-kondo.fixtures.py-dot-test
2-
(:require [libpython-clj2.python :refer [py. py..]]))
2+
(:require [libpython-clj2.python :refer [py. py.. py.- py* py**]]))
33

4-
(defn test-py-dot []
4+
(defn test-py-macros []
55
(let [obj {:foo "bar"}]
66
(py. obj method arg1 arg2)
7-
(py.. obj method1 method2 method3)))
7+
(py.. obj method1 method2 method3)
8+
(py.- obj attribute)
9+
(py* callable [arg1 arg2])
10+
(py** callable [arg1] {:kwarg1 val1})))

0 commit comments

Comments
 (0)