Bind with ... as targets to __enter__() return values#788
Open
BI71317 wants to merge 1 commit intoexaloop:developfrom
Open
Bind with ... as targets to __enter__() return values#788BI71317 wants to merge 1 commit intoexaloop:developfrom
with ... as targets to __enter__() return values#788BI71317 wants to merge 1 commit intoexaloop:developfrom
Conversation
Contributor
Author
|
And, yeah. It conflicts every other test cases with current in #%% with,barebones
class Foo:
i: int
def __enter__(self: Foo):
print '> foo! ' + str(self.i)
def __exit__(self: Foo):
print '< foo! ' + str(self.i)
def foo(self: Foo):
print 'woof'
class Bar:
s: str
def __enter__(self: Bar):
print '> bar! ' + self.s
def __exit__(self: Bar):
print '< bar! ' + self.s
def bar(self: Bar):
print 'meow'
with Foo(0) as f:
#: > foo! 0
f.foo() #: woof
#: < foo! 0
with Foo(1) as f, Bar('s') as b:
#: > foo! 1
#: > bar! s
f.foo() #: woof
b.bar() #: meow
#: < bar! s
#: < foo! 1
with Foo(2), Bar('t') as q:
#: > foo! 2
#: > bar! t
print 'eeh' #: eeh
q.bar() #: meow
#: < bar! t
#: < foo! 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Limitation of this PR
This PR addresses only the first item of #787 : binding the result of
__enter__()to theastarget.Current state in pseudo code
The below code interpreted differently in each codon and python:
In Codon
Lowering current
with syntax in Codonbehaves conceptually like this:In Codon,
pairrefers to theManager Class instancein Codon, and the return value of__enter__()is discarded.In Python
In a While,
with syntax in Pythonbehaves like below pseudo code:https://docs.python.org/3/reference/compound_stmts.html#the-with-statement
In Python,
pairrefers to the return value of__enter__().What this PR fixes
Conceptually, lowering changes to: