You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs/pyinterop.rst: elucidate syntax around referencing things within modules (#1263)
I find the initial writeup a bit terse, and also not clear and somewhat
confusing for me. I hope you will accept this edit; I think this is an
improvement, and helps elucidate and call out the one thing that
confused me: namely, how referencing stuff within a class effectively
creates its own namespace, something that took this used-to-Clojure
brain some time to grok (making this PR was also part of my process).
Thank you for Basilisp!
Copy file name to clipboardExpand all lines: docs/pyinterop.rst
+38-6Lines changed: 38 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -104,15 +104,47 @@ It is also possible to refer all module members into the namespace using ``:refe
104
104
Referencing Module Members
105
105
--------------------------
106
106
107
-
Once a Python module is imported into the current Namespace, it is trivial to reference module members directly.
108
-
References to Python module members appear identical to qualified Basilisp Namespace references.
109
-
Class constructors or other callables in the module can be called directly as a standard Basilisp function call.
110
-
Static members and class members can be referenced by adding the class name to the (potentially) qualified symbol namespace, separated by a single ``.``.
107
+
Once a Python module is imported into the current Namespace, it is trivial to reference things (if a bit unintuitive for Class members if you're used to Clojure syntax; but more on that later) within the module.
108
+
109
+
References to Python module top-level members are as expected, with the namespace at the front, followed by a ``/``, and then the name of the member:
;; top-level callables within the module can be called as you would a standard Basilisp function call
135
+
(src.boo/module-method)
136
+
(src.boo/BooClass)
137
+
138
+
For referencing members within classes, Basilisp expects that you tack on the class name with a leading ``.`` to the (potentially) qualified namespace symbol:
139
+
140
+
.. code-block:: clojure
141
+
142
+
(import src.boo)
143
+
144
+
(src.boo.BooClass/class-var) ;; => "BooClass class variable!"
145
+
(src.boo.BooClass/some-class-method) ;; => "hello from <class 'src.test.BooClass'>!"
146
+
147
+
Notice that for these cases the class (name) effectively becomes a namespace of its own, even if it is not defined in a separate file. This is unlike Clojure.
0 commit comments