Skip to content

Commit 7cc260f

Browse files
authored
Preserve metadata on collection operations (#1115)
Fixes #1103
1 parent 27f7d01 commit 7cc260f

28 files changed

+369
-347
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
### Fixed
1212
* Fix a bug where symbols and keyword containing `:` characters in the name were rejected by the reader (#1105)
1313
* Fix a bug where records did not support reducing via `reduce-kv` (#1102)
14+
* Fix a bug where collection modifying library functions such as `conj`, `disj`, `assoc`, `dissoc`, and `empty` would not preserve collection metadata (#1103)
1415

1516
## [v0.3.0]
1617
### Added

src/basilisp/contrib/sphinx/autodoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def get_object_members(self, want_all: bool) -> tuple[bool, list[ObjectMember]]:
380380
assert isinstance(proto, IPersistentMap)
381381
proto_methods = cast(
382382
IPersistentMap[kw.Keyword, Any],
383-
proto.val_at(_METHODS_KW, lmap.PersistentMap.empty()),
383+
proto.val_at(_METHODS_KW, lmap.EMPTY),
384384
)
385385
return False, list(
386386
map(

src/basilisp/lang/atom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
from typing_extensions import Concatenate, ParamSpec
55

6+
from basilisp.lang import map as lmap
67
from basilisp.lang.interfaces import IPersistentMap, RefValidator
7-
from basilisp.lang.map import PersistentMap
88
from basilisp.lang.reference import RefBase
99

1010
T = TypeVar("T")
@@ -23,7 +23,7 @@ def __init__(
2323
self._meta: Optional[IPersistentMap] = meta
2424
self._state = state
2525
self._lock = threading.RLock()
26-
self._watches = PersistentMap.empty()
26+
self._watches = lmap.EMPTY
2727
self._validator = validator
2828

2929
if validator is not None:

src/basilisp/lang/compiler/analyzer.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def __init__(
331331
self._func_ctx: collections.deque[FunctionContext] = collections.deque([])
332332
self._is_quoted: collections.deque[bool] = collections.deque([])
333333
self._opts = (
334-
Maybe(opts).map(lmap.map).or_else_get(lmap.PersistentMap.empty()) # type: ignore[arg-type, unused-ignore]
334+
Maybe(opts).map(lmap.map).or_else_get(lmap.EMPTY) # type: ignore[arg-type, unused-ignore]
335335
)
336336
self._recur_points: collections.deque[RecurPoint] = collections.deque([])
337337
self._should_macroexpand = should_macroexpand
@@ -808,7 +808,7 @@ def _call_args_ast(
808808
kwargs = lmap.map(kw_map)
809809
else:
810810
args = vec.vector(map(lambda form: _analyze_form(form, ctx), form))
811-
kwargs = lmap.PersistentMap.empty()
811+
kwargs = lmap.EMPTY
812812

813813
return args, kwargs
814814

@@ -940,7 +940,7 @@ def _def_ast( # pylint: disable=too-many-locals,too-many-statements
940940
if nelems == 2:
941941
init_idx = None
942942
doc = None
943-
children = vec.PersistentVector.empty()
943+
children = vec.EMPTY
944944
elif nelems == 3:
945945
init_idx = 2
946946
doc = None
@@ -2823,9 +2823,7 @@ def __letfn_fn_body(form: ISeq, ctx: AnalyzerContext) -> Fn:
28232823
fn_body = _analyze_form(
28242824
fn_rest.cons(
28252825
fn_name.with_meta(
2826-
(fn_name.meta or lmap.PersistentMap.empty()).assoc(
2827-
SYM_NO_WARN_ON_SHADOW_META_KEY, True
2828-
)
2826+
(fn_name.meta or lmap.EMPTY).assoc(SYM_NO_WARN_ON_SHADOW_META_KEY, True)
28292827
)
28302828
).cons(fn_sym),
28312829
ctx,
@@ -3456,7 +3454,7 @@ def _yield_ast(form: ISeq, ctx: AnalyzerContext) -> Yield:
34563454
@_analyze_form.register(ISeq)
34573455
@_with_loc
34583456
def _list_node(form: ISeq, ctx: AnalyzerContext) -> Node:
3459-
if form == llist.PersistentList.empty():
3457+
if form == llist.EMPTY:
34603458
with ctx.quoted():
34613459
return _const_node(form, ctx)
34623460

0 commit comments

Comments
 (0)