Skip to content

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

Closed
@raff

Description

@raff

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions