Skip to content

[ANY …] toggle drops its section when the selection list has multiple entries and a non-matching one comes first #619

Description

@AntoineGautier

mogrifier.evaluate_annotation passes a lazy map object to utils.common_member, which tests membership with i in l2 inside a list comprehension. The first i in l2 consumes the one-shot iterator; every subsequent lookup sees it empty. When the resolved selection list (selections[long_name]) has more than one element and a non-matching element is iterated before a matching one, common_member returns [] and the [ANY …] section is wrongly deleted.

Root cause

server/scripts/sequence-doc/src/mogrifier.py:390 (ANY branch):

long_compare = map(lambda name: name_map[name], short_compare)
...
elif not utils.common_member(selections[long_name], long_compare):

server/scripts/sequence-doc/src/utils.py:6:

def common_member(l1, l2) -> bool:
    return [i for i in l1 if i in l2]   # `i in l2` consumes l2 when l2 is an iterator

Fix

Materialize before membership testing — either:

# mogrifier.py, ANY branch
long_compare = [name_map[name] for name in short_compare]

or harden the helper:

# utils.py
def common_member(l1, l2) -> bool:
    l2 = list(l2)
    return [i for i in l1 if i in l2]

Sub-issue: Sequence doc tests not integrated in CI

It turns out that server/scripts/sequence-doc/tests/test_sequence_doc.py is not part of the CI workflow.
This ticket will integrate it and add the unit tests for the issue above.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Top PriorityTop of the Priority ListbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions