Skip to content

Commit 980ec49

Browse files
committed
Fix: 0.2.1 Bug which causes infinite loop upon iteration of undefined
1 parent c35f90d commit 980ec49

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The examples shown will be using `_` instead of `nullsafe` for code clarity. For
8282

8383
## Implementation
8484

85-
Nullsafe abilities are granted after proxying an object through `NullSafeProxy`. To proxy an object pass it through `_()` or `nullsafe()`. Due to language limitation, the implementation does not follow the "return the first nullish value in chain", instead it "extend the a custom nullish value until the end of chain". Inexistent values of a proxied object and its subsequent values in chain will return `undefined`.
85+
Nullsafe abilities are granted after proxying an object through `NullSafeProxy`. To proxy an object pass it through `_()` or `nullsafe()`. Due to language limitation, the implementation does not follow the "return the first nullish value in chain", instead it "extend `undefined` (custom nullish value) until the end of chain". Inexistent values of a proxied object and its subsequent values in chain will return `undefined`.
8686

8787
## Import
8888

@@ -194,7 +194,7 @@ List of limitations that you may encounter.
194194

195195
### `undefined` behavior
196196

197-
`undefined` is actually an instance of `NullSafe`, the actual mechanism used for nullsafe chaining, it cannot self rip the nullsafe functionality when the chain ends (because it doesn't know), so this following actually possible and probably not the wanted behavior.
197+
`undefined` is actually an instance of `NullSafe`, the actual mechanism used for nullsafe chaining, it cannot self rip the nullsafe functionality when the chain ends (because it doesn't know), so the following instruction is technically correct but probably not the wanted behavior.
198198

199199
```python
200200
val = _(o).inexistent

nullsafe/core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def __str__(self) -> str:
3232
def __setattr__(self, name: str, value: Any) -> None:
3333
raise AttributeError(f"'{self.__class__.__name__}' object can't set attribute")
3434

35+
def __iter__(self):
36+
raise TypeError(f"'{repr(self)}' object is not iterable")
37+
3538

3639
undefined = NullSafe()
3740

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
setup(
2323
name="nullsafe",
24-
version="0.2.0",
24+
version="0.2.1",
2525
author="Paaksing",
2626
author_email="paaksingtech@gmail.com",
2727
url="https://github.com/paaksing/nullsafe-python",

test/test_cases.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,11 @@ def test_null_call():
239239
assert _(o)["inexistent"]["inexistent"]["dsrghsuiorgh"]() is undefined
240240
assert _(o)["inexistent"]("douihgrf", 35)["inexistent"]["dsrghsuiorgh"]() is undefined
241241
assert _(o)["caller"]({"fakeself"}, "some", 2) == "some2"
242+
243+
244+
def test_iteration_fail():
245+
try:
246+
for _ in undefined:
247+
assert False
248+
except TypeError:
249+
assert True

0 commit comments

Comments
 (0)