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

Context manager cannot be used with 'as' #1

Closed
andy-maier opened this issue Dec 6, 2016 · 1 comment
Closed

Context manager cannot be used with 'as' #1

andy-maier opened this issue Dec 6, 2016 · 1 comment

Comments

@andy-maier
Copy link

I was trying to use the as clause along with the context manager abilities of the Spinner class in order to remember the Spinner object, because I want to temporarily suspend the spinner during a password prompt that may happen while executing the code that has the spinner turned on.

However, that resulted in a value of None in the name specified in the as clause.

For example:

with click_spinner.spinner() as sp:
    print(sp)

will print None.

Even if there is not much value currently in having the Spinner object at hand, I think it is part of the contract for a context manager to be able to support the `as´ clause.

Solution: Python uses the return value of the __enter__() method to bind the name specified in the as clause to. So in order to support the as clause, the __enter__() method of the Spinner class needs to return self.

@andy-maier
Copy link
Author

Fixed in PR #2.

@yoavram yoavram closed this as completed Dec 7, 2016
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