Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

composing generator expression doesn't work as expected #80808

Closed
TsvikaShapira mannequin opened this issue Apr 14, 2019 · 2 comments
Closed

composing generator expression doesn't work as expected #80808

TsvikaShapira mannequin opened this issue Apr 14, 2019 · 2 comments
Labels
3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error

Comments

@TsvikaShapira
Copy link
Mannequin

TsvikaShapira mannequin commented Apr 14, 2019

BPO 36627
Superseder
  • bpo-7423: nested generator expression produces strange results
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-04-14.10:15:16.891>
    created_at = <Date 2019-04-14.09:32:03.322>
    labels = ['invalid', 'type-bug', '3.7']
    title = "composing generator expression doesn't work as expected"
    updated_at = <Date 2019-04-14.10:15:16.886>
    user = 'https://bugs.python.org/TsvikaShapira'

    bugs.python.org fields:

    activity = <Date 2019-04-14.10:15:16.886>
    actor = 'SilentGhost'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-04-14.10:15:16.891>
    closer = 'SilentGhost'
    components = []
    creation = <Date 2019-04-14.09:32:03.322>
    creator = 'Tsvika Shapira'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36627
    keywords = []
    message_count = 2.0
    messages = ['340200', '340203']
    nosy_count = 2.0
    nosy_names = ['SilentGhost', 'Tsvika Shapira']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = '7423'
    type = 'behavior'
    url = 'https://bugs.python.org/issue36627'
    versions = ['Python 3.6', 'Python 3.7']

    @TsvikaShapira
    Copy link
    Mannequin Author

    TsvikaShapira mannequin commented Apr 14, 2019

    the following code:

    lists_to_filter = [
        ['a', 'exclude'],
        ['b']
    ]
    # notice that when 'exclude' is the last element, the code returns the expected result
    for exclude_label in ['exclude', 'something']:
        lists_to_filter = (labels_list for labels_list in lists_to_filter if exclude_label not in labels_list)
        # notice that changing the line above to the commented line below (i.e. expanding the generator to a list) will make the code output the expected result, 
        # i.e. the issue is only when using filter on another filter, and not on a list
        # lists_to_filter = [labels_list for labels_list in lists_to_filter if exclude_label not in labels_list]
    lists_to_filter = list(lists_to_filter)
    print(lists_to_filter)
    

    as far as i understand, the code above should output "[['b']]"
    instead it outputs "[['a', 'exclude'], ['b']]"

    @TsvikaShapira TsvikaShapira mannequin added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Apr 14, 2019
    @SilentGhost
    Copy link
    Mannequin

    SilentGhost mannequin commented Apr 14, 2019

    I probably won't be able to better explain the issue then Benjamin did in the referenced issue. Just to note, that (...) in your code are called generator expressions.

    @SilentGhost SilentGhost mannequin closed this as completed Apr 14, 2019
    @SilentGhost SilentGhost mannequin changed the title composing filter() doesn't work as expected composing generator expression doesn't work as expected Apr 14, 2019
    @SilentGhost SilentGhost mannequin added the invalid label Apr 14, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants