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

Why not support "with" keyword? #67

Open
ethe opened this issue May 31, 2016 · 2 comments
Open

Why not support "with" keyword? #67

ethe opened this issue May 31, 2016 · 2 comments

Comments

@ethe
Copy link

ethe commented May 31, 2016

Does not below two ways equal?

class Foo(object):
    def __enter__(self):
        print "hello, world"

    def __exit__(self, type, value, tb):
        print "bye"


with Foo() as foo:
    pass


mgr = Foo()
exit = type(mgr).__exit__
value = type(mgr).__enter__(mgr)
exc = True
try:
    try:
        foo = value
        pass
    except:
        exc = False
        if not exit(mgr, *sys.exc_info()):
            raise
finally:
    if exc:
        exit(mgr, None, None, None)
@andersk
Copy link
Collaborator

andersk commented May 31, 2016

We’re familiar with PEP 343, yes. This is an implementation challenge, not a conceptual challenge. (Learning how to catch exceptions was the conceptual challenge.) There’s a not-quite-working attempt to support with at #59.

@ethe
Copy link
Author

ethe commented Jun 1, 2016

@andersk Thanks, but yield has some theoretical limits to be supported, doesn't it? Lambda calculus can not express call/cc simply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants