Skip to content

fix(core): materialise TableList iterable so bool/len work - #710

Merged
bosd merged 2 commits into
camelot-dev:masterfrom
bosd:fix/655-tablelist-iterable
May 20, 2026
Merged

bosd merged 2 commits into
camelot-dev:masterfrom
bosd:fix/655-tablelist-iterable

Conversation

@bosd

@bosd bosd commented May 19, 2026

Copy link
Copy Markdown
Collaborator

Closes #655.

TableList.__init__ accepts Iterable[Table] per its type annotation but stored the value unchanged. __len__ (and therefore __bool__) only worked for Sized containers, so the documented usage:

bool(TableList(x for x in old_tablelist))

raised TypeError: object of type 'generator' has no len().

Materialise the iterable once in __init__ (i.e. list(tables)). Adds a regression test covering empty and non-empty generators.

…erable

TableList.__init__ accepts Iterable[Table] per its type annotation but
stored it as-is, so __len__ (and therefore __bool__) only worked for
Sized inputs. Constructing TableList from a generator and then
evaluating it as bool — exactly the documented usage — raised
TypeError: object of type 'generator' has no len().

Materialise the iterable to a list once in __init__. Adds a regression
test that covers an empty and a non-empty generator input. Closes camelot-dev#655.
@bosd
bosd force-pushed the fix/655-tablelist-iterable branch from e1c1afa to 0de5c09 Compare May 19, 2026 23:21
@bosd bosd added the enhancement New feature or request label May 20, 2026
@bosd
bosd merged commit bae84c5 into camelot-dev:master May 20, 2026
15 checks passed
@bosd
bosd deleted the fix/655-tablelist-iterable branch May 20, 2026 08:02
bosd added a commit that referenced this pull request May 20, 2026
The test_tablelist_accepts_iterable from #710 used plain object() as
TableList input, which broke the typeguard CI session once #715 landed
the `__getitem__(...) -> Table` annotation:

  typeguard.TypeCheckError: the return value (object) is not an
  instance of camelot.core.Table

Replace the sentinels with MagicMock(spec=Table). isinstance() passes
on those (via the spec), the identity assertions (`is`) still work,
and typeguard is satisfied. The test still exercises the original bug
(__bool__/__len__ on a generator-built TableList).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

boolean evalutation of TableList breaks when its tables are an iterable

1 participant