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

Add a with expression, for use in comprehensions #61988

Closed
eric-wieser mannequin opened this issue Apr 18, 2013 · 3 comments
Closed

Add a with expression, for use in comprehensions #61988

eric-wieser mannequin opened this issue Apr 18, 2013 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@eric-wieser
Copy link
Mannequin

eric-wieser mannequin commented Apr 18, 2013

BPO 17788
Nosy @warsaw, @ericvsmith, @berkerpeksag, @eric-wieser

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 2013-04-18.11:50:34.180>
created_at = <Date 2013-04-18.10:02:40.205>
labels = ['interpreter-core', 'type-feature', 'invalid']
title = 'Add a with expression, for use in comprehensions'
updated_at = <Date 2013-04-18.13:18:21.172>
user = 'https://github.com/eric-wieser'

bugs.python.org fields:

activity = <Date 2013-04-18.13:18:21.172>
actor = 'barry'
assignee = 'none'
closed = True
closed_date = <Date 2013-04-18.11:50:34.180>
closer = 'eric.smith'
components = ['Interpreter Core']
creation = <Date 2013-04-18.10:02:40.205>
creator = 'Eric.Wieser'
dependencies = []
files = []
hgrepos = []
issue_num = 17788
keywords = []
message_count = 3.0
messages = ['187232', '187236', '187239']
nosy_count = 4.0
nosy_names = ['barry', 'eric.smith', 'berker.peksag', 'Eric.Wieser']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue17788'
versions = []

@eric-wieser
Copy link
Mannequin Author

eric-wieser mannequin commented Apr 18, 2013

It would be nice if there was a with "expression". Such that instead of:

    with open(...) as f:
        result = foo(f)

One could write:

    result = foo(f) with open(...) as f

This would be particularly useful in comprehensions. Instead of:

    files = {}
    for fname in os.listdir('.'):
        if predicate(fname):
            with open(fname) as f:
                files[fname] = foo(f)

    files = {
        fname: foo(f) with open(fname) as f
        for fname in os.listdir('.') if predicate(fname)
    }

@eric-wieser eric-wieser mannequin added type-feature A feature request or enhancement interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Apr 18, 2013
@berkerpeksag
Copy link
Member

I think this needs to be discussed on python-ideas first.

@ericvsmith
Copy link
Member

Indeed, this should be on python-ideas. Eric: can you start a thread over there? Thanks.

@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
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants