tbodt / v8py

Write Python APIs, then call them from JavaScript using the V8 engine.
GNU Lesser General Public License v3.0
440 stars 28 forks source link

Make v8py.Context a Python context manager #7

Closed buffer closed 7 years ago

tbodt commented 7 years ago

Why is it useful for Context to be a context manager?

tbodt commented 7 years ago

Also, creating a context fails on Python 3:

self = <v8py.context.Context object at 0x7ff3ba7d0518>
args = (<class 'test_global.Global.<locals>.Global'>,), kwargs = {}
    def __init__(self, *args, **kwargs):
>       _v8py.Context.__init__(self, *args, **kwargs)
E       TypeError: object.__init__() takes no parameters
v8py/context.py:5: TypeError
buffer commented 7 years ago

Context as a context manager could be useful so that it can be used directly in with statements without first having to be wrapped by contextlib.closing(). Apart from being a Pythonic approach, it would also allow to manage some initialization/destruction details transparently in the next future if needed.

tbodt commented 7 years ago

In v8py, contexts don't need to be opened or closed, they can just be used.