Author eryksun
Recipients eryksun, lfriedri
Date 2018-09-27.12:26:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538051186.59.0.545547206417.issue34816@psf.upfronthosting.co.za>
In-reply-to
Content
ctypes.windll is an instance of ctypes.LibraryLoader, which has a __getattr__ method that calls ctypes.WinDLL(name) and caches the result as an instance attribute. I suppose with chained exceptions it's reasonable to handle OSError in __getattr__ by raising AttributeError. For example:

    class A:
        def __init__(self, name):
            raise OSError

    class B:
        def __getattr__(self, name):
            try:
                A(name)
            except OSError:
                raise AttributeError

Demo:

    >>> b = B()
    >>> b.test
    Traceback (most recent call last):
      File "<stdin>", line 4, in __getattr__
      File "<stdin>", line 3, in __init__
    OSError

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 6, in __getattr__
    AttributeError

    >>> hasattr(b, 'test')
    False

FYI, I recommend avoiding the cdll and windll LibraryLoader instances. I wish they were deprecated because globally caching CDLL and WinDLL instances leads to conflicts between projects that use the same shared libraries.
History
Date User Action Args
2018-09-27 12:26:26eryksunsetrecipients: + eryksun, lfriedri
2018-09-27 12:26:26eryksunsetmessageid: <1538051186.59.0.545547206417.issue34816@psf.upfronthosting.co.za>
2018-09-27 12:26:26eryksunlinkissue34816 messages
2018-09-27 12:26:26eryksuncreate