Skip to content

Commit 77e2f29

Browse files
authored
Fixed issue with import modules aliasing using ns eval (#719) (#728)
Hi, could you please review patch to fix issue with import name aliasing in the context of an `eval` operation. It addresses #719. (part of breaking the individual bugfixes from #723) Thanks. Co-authored-by: ikappaki <[email protected]>
1 parent 78d841a commit 77e2f29

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
* Fix issue with `sort-*` family of funtions returning an error on an empty seq (#716).
1616
* Fix issue with `intern` failing when used (#725).
1717
* Fix issue with `ns` not being available after `in-ns` on the REPL (#718).
18+
* Fixed issue with import modules aliasing using ns eval (#719).
1819

1920
## [v0.1.0a2]
2021
### Added

src/basilisp/core.lpy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4642,7 +4642,13 @@
46424642
Use of ``import`` directly is discouraged in favor of the ``:import`` directive in
46434643
the :lpy:fn:`ns` macro."
46444644
[& modules]
4645-
`(import* ~@modules))
4645+
;; We need to use eval here, because there could have been an ns
4646+
;; switch inside an eval earlier, and although *ns* is correctly set
4647+
;; to the new ns, the global python namespace can still refer to the
4648+
;; old python global ns where the import would have been evaluated
4649+
;; otherwise.
4650+
(let [form `(import* ~@modules)]
4651+
`(eval '~form *ns*)))
46464652

46474653
(defn ^:private rewrite-clojure-libspec
46484654
"Rewrite libspecs which point to namespaces starting with 'clojure.' to use a

tests/basilisp/test_core_fns.lpy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,4 +2021,10 @@
20212021
(binding [*ns* *ns*]
20222022
(eval '(in-ns 'test-core-fns.ns-after-in-ns))
20232023
(eval '(ns test-core-fns.ns-after-in-ns))
2024-
(is (= *ns* (the-ns 'test-core-fns.ns-after-in-ns))))))
2024+
(is (= *ns* (the-ns 'test-core-fns.ns-after-in-ns)))))
2025+
2026+
(testing "eval ns with import aliases"
2027+
(binding [*ns* *ns*]
2028+
(eval '(ns test-core-fns.ns-with-import (:import [time :as time-alias])))
2029+
(is (= *ns* (the-ns 'test-core-fns.ns-with-import)))
2030+
(is (= "Thu Jan 1 00:00:01 1970" (eval '(time-alias/asctime (time-alias/gmtime 1))))))))

0 commit comments

Comments
 (0)