Skip to content

Why not support "with" keyword? #67

Description

@ethe

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions