Skip to content

Commit 36e4677

Browse files
committed
Add py. and py.. hooks
1 parent 6f1cc55 commit 36e4677

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
libpython-clj.require/require-python
1111
hooks.libpython-clj.require.require-python/require-python
1212
libpython-clj2.require/require-python
13-
hooks.libpython-clj.require.require-python/require-python}}
13+
hooks.libpython-clj.require.require-python/require-python
14+
15+
libpython-clj2.python/py..
16+
hooks.libpython-clj.python.py-dot-dot/py..
17+
libpython-clj2.python/py.
18+
hooks.libpython-clj.python.py-dot-dot/py..}}
1419

1520
:linters
1621
{:unresolved-namespace
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(ns hooks.libpython-clj.python.py-dot-dot
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn py..
5+
"Transform py.. to just evaluate the object, ignoring method/attribute symbols.
6+
(py.. obj method arg) -> obj"
7+
[{:keys [node]}]
8+
(let [children (:children node)
9+
obj-node (second children)]
10+
(if obj-node
11+
{:node obj-node}
12+
{:node (api/token-node nil)})))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(ns clj-kondo.fixtures.py-dot-test
2+
(:require [libpython-clj2.python :refer [py. py..]]))
3+
4+
(defn test-py-dot []
5+
(let [obj {:foo "bar"}]
6+
(py. obj method arg1 arg2)
7+
(py.. obj method1 method2 method3)))

test/clj_kondo/hook_test.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@
3535
(str "Found require-python errors in output:\n" output))
3636
(is (not (has-unresolved-refer-errors? output))
3737
(str "Found unresolved symbol errors for referred symbols:\n" output)))))
38+
39+
(defn- has-py-dot-errors? [output]
40+
(boolean (re-find #"(Unresolved symbol: py\.|unresolved var.*py\.)" output)))
41+
42+
(deftest py-dot-hook-test
43+
(testing "py_dot_test.clj - py. and py.. macros"
44+
(let [{:keys [out err]} (run-clj-kondo (str fixtures-dir "/py_dot_test.clj"))
45+
output (str out err)]
46+
(is (not (has-py-dot-errors? output))
47+
(str "Found py. related errors in output:\n" output)))))

0 commit comments

Comments
 (0)