Skip to content

Materialize ignore iterables before collecting rules - #23

Open
hakarrr wants to merge 2 commits into
morepath:masterfrom
hakarrr:fix-22-ignore-iterator
Open

hakarrr wants to merge 2 commits into
morepath:masterfrom
hakarrr:fix-22-ignore-iterator

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 8, 2026

Copy link
Copy Markdown

Fixes #22.

Problem

get_is_ignored iterates the ignore rules twice: once to collect string rules and once to collect callable rules. When the caller passes a one-shot iterable such as an iterator, the first pass exhausts it, so callable rules are silently lost and modules that should be ignored get imported:

rules = [lambda name: name.endswith('ignored')]
scan(pkg, ignore=list(rules))  # works
scan(pkg, ignore=iter(rules))  # callable rule lost, sample.ignored is imported

Fix

Materialize the rules into a list once before the two collection passes. Behavior for lists, single strings and single callables is unchanged.

Tests

New regression test test_ignore_module_function_in_iterator passes a callable rule inside iter([...]) and asserts the matched module is not imported. It fails on master and passes with this change. Full test suite: 24 passed.

hakarrr and others added 2 commits November 9, 2026 01:47
get_is_ignored iterated the ignore rules twice - once for strings and once for callables - so a one-shot iterable (e.g. an iterator) was exhausted before callable rules were collected and they were silently lost. Materialize the rules into a list first. Fixes morepath#22.

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Regression test for issue morepath#22: callable rules keep working when the ignore iterable is a one-shot iterator.

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One-shot ignore iterables lose callable rules during scan

1 participant