https://github.com/python/cpython/blame/master/Lib/unittest/test/testmock/testwith.py#L16
On Mon, Sep 28, 2020 at 12:00 PM Wes Turner <[email protected]> wrote: > `my_dict = (json.load(f) with open(filename.json, "r") as f)` > > Would that be called a generator expression / comprehension context > manager? > > https://docs.python.org/3/reference/datamodel.html#context-managers > > https://docs.python.org/3/library/contextlib.html > > PEP 343 added the "with" statement. > > Tests that would need to be extended / that may be useful references: > > https://github.com/python/cpython/blob/master/Lib/test/test_with.py > > https://github.com/python/cpython/blob/master/Lib/test/test_contextlib.py > > > https://github.com/python/cpython/blob/master/Lib/test/test_contextlib_async.py > > > https://github.com/python/cpython/blob/master/Lib/test/test_grammar.py#L1701 > test_with_statement > > > https://github.com/python/cpython/blob/master/Lib/test/test_grammar.py#L1864 > test_async_with > > https://github.com/python/cpython/blob/master/Grammar/python.gram > > Would there be any new scope issues? > > > On Mon, Sep 28, 2020, 11:12 AM Eric Wieser <[email protected]> > wrote: > >> This reminds me of a previous proposal I can't remember if I hit the list >> with, allowing >> >> with open(filename.json, "r") as f: >> my_dict = json.load(f) >> >> to be spelt as a single expression: >> >> my_dict = (json.load(f) with open(filename.json, "r") as f) >> >> Obviously this would be more useful in comprehensions, but it might >> encourage people not to lazily write `json.load(open("filename.json", >> "r"))` because they want an expression, and end up leaving files open. >> >> Eric >> _______________________________________________ >> Python-ideas mailing list -- [email protected] >> To unsubscribe send an email to [email protected] >> https://mail.python.org/mailman3/lists/python-ideas.python.org/ >> Message archived at >> https://mail.python.org/archives/list/[email protected]/message/QR233SIBDHWDZLKWURUHXG37BDWJHA7Z/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> >
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/NA2J2YOYWXGNAUWHDWMD6TGDXMHIT5CX/ Code of Conduct: http://python.org/psf/codeofconduct/
