Skip to content

Preserve metadata on collection operations #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
* Fix a bug where symbols and keyword containing `:` characters in the name were rejected by the reader (#1105)
* Fix a bug where records did not support reducing via `reduce-kv` (#1102)
* Fix a bug where collection modifying library functions such as `conj`, `disj`, `assoc`, `dissoc`, and `empty` would not preserve collection metadata (#1103)

## [v0.3.0]
### Added
Expand Down
2 changes: 1 addition & 1 deletion src/basilisp/contrib/sphinx/autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def get_object_members(self, want_all: bool) -> tuple[bool, list[ObjectMember]]:
assert isinstance(proto, IPersistentMap)
proto_methods = cast(
IPersistentMap[kw.Keyword, Any],
proto.val_at(_METHODS_KW, lmap.PersistentMap.empty()),
proto.val_at(_METHODS_KW, lmap.EMPTY),
)
return False, list(
map(
Expand Down
4 changes: 2 additions & 2 deletions src/basilisp/lang/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from typing_extensions import Concatenate, ParamSpec

from basilisp.lang import map as lmap
from basilisp.lang.interfaces import IPersistentMap, RefValidator
from basilisp.lang.map import PersistentMap
from basilisp.lang.reference import RefBase

T = TypeVar("T")
Expand All @@ -23,7 +23,7 @@ def __init__(
self._meta: Optional[IPersistentMap] = meta
self._state = state
self._lock = threading.RLock()
self._watches = PersistentMap.empty()
self._watches = lmap.EMPTY
self._validator = validator

if validator is not None:
Expand Down
12 changes: 5 additions & 7 deletions src/basilisp/lang/compiler/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def __init__(
self._func_ctx: collections.deque[FunctionContext] = collections.deque([])
self._is_quoted: collections.deque[bool] = collections.deque([])
self._opts = (
Maybe(opts).map(lmap.map).or_else_get(lmap.PersistentMap.empty()) # type: ignore[arg-type, unused-ignore]
Maybe(opts).map(lmap.map).or_else_get(lmap.EMPTY) # type: ignore[arg-type, unused-ignore]
)
self._recur_points: collections.deque[RecurPoint] = collections.deque([])
self._should_macroexpand = should_macroexpand
Expand Down Expand Up @@ -808,7 +808,7 @@ def _call_args_ast(
kwargs = lmap.map(kw_map)
else:
args = vec.vector(map(lambda form: _analyze_form(form, ctx), form))
kwargs = lmap.PersistentMap.empty()
kwargs = lmap.EMPTY

return args, kwargs

Expand Down Expand Up @@ -940,7 +940,7 @@ def _def_ast( # pylint: disable=too-many-locals,too-many-statements
if nelems == 2:
init_idx = None
doc = None
children = vec.PersistentVector.empty()
children = vec.EMPTY
elif nelems == 3:
init_idx = 2
doc = None
Expand Down Expand Up @@ -2823,9 +2823,7 @@ def __letfn_fn_body(form: ISeq, ctx: AnalyzerContext) -> Fn:
fn_body = _analyze_form(
fn_rest.cons(
fn_name.with_meta(
(fn_name.meta or lmap.PersistentMap.empty()).assoc(
SYM_NO_WARN_ON_SHADOW_META_KEY, True
)
(fn_name.meta or lmap.EMPTY).assoc(SYM_NO_WARN_ON_SHADOW_META_KEY, True)
)
).cons(fn_sym),
ctx,
Expand Down Expand Up @@ -3456,7 +3454,7 @@ def _yield_ast(form: ISeq, ctx: AnalyzerContext) -> Yield:
@_analyze_form.register(ISeq)
@_with_loc
def _list_node(form: ISeq, ctx: AnalyzerContext) -> Node:
if form == llist.PersistentList.empty():
if form == llist.EMPTY:
with ctx.quoted():
return _const_node(form, ctx)

Expand Down
Loading