Commit Graph

4 Commits

Author SHA1 Message Date
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