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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
7
7
## [Unreleased]
8
+
### Added
9
+
* Added support for referring imported Python names as by `from ... import ...` (#1154)
8
10
9
11
## [v0.3.8]
10
12
### Added
@@ -18,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
18
20
* Fix an issue where consecutive reader comment forms would not be ignored (#1207)
19
21
20
22
## [v0.3.7]
21
-
### Fixed
23
+
### Fixed
22
24
* Fix a regression introduced in #1176 where the testrunner couldn't handle relative paths in `sys.path`, causing `basilisp test` to fail when no arugments were provided (#1204)
23
25
* Fix a bug where `basilisp.process/exec` could deadlock reading process output if that output exceeded the buffer size (#1202)
24
26
* Fix `basilisp boostrap` issue on MS-Windows where the boostrap file loaded too early, before Basilisp was in `sys.path` (#1208)
Copy file name to clipboardExpand all lines: docs/pyinterop.rst
+28-7Lines changed: 28 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,13 +49,39 @@ Submodules will be available under the full, dot-separated name.
49
49
50
50
To avoid name clashes from the above, you may alias imports (as in native Python code) using the same syntax as ``require``.
51
51
Both top-level modules and submodules may be aliased: ``(import [module.sub :as sm])``.
52
-
Note that none of the other convenience features or flags from :lpy:fn:`require` are available, so you will not be able to, say, refer unqualified module members into the current Namespace.
53
52
54
53
.. code-block::
55
54
56
55
(import [os.path :as path])
57
56
(path/exists "test.txt") ;;=> false
58
57
58
+
As with Basilisp ``refers`` (and as in Python), it is possible to refer individual module members by name into the current namespace using the ``:refer`` option.
59
+
It is also possible to refer all module members into the namespace using ``:refer :all``.
60
+
61
+
.. code-block::
62
+
63
+
(import [math :refer [sqrt pi]])
64
+
pi ;; 3.141592653589793
65
+
66
+
(import [statistics :refer :all])
67
+
mean ;; <function mean at 0x...>
68
+
69
+
.. warning::
70
+
71
+
Basilisp refers names into the current module in different conceptual namespaces and resolves names against those namespaces in order of precedence, preferring Basilisp members first.
72
+
Referred Python module members may not resolve if other names take precedence within the current namespace context.
73
+
74
+
.. code-block::
75
+
76
+
(import [datetime :as dt :refer :all])
77
+
78
+
;; This name using the module alias directly will guarantee we are referencing
79
+
;; the module member `datetime.time` (a class)
80
+
dt/time ;; <class 'datetime.time'>
81
+
82
+
;; ...whereas this reference prefers the `basilisp.core` function `time`
83
+
time ;; <function time at 0x...>
84
+
59
85
.. note::
60
86
61
87
Users should generally prefer to use the :lpy:fn:`ns` macro for importing modules into their namespace, rather than using the :lpy:fn:`import` form directly.
@@ -65,14 +91,9 @@ Note that none of the other convenience features or flags from :lpy:fn:`require`
65
91
(ns myproject.ns
66
92
(:import [os.path :as path]))
67
93
68
-
.. warning::
69
-
70
-
Unlike in Python, imported module names and aliases cannot be referred to directly in Basilisp code.
71
-
Module and Namespace names are resolved separately from local names and will not resolve as unqualified names.
0 commit comments