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

missing __enter__ + __getattr__ forwarding #44152

Closed
ocean-city mannequin opened this issue Oct 20, 2006 · 2 comments
Closed

missing __enter__ + __getattr__ forwarding #44152

ocean-city mannequin opened this issue Oct 20, 2006 · 2 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@ocean-city
Copy link
Mannequin

ocean-city mannequin commented Oct 20, 2006

BPO 1581357
Nosy @birkenfeld
Files
  • a.py: the script to reproduce problem
  • a.patch: simply solve only codecs.open
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2006-10-29.14:47:51.000>
    created_at = <Date 2006-10-20.15:17:13.000>
    labels = ['library']
    title = 'missing __enter__ + __getattr__ forwarding'
    updated_at = <Date 2006-10-29.14:47:51.000>
    user = 'https://bugs.python.org/ocean-city'

    bugs.python.org fields:

    activity = <Date 2006-10-29.14:47:51.000>
    actor = 'georg.brandl'
    assignee = 'georg.brandl'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2006-10-20.15:17:13.000>
    creator = 'ocean-city'
    dependencies = []
    files = ['2190', '2191']
    hgrepos = []
    issue_num = 1581357
    keywords = []
    message_count = 2.0
    messages = ['30327', '30328']
    nosy_count = 2.0
    nosy_names = ['georg.brandl', 'ocean-city']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1581357'
    versions = ['Python 2.5']

    @ocean-city
    Copy link
    Mannequin Author

    ocean-city mannequin commented Oct 20, 2006

    Hello. I encountered some unexpected behavior on "with"
    statement.

    First, please run attached "a.py" file.

    # traditional way
    <open file 'a.txt', mode 'wb' at 0x009373C8> shift_jis
    <type 'instance'> True
    # with statement
    <open file 'a.txt', mode 'wb' at 0x009373C8> None <type
    'file'> False
    Traceback (most recent call last):
      File "R:\a.py", line 15, in <module>
        test(io)
      File "R:\a.py", line 8, in test
        io.write(u"�����")
    UnicodeEncodeError: 'ascii' codec can't encode
    characters in position 0-4: ordin
    al not in range(128)

    "traditional way" runs as expected, but "with
    statement" crashes. This happens because....

    1. codecs.open returns codecs.StreamReaderWriter
    2. codecs.StreamReaderWriter defines __getattr__
      like this.
        def __getattr__(self, name,
                        getattr=getattr):
        """ Inherit all other methods from the
            underlying stream.
        """
        return getattr(self.stream, name)
    
    1. But codecs.StreamReaderWriter doesn't have its
      __enter__ definition, so
        srw = StreamReaderWriter(stream, ...
        srw.__enter__() # actually calls stream.__enter__
                          which returns stream not srw
                          via __getattr__
     And more worse, with statement doesn't complain
     StreamReaderWriter (currently) doesn't support
     context manager.
    

    Is this intended behavior? If not, only this problem
    can be solved by attached "a.patch". I greped library
    files, I found many __getattr__ without __enter__...

    @ocean-city ocean-city mannequin closed this as completed Oct 20, 2006
    @ocean-city ocean-city mannequin assigned birkenfeld Oct 20, 2006
    @ocean-city ocean-city mannequin added the stdlib Python modules in the Lib dir label Oct 20, 2006
    @ocean-city ocean-city mannequin closed this as completed Oct 20, 2006
    @ocean-city ocean-city mannequin assigned birkenfeld Oct 20, 2006
    @ocean-city ocean-city mannequin added the stdlib Python modules in the Lib dir label Oct 20, 2006
    @birkenfeld
    Copy link
    Member

    Logged In: YES
    user_id=849994

    This is a duplicate of bpo-1586513 which has been fixed today.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant