Commit Graph

18 Commits

Author SHA1 Message Date
Christopher Schramm
fddc78293a Extend function pointer type returned by CDLL (#4444)
CDLL.__getattr__ and __getitem__ return function pointers that have a __name__ attribute set, so "CDLL(lib).fun.__name__" is valid code but currently not covered.
2020-08-13 17:35:36 +02:00
Eric Traut
04c74640f0 Removed imported symbols that are not accessed or re-exported (#4387)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-05 22:49:17 -07:00
Joshua Oreman
e6736cde8d ctypes: allow cast() 1st argument to be int and 2nd argument to be Type[py_object] (#4311) 2020-07-10 10:44:23 +02:00
Jelle Zijlstra
5d553c9584 apply black and isort (#4287)
* apply black and isort

* move some type ignores
2020-06-28 13:31:00 -07:00
Shantanu
c988348179 ctypes: fix arg name on windows (#4111)
Co-authored-by: hauntsaninja <>
2020-05-27 20:21:45 -07:00
Javier Honduvilla Coto
f7d240f06e ctypes.CDLL name can be None (#3945) 2020-04-26 15:51:38 +02:00
Sebastian Rittau
62bbdf856c Add several Python 3.8 annotations (#3347) 2019-10-12 19:36:56 +02:00
Rebecca Chen
ac35a18ad6 Make the value argument to ctypes.cbool.__init__ optional. (#3273) 2019-09-28 00:39:04 +02:00
dgelessus
45d4e88175 Let ctypes._CData.from_buffer[_copy] accept any buffer object (#2610)
Fixes the issue discussed here:
https://github.com/python/typeshed/pull/1906#discussion_r234798828
2018-11-20 07:43:21 -08:00
dgelessus
232b7c5147 Fix two small issues in ctypes.Array stubs (#2599)
* Allow only _CData subclasses as ctypes.Array elements

* Change type of ctypes.Array.raw and .value to Any (Closes #2111)

.raw and .value don't exist on all arrays. On c_char arrays, both exist
and have type bytes; on c_wchar arrays, only .value exists and has
type Text; on all other arrays neither one exists.

This is impossible to describe properly in a stub, so marking .value as
Any is the best that can be done.
2018-11-16 17:21:32 +01:00
Yusuke Miyazaki
581705d9ee Prefer to use ellipsis over pass (#2292) 2018-06-28 10:29:45 -07:00
Michael J. Sullivan
df55343e60 Fix some more ctypes issues (#2009)
* Make {C,WIN,PY}FUNCTYPE's restype argument optional (for void returns)
 * Make WinError return WindowsError
 * Don't have Array explicitly inherit from Sized
   (since inheriting from classes with different metaclasses causes problems, 
    and it is a protocol anyways)
 * Have Array.__iter__ properly return an Iterator instead of an Iterable
2018-03-30 18:03:52 -07:00
Michael J. Sullivan
9b99161ca9 Make argtypes in ctypes be a Sequence instead of a Tuple (#2005)
A lot of code uses lists here.
2018-03-29 14:55:56 -07:00
dgelessus
06aee52581 Fix some issues in ctypes (fixes #1983) (#1986)
* Support additional argument types for c_void_p parameters
* Don't allow passing bytes where a writable c_void_p is expected
* Fix type of ctypes._CDataMeta.__[r]mul__
* Rename ctypes._cparam to _CArgObject to match the real type name
* Fix value type of ctypes.HRESULT
* Add stub for ctypes.wintypes
* Fix trailing whitespace in ctypes.wintypes
* Add a workaround to ctypes.Array to fix incorrect typing in some cases
* Expand multiple assignments so mypy recognizes them as type aliases
* Rename ctypes._Pointer to pointer so it can be used externally
2018-03-29 12:41:42 -07:00
dgelessus
8009a34b90 Re-add stubs for ctypes (#1906)
* Convert type comments to variable annotations in ctypes.__init__

* Add missing List import in ctypes.__init__

* Add missing bound kwarg to _CT TypeVar in ctypes.__init__

* Fix ctypes._CData classmethod definitions

* Fix ctypes Structure/Union __getattr__ definitions

Both Structure's metaclass and Structure itself define a __getattr__.
The former returns field objects (each representing a field definition
in the Structure), while the latter can return anything (the value of
the field in a specific Structure instance).
Structure also defines a __setattr__, while Structure's metaclass
does not.

BigEndianStructure, LittleEndianStructure and Union support the same
operations as Structure does, but the semantics obviously differ.

Depending on the system endianness, exactly one of the EndianStructures
is an alias for Structure, and the other one is a special Structure
subclass. For simplicity, both EndianStructures are considered
subclasses of Structure here, even though this is technically not
always accurate.

* Fix swapped parameter types in ctypes._CData.in_dll

* Add limited support for ctypes._CData.__class__.__mul__

It's not possible to specify the correct return type for __mul__ and
__rmul__ here - see comments for explanation.

* Make ctypes._FuncPtr extend ctypes._CData

* Improve typing of ctypes.cast

* Mark class attributes with ClassVar in ctypes.__init__

* Mark ctypes._CData.from_buffer[_copy] offset arg as optional

* Remove trailing whitespace in ctypes.__init__

* Don't export ctypes.UnionT

* Add ctypes._DLL.__getitem__

* Make ctypes._DLL.__get(attr|item)__ return _FuncPtr instead of Any

* Change ctypes DLL inheritance hierarchy to match the real one better

* Add some missing attributes to ctypes.CDLL

* Rename ctypes._FuncPtr so it doesn't conflict with CDLL._FuncPtr

* Fix type of ctypes.CDLL._FuncPtr

* Merge _FuncProto into _FuncPointer

The function pointer types returned by CFUNCTYPE and friends are the
same as those encountered elsewhere, so there's no need to treat them
differently.

* Fix some leftover references to ctypes._DLL

* Simplify definition of ctypes._DLLT

* Add ctypes.LibraryLoader.__get(attr|item)__

* Use Text instead of str where appropriate in ctypes.__init__

* Make ctypes.c_char accept ints

* Make ctypes.c_[w]char_p accept None

* Remove unneeded Generic base from ctypes.py_object

* Make ctypes.cast accept _cparam

* Fix ctypes._PF being declared too late

* Remove incorrect ctypes.PyDLL.__init__ override
2018-03-16 20:17:24 -07:00
Guido van Rossum
73bdb705bf Delete ctypes. It is not yet ready for prime time, alas.
See https://github.com/python/typeshed/issues/475
2016-08-24 10:56:23 -07:00
David Euresti
ff86b1bd26 Remove empty wintypes module which just causes imports to break (#490) 2016-08-22 08:48:33 -07:00
Valérian Rousset
17f7d3db20 Add ctypes (#454)
* util done

* __init__, 16.16.2.2 done

* 16.16.2.3 done

* 16.16.2.4

* fix *FUNCTYPE, fix generic

* remove part of generic

* temporarly broad some type

* 16.16.2.5

* 16.16.2.6

* 16.16.2.7

* 16.16.2.8

* 16.16.2.9 and cleanup

* no documentation on wintypes

* move from _SimpleCData to _CData

* base on some example

* py2 done, cleanup

* make pytype happy
2016-08-15 11:39:23 -07:00