jhanarato / uposatha-inky

Display the uposatha on a Pimoroni Inky display
MIT License
0 stars 0 forks source link

Mapping fails on `not all()` #16

Closed jhanarato closed 1 year ago

jhanarato commented 1 year ago

At some point I deleted this test:

def test_should_work_with_all_old_bug():
    appearances = IconCountMapping[Appearance](15)
    appearances[1, 14] = Appearance(1, 2, 3)
    assert not all(appearances)

I've added it again and it still fails.

test_countdown_resize.py::test_should_work_with_all_old_bug FAILED       [ 92%]
test_countdown_resize.py:83 (test_should_work_with_all_old_bug)
def test_should_work_with_all_old_bug():
        appearances = IconCountMapping[Appearance](15)
        appearances[1, 14] = Appearance(1, 2, 3)
>       assert not all(appearances)
E       assert not True
E        +  where True = all(<countdown.IconCountMapping object at 0x7fa0f1be5350>)

test_countdown_resize.py:87: AssertionError
jhanarato commented 1 year ago

Dale says:

all expects an iterable, so when all(appearances) is the equivalent of all(iter(appearances)). For a mapping type, ie a dict-like thing, the default iteration is over the keys. So, a more explicit version of what you wrote is

all(k for k in appearances.keys())

That's assuming appearances behaves like a dict, but since you have control of what it's dunder iter method does, it can do whatever makes the most sense for an Apperances object to do.

jhanarato commented 1 year ago

This is fixed. __iter__ yields all keys or None if missing.