-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inheritance and metaclass of base ctypes classes #12982
base: main
Are you sure you want to change the base?
Conversation
The hierarchy of _CData types doesn't much resemble runtime right now. What if it did? This is still a WIP, mostly because I suspect it might be disruptive but I'm not sure about that. If mypy-primer doesn't completely explode, I can do some fine tuning.
This comment has been minimized.
This comment has been minimized.
Hmmmmm |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
They probably can't be fixed, but I'm not certain enough right now.
This comment has been minimized.
This comment has been minimized.
Seems good! I'm encouraged by the fact that an actual error showed up in mypy-primer when I had something wrong. I found it interesting that the comment about how the classmethods on The note on |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi, +1 for the potential to resolve the false positives detected by type checkers around the metaclasses used in If this PR gets merged, I would appreciate guidance on how projects like |
This comment has been minimized.
This comment has been minimized.
Hi @junkmd , Unfortunately this particular MR doesn't have much impact on comtypes. I did a local comparison using > comtypes/_memberspec.py:191: error: "type[_CData]" has no attribute "from_param" [attr-defined]
> comtypes/test/find_memleak.py:26: error: Too many values to unpack (2 expected, 3 provided) [misc] The first is, strictly speaking, correct. The second is from a line like this: for n, _ in self._fields_: This is also a correct addition. As for the aliases, that's just There's no particular need for you to stop using |
This comment has been minimized.
This comment has been minimized.
Latest commit adds I also added Marking as draft while I check out those mypy-primer results. |
This comment has been minimized.
This comment has been minimized.
I updated to continue to accept I think the pwndbg diff makes sense: they're using the existence of a But a struct or union might have a member which is coincidentally named |
Hi @tungol, Thank you for your thorough investigation.
Nonetheless, such improvements to the type stubs bring the possibility of Given the shared history that the originator of both Once this is merged and incorporated into major type checkers, I intend to work on refining If you have any thoughts on |
Diff from mypy_primer, showing the effect of this PR on open source code: pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/aglib/heap/structs.py: note: In member "read_field" of class "CStruct2GDB":
+ pwndbg/aglib/heap/structs.py:175: error: Item "PyCSimpleType" of "type[_SimpleCData[Any]] | type[_Pointer[Any]] | type[CFuncPtr] | type[_ctypes.Union] | type[Structure] | type[Array[Any]]" has no attribute "_type_" [union-attr]
+ pwndbg/aglib/heap/structs.py:175: error: Access to generic instance variables via class is ambiguous [misc]
+ pwndbg/aglib/heap/structs.py:175: error: Item "PyCFuncPtrType" of "type[_SimpleCData[Any]] | type[_Pointer[Any]] | type[CFuncPtr] | type[_ctypes.Union] | type[Structure] | type[Array[Any]]" has no attribute "_type_" [union-attr]
+ pwndbg/aglib/heap/structs.py:175: error: Invalid index type "Any | type[Any] | CField[Any, Any, Any] | overloaded function" for "dict[type[object], Type]"; expected type "type[object]" [index]
+ pwndbg/aglib/heap/structs.py:177: error: Argument 1 to "array" of "Type" has incompatible type "Any | CField[Any, Any, Any] | overloaded function"; expected "int" [arg-type]
+ pwndbg/aglib/heap/structs.py: note: In member "fields" of class "CStruct2GDB":
+ pwndbg/aglib/heap/structs.py:206: error: Item "PyCSimpleType" of "type[_SimpleCData[Any]] | type[_Pointer[Any]] | type[CFuncPtr] | type[_ctypes.Union] | type[Structure] | type[Array[Any]]" has no attribute "_type_" [union-attr]
+ pwndbg/aglib/heap/structs.py:206: error: Access to generic instance variables via class is ambiguous [misc]
+ pwndbg/aglib/heap/structs.py:206: error: Item "PyCFuncPtrType" of "type[_SimpleCData[Any]] | type[_Pointer[Any]] | type[CFuncPtr] | type[_ctypes.Union] | type[Structure] | type[Array[Any]]" has no attribute "_type_" [union-attr]
+ pwndbg/aglib/heap/structs.py:206: error: Invalid index type "Any | type[Any] | CField[Any, Any, Any] | overloaded function" for "dict[type[object], Type]"; expected type "type[object]" [index]
+ pwndbg/aglib/heap/structs.py:207: error: Argument 1 to "array" of "Type" has incompatible type "Any | CField[Any, Any, Any] | overloaded function"; expected "int" [arg-type]
|
The hierarchy of _CData types doesn't much resemble runtime right now. What if it did?
This is still a WIP, mostly because I suspect it might be disruptive but I'm not sure about that. If mypy-primer doesn't completely explode, I can do some fine tuning.