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

built-in objects __exit__ method is not picked up in contexts #28

Closed
raff opened this issue Sep 8, 2018 · 1 comment
Closed

built-in objects __exit__ method is not picked up in contexts #28

raff opened this issue Sep 8, 2018 · 1 comment

Comments

@raff
Copy link
Contributor

raff commented Sep 8, 2018

I added the M__exit__ method to file to support "with open() as f" but the execution fails as following:

>>> with open("testfile") as f:
...   print("hello")
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    FIXME line of source goes here
AttributeError: AttributeError: "'file' has no attribute '__exit__'"

The code in this case is only checking for the exit attribute instead of also checking for the implemented interface.

I see this comment:

 // exit := py.ObjectLookupSpecial(mgr, "__exit__")

But I am not sure of how ObjectLookSpecial could be implemented.

An easier way to do this, but it feels "wrong", would be to add an exit method in the object dictionary.

@ncw ncw closed this as completed in 8cee534 Sep 10, 2018
@ncw
Copy link
Collaborator

ncw commented Sep 10, 2018

I have fixed that now so I think it should work properly and call the __exit__ !

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