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

scoped cannot be used with yield (and probably async and lambdas) in implicit mode #661

Open
zhiltsov-max opened this issue Feb 10, 2022 · 0 comments
Labels
BUG Something isn't working

Comments

@zhiltsov-max
Copy link
Contributor

zhiltsov-max commented Feb 10, 2022

When @scoped is used in implicit mode, it does not make a visible variable in the function context, so when it is used with a generator or lambda, the context is not being captured. This leads to wrong behavior and Scope.current() access errors.

from datumaro.util.scope import scoped, on_exit_do
def bar(): pass

@scoped
def foo():
  on_exit_do(bar)
  yield from [1, 2, 3]

list(foo())

>>>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in foo
  File "datumaro/datumaro/util/scope.py", line 149, in on_exit_do
    return Scope.current().on_exit_do(callback, *args,
AttributeError: 'NoneType' object has no attribute 'on_exit_do'
@zhiltsov-max zhiltsov-max added the BUG Something isn't working label Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant