Skip to content

Commit 023ddfa

Browse files
authored
Fix lazy sequences not propagating AttributeError #1019 (#1021)
Fixes #1019
1 parent a1fa690 commit 023ddfa

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Changed
9-
* Exceptions occurring during inlining during macroexpansion are no longer obscured by the outer macroexpansion exception (#1013)
9+
* Exceptions occurring during inlining during macroexpansion are no longer obscured by the outer macroexpansion exception (#1013)
1010

1111
### Fixed
1212
* Fix the behaviour of `nil` with several collection functions (#1011)
1313
* Fix a bug where `keys` and `vals` did not yield keys and values from sequences of map entries (#1018)
1414
* Fix a bug where `set` and `vec` do not produce collections of map entries when called on map arguments (#1020)
15+
* Fix lazy sequences not propagating `AttributeError` (#1019)
1516

1617
## [v0.2.0]
1718
### Added

src/basilisp/lang/seq.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,15 @@ def is_empty(self) -> bool:
194194

195195
@property
196196
def first(self) -> Optional[T]:
197-
try:
198-
return self.seq().first # type: ignore[union-attr]
199-
except AttributeError:
197+
if self.is_empty:
200198
return None
199+
return self.seq().first # type: ignore[union-attr]
201200

202201
@property
203202
def rest(self) -> "ISeq[T]":
204-
try:
205-
return self.seq().rest # type: ignore[union-attr]
206-
except AttributeError:
203+
if self.is_empty:
207204
return EMPTY
205+
return self.seq().rest # type: ignore[union-attr]
208206

209207
def cons(self, *elems: T) -> ISeq[T]: # type: ignore[override]
210208
l: ISeq = self

tests/basilisp/seq_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from basilisp.lang import keyword as kw
24
from basilisp.lang import list as llist
35
from basilisp.lang import runtime as runtime
@@ -72,6 +74,16 @@ def inner_inner_seq():
7274

7375
assert [1, 2, 3] == [e for e in s]
7476

77+
def raise_error(er):
78+
raise er
79+
80+
s = lseq.LazySeq(lambda: raise_error(BaseException))
81+
with pytest.raises(BaseException):
82+
s.first
83+
s = lseq.LazySeq(lambda: raise_error(AttributeError))
84+
with pytest.raises(AttributeError):
85+
s.first
86+
7587

7688
def test_empty_sequence():
7789
empty = lseq.sequence([])

0 commit comments

Comments
 (0)