This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author superbobry
Recipients superbobry
Date 2018-09-05.21:35:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1536183341.44.0.56676864532.issue34592@psf.upfronthosting.co.za>
In-reply-to
Content
LoadLibrary in Python 2.7 through 3.7 accepts None as an argument. I wonder if this has been allowed for a reason? If not, it should probably be changed to raise a TypeError instead.

>>> ctypes.cdll.LoadLibrary(None)
<CDLL 'None', handle fffffffffffffffe at 10eedbe90>

Interestingly, on Python 2.7 LoadLibrary explicitly mentions None as allowed in the error message:

>>> ctypes.cdll.LoadLibrary(42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/ctypes/__init__.py", line 444, in LoadLibrary
    return self._dlltype(name)
  File "[...]/ctypes/__init__.py", line 366, in __init__
    self._handle = _dlopen(self._name, mode)
TypeError: dlopen() argument 1 must be string or None, not int

A side-effect of None being allowed is that chaining find_library and LoadLibrary is error-prone:

>>> ctypes.cdll.LoadLibrary(find_library("foobar"))
<CDLL 'None', handle fffffffffffffffe at 10ef35fd0>
History
Date User Action Args
2018-09-05 21:35:41superbobrysetrecipients: + superbobry
2018-09-05 21:35:41superbobrysetmessageid: <1536183341.44.0.56676864532.issue34592@psf.upfronthosting.co.za>
2018-09-05 21:35:41superbobrylinkissue34592 messages
2018-09-05 21:35:41superbobrycreate