Skip to content

Commit 63ba73f

Browse files
authored
Adress issue with intern not working (#725)
Hi, could you please review patch to fix `intern`. It addresses #724. It was using var methods such as `.set-root` that don't exist. Tests included. Thanks --------- Co-authored-by: ikappaki <[email protected]>
1 parent 44760b6 commit 63ba73f

File tree

7 files changed

+44
-9
lines changed

7 files changed

+44
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
* Fix `(is (= exp act))` should only evaluate its args once on failure (#712).
1414
* Fix issue with `with` failing with a traceback error when an exception is thrown (#714).
1515
* Fix issue with `sort-*` family of funtions returning an error on an empty seq (#716).
16+
* Fix issue with `intern` failing when used (#725).
1617

1718
## [v0.1.0a2]
1819
### Added

docs/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
sphinx~=4.4.0
1+
sphinx~=4.4.0
2+
sphinx-rtd-theme==1.3.0

src/basilisp/core.lpy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4533,13 +4533,13 @@
45334533
the root binding to ``val``\\, if provided. The namespace must exist. Return the Var."
45344534
([ns name]
45354535
(let [ns (the-ns ns)
4536-
v (basilisp.lang.runtime/Var ns name)]
4537-
(.intern ns v)))
4536+
v (basilisp.lang.runtime/Var ns name ** :meta {:ns ns :name name})]
4537+
(.intern ns name v)))
45384538
([ns name val]
45394539
(let [ns (the-ns ns)
4540-
v (basilisp.lang.runtime/Var ns name)]
4541-
(.set-root v val)
4542-
(.intern ns v))))
4540+
v (basilisp.lang.runtime/Var ns name ** :meta {:ns ns :name name})]
4541+
(.bind-root v val)
4542+
(.intern ns name v))))
45434543

45444544
(defn ^:inline create-ns
45454545
"Create a Namespace with the name ``ns-sym`` or return the existing one if it already

src/basilisp/lang/compiler/analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def __init__(
333333
self._func_ctx: Deque[FunctionContext] = collections.deque([])
334334
self._is_quoted: Deque[bool] = collections.deque([])
335335
self._opts = (
336-
Maybe(opts).map(lmap.map).or_else_get(lmap.PersistentMap.empty()) # type: ignore
336+
Maybe(opts).map(lmap.map).or_else_get(lmap.PersistentMap.empty()) # type: ignore[arg-type, unused-ignore]
337337
)
338338
self._recur_points: Deque[RecurPoint] = collections.deque([])
339339
self._should_macroexpand = should_macroexpand

src/basilisp/lang/compiler/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3527,7 +3527,7 @@ def _const_type_to_py_ast(form: IType, ctx: GeneratorContext) -> GeneratedPyAST:
35273527

35283528
ctor_args = []
35293529
ctor_arg_deps: List[ast.AST] = []
3530-
for field in attr.fields(tp): # type: ignore[arg-type]
3530+
for field in attr.fields(tp): # type: ignore[arg-type, misc, unused-ignore]
35313531
field_nodes = _const_val_to_py_ast(getattr(form, field.name, None), ctx)
35323532
ctor_args.append(field_nodes.node)
35333533
ctor_args.extend(field_nodes.dependencies)

src/basilisp/lang/runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ def add_generated_python(
19631963
which_ns = get_current_ns()
19641964
v = Maybe(which_ns.find(sym.symbol(GENERATED_PYTHON_VAR_NAME))).or_else(
19651965
lambda: Var.intern(
1966-
which_ns, # type: ignore
1966+
which_ns, # type: ignore[arg-type, unused-ignore]
19671967
sym.symbol(GENERATED_PYTHON_VAR_NAME),
19681968
"",
19691969
dynamic=True,

tests/basilisp/test_core_fns.lpy

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,39 @@
13631363
;; a valid symbol in that namespace
13641364
(is (= (resolve 'basilisp.shell/sh) (requiring-resolve 'basilisp.shell/sh))))
13651365

1366+
(deftest intern-test
1367+
(let [ns-sym (gensym "intern-test-ns")
1368+
ns0 (create-ns ns-sym)]
1369+
(testing "unbound"
1370+
(let [sym (gensym "intern-test")
1371+
v (intern ns0 sym)
1372+
{:keys [name ns] :as m} (meta v)]
1373+
(is (= ns0 ns))
1374+
(is (= sym name))
1375+
(is (= false (.-is-bound v)))))
1376+
1377+
(testing "unbound ns-sym"
1378+
(let [sym (gensym "intern-test")
1379+
v (intern ns-sym sym)
1380+
{:keys [name ns] :as m} (meta v)]
1381+
(is (= ns0 ns))
1382+
(is (= sym name))
1383+
(is (= false (.-is-bound v)))))
1384+
1385+
(testing "bound"
1386+
(let [sym (gensym "intern-test")
1387+
v (intern ns0 sym 5)
1388+
{:keys [name ns] :as m} (meta v)]
1389+
(is (= ns0 ns))
1390+
(is (= sym name))
1391+
(is (= true (.-is-bound v)))
1392+
(is (= 5 @v))
1393+
(is (= v (find-var (symbol (str ns0) (str sym))))))))
1394+
1395+
1396+
(testing "ns-not-exists"
1397+
(is (thrown? python/AttributeError (intern 'ns-non-existant 'xyz)))))
1398+
13661399
;;;;;;;;;;;;;;;;;
13671400
;; Hierarchies ;;
13681401
;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)