I think it makes good sense for the type-checking reason: _CData *does* declare a fairly useful base interface that other classes also expose, so saying that a function takes a _CData argument can make good sense. (As a bunch of the methods in the io library do, for example) typeshed hacks it for the case where one is using .pyi files for type annotations, but there's no great way to just do that in ordinary Python code.
(Really, I think it would be lovely to stick proper type signatures directly into the base libraries like io, but that's a whole separate conversation. I like strong typing, does it show?) Yonatan On Wed, Jan 5, 2022 at 5:15 PM Gregory P. Smith <g...@krypto.org> wrote: > > On Wed, Jan 5, 2022 at 3:17 PM Yonatan Zunger <zun...@gmail.com> wrote: > >> Hey everyone. >> >> Quick sanity check: The ctypes docs >> <https://docs.python.org/3.10/library/ctypes.html#ctypes._CData> refer >> to _CData as a non-public class which is in the module, but _ctypes.c doesn't >> actually export it >> <https://github.com/python/cpython/blob/main/Modules/_ctypes/_ctypes.c#L5680>. >> (I discovered this because it turns out that typeshed *is* referencing >> _CData, e.g. in its type annotations for RawIOBase >> <https://github.com/python/typeshed/blob/master/stdlib/_typeshed/__init__.pyi#L190> >> ) >> >> Is this intended behavior in CPython (in which case the docs are a bit >> off and typeshed has a bug), or is it unexpected to people on this list (in >> which case it's an issue in _ctypes.c)? >> > > typeshed is presumably referring to itself. It defines an interface for > ctypes._CData in > https://github.com/python/typeshed/blob/master/stdlib/ctypes/__init__.pyi#L82 > > The CPython ctypes docs *seem* reasonable to me. There is such a class. > It is not public, so you cannot access ctypes._CData in any direct manner. > That it gets called a class may be somewhat historical - its purpose is to > provide a common interface. What code would ever actually care that it used > class mechanisms as an internal implementation detail to do that? > > -gps > > >> >> Yonatan >> _______________________________________________ >> Python-Dev mailing list -- python-dev@python.org >> To unsubscribe send an email to python-dev-le...@python.org >> https://mail.python.org/mailman3/lists/python-dev.python.org/ >> Message archived at >> https://mail.python.org/archives/list/python-dev@python.org/message/7L6DNNI3MJ4UIM3C7A7KAIWHX562MRZL/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> >
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/RFEECGPCUIYAWYIC7C4EFDR4JAH7I4MP/ Code of Conduct: http://python.org/psf/codeofconduct/