Skip to content

Complexity in list comprehensions #69

Open
@Peque

Description

@Peque

Having asdf.py:

elements = [0, 1, 2, 3, 4]
ignore = [1, 2]


def loop():
    for x in elements:
        if x in ignore:
            continue
        print(x)


def comprehension():
    filtered = [x for x in elements if x not in ignore]
    for x in filtered:
        print(x)


loop()
print('----')
comprehension()

The McCabe complexity in loop() seems to be higher than in comprehension():

$ python -m mccabe asdf.py 
5:0: 'loop' 3
12:0: 'comprehension' 2

Is that really expected? Should not fors and ifs in list comprehensions count towards total complexity?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions