| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This allows adding type annotations to structures and unions that resolve to the underlying types when accessed inside structures
… feedback from reviewers/maintainers
|
I've checked out the problem from enthought/comtypes and these are my findings: ITypeComp.Bind is specified to return Optional[Tuple[str, _UnionT[FUNCDESC, VARDESC, ITypeComp]]]. typeinfo.py:375. The offending line returns "type", bindptr.lptcomp where bindptr is an instance of BINDPTR/tagBINDPTR. ITypeComp inherits from IUnknown which inherits from _IUnknown_Base which inherits from c_void_p. ITypeComp is effectively a c_void_p. When the interpreter returns bindptr.lptcomp, the type is POINTER(ITypeComp), and the returned type is ITypeComp, as defined by the _field_. edit: clarified last part, was tired when I wrote it, still am |
Sorry, something went wrong.
|
Now after the fact I saw #10595 . I think this proposal does what was intended in the PR and discussed in #10567, but better, as it is performed automatically by all primitives that are part of a structure/union and doesn't need manual type definitions as is done in that PR? |
Sorry, something went wrong.
|
See the test_cases/stdlib directory for examples on how to write tests. Basically, use typing_extensions.assert_type() to make sure a type is as expected, and # type: ignore for expected failures. |
Sorry, something went wrong.
|
It turns out that subclassing the basic types causes them to not be unboxed, and this behaviour has always been part of ctypes. I added # pyright: reportUninitializedInstanceVariable=false to the top of the new regression testing file since pyright complained about uninitialized members. |
Sorry, something went wrong.
|
Diff from mypy_primer, showing the effect of this PR on open source code: comtypes (https://github.com/enthought/comtypes)
+ comtypes/typeinfo.py:452: error: Incompatible return value type (got "tuple[str, int | None]", expected "tuple[str, tagFUNCDESC | tagVARDESC | ITypeComp] | None") [return-value]
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This allows adding type annotations to structures and unions that resolve to the underlying types when accessed inside structures.
I don't know how to make proper tests for this, so I've made some examples where I've marked the lines that are expected to fail typechecking.