FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Adding descriptor methods to _SimpleCData by DrInfiniteExplorer · Pull Request #11272 · python/typeshed · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .pyi  (1) .txt  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions stdlib/_ctypes.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class _SimpleCData(_CData, Generic[_T]):
# The TypeVar can be unsolved here,
# but we can't use overloads without creating many, many mypy false-positive errors
def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse]
@overload
def __get__(self, __instance: None, __owner: type[Any] | None) -> Self: ...
@overload
def __get__(self, __instance: Any, __owner: type[_StructUnionBase]) -> _T: ...
@overload
def __get__(self, __instance: Any, __owner: type[Any] | None) -> Self: ...
def __set__(self, __instance: Any, __value: _T) -> None: ...

class _CanCastTo(_CData): ...
class _PointerLike(_CanCastTo): ...
Expand Down
45 changes: 45 additions & 0 deletions test_cases/stdlib/check_ctypes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# pyright: reportUninitializedInstanceVariable=false

from __future__ import annotations

import ctypes
from typing import Any
from typing_extensions import assert_type


class Annotated(ctypes.Structure):
_fields_ = [("i", ctypes.c_int), ("f", ctypes.c_float)]
i: ctypes.c_int
f: ctypes.c_float


class NoAnnotation(ctypes.Structure):
_fields_ = [("i", ctypes.c_int), ("f", ctypes.c_float)]


class NonCType:
i: ctypes.c_int
f: ctypes.c_float


assert_type(ctypes.c_int().value, int)
ctypes.c_int() + 2 # type: ignore

assert_type(ctypes.c_float().value, float)
ctypes.c_float() + 2 # type: ignore

# All passes; all access are Any
assert_type(NoAnnotation().x + 2, Any)
assert_type(NoAnnotation().vec.x + 2, Any)

Annotated.x.value + 2 # type: ignore
Annotated.x + 2 # type: ignore
assert_type(Annotated().i, int)
Annotated().i.value + 2 # type: ignore
assert_type(Annotated().f, float)
Annotated().f.value + 3.14 # type: ignore

assert_type(NonCType.i.value, int)
NonCType.i + 2 # type: ignore
NonCType().i + 2 # type: ignore
assert_type(NonCType().i.value, int)
4 changes: 4 additions & 0 deletions tests/stubtest_allowlists/py3_common.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ _collections_abc.KeysView.__reversed__
_collections_abc.ValuesView.__reversed__
_csv.Dialect.__init__ # C __init__ signature is inaccurate
_ctypes.CFuncPtr # stubtest erroneously thinks it can't be subclassed
_ctypes._SimpleCData.__get__ # Does not exist on runtime object
_ctypes._SimpleCData.__set__ # Does not exist on runtime object
_threading_local.local.__new__
ast.Bytes.__new__
ast.Ellipsis.__new__
Expand All @@ -37,6 +39,8 @@ ctypes.memmove # CFunctionType
ctypes.memset # CFunctionType
ctypes.string_at # docstring argument name is wrong
ctypes.wstring_at # docstring argument name is wrong
ctypes._SimpleCData.__get__ # Does not exist on runtime object
ctypes._SimpleCData.__set__ # Does not exist on runtime object
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
functools.cached_property.__set__ # Stub is a white lie; see comments in the stub
Expand Down

Back | FazBrowse Home | New Git URL