-
Notifications
You must be signed in to change notification settings - Fork 522
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
Type stub improvements #2668
base: master
Are you sure you want to change the base?
Type stub improvements #2668
Conversation
- Remove typehints from argsString before checking signature - lie and detect `_from`, `_is`, and `_def` as `from`, `is`, and `def for signature validating purposes - Fix: don't remove const from identifiers containing const (eg: constraint)
`parent` argument.
This one has probably been in the generated type-stub for ages. One of the base classes in the generated stub was generated as `RichTextLine*`.
Thanks a lot @lojack5 this looks good. As far as the |
Maybe. Does the conversion added happen anywhere a If so, I could probably do something like: DateTimeT: TypeAlias = Union[wx.DateTime, datetime.datetime, datetime.date] Then Follow on, should something similar be done for PointT: TypeAlias = Union[wx.Point, tuple[int, int]]
SizeT: TypeAlias = Union[wx.Size, tuple[int, int]]
ColourT: TypeAlias = Union[wx.Colour, tuple[int, int, int], tuple[int, int, int, int], str] |
Note that typealias should come from typing_extensions for Python 3.9 (minimum supported version here), as it was only introduced in 3.10. It's possible to use type aliases on Python 3.9, just without using the semicolon and TypeAlias, and directly using equal the thing it is aliasing. |
And yes, |
What started my interest in improving wxPython typing a couple weeks ago was specifically because of the typing for Point and Size. So I'm interested in any improvement for that. I remember trying hard to find where the conversion from class to tuple happens, but it wasn't clear yet. Line 487 in c3092be
Lines 243 to 252 in c3092be
|
They're in the sip generating files as far as I can tell:
So I guess adding things for all of these is on the table. I'll see if there's a more general way to do this, instead of hard-coding all of them. |
Yes, it does. Passing datetime.date to wx.adv.CalendarCtrl works. |
Gotcha, I'll start working on a solution that should encompass all types with a |
Pulls out the data into a separate class, `tweaker_tools.Signature`. This simplifies stringizing the args string, and allows for some checks to be written in a much less complex way. The motivator for this was adding unions to type-hints (for the upcoming automatically converted python->wx types). This made parsing the already stringized args string very complex to be able to handle the potential for commas in `Union`.
Ok, I'm ready for review of this. In particular if @timrid can find anymore edge cases to fixup, now would be a great time to find them :). Otherwise, I'm pretty sure this handles most cases correctly now. There are still some edge cases I found that aren't exactly easy to fix, but from what I can tell they are on rarely used interfaces. Still would like a yes/no on the |
Oh, actually there were two points I was unsure about: |
This handles any type with a defined `.convertFromPyObject` set in its sip generator.
I downloaded the
|
Thanks, I know what's happening with the functions (vs methods) - I can fix that quickly. The others, not so sure why they're getting renamed, so I'll have to look into that. |
Also - I take back everything else working as intended - types that are automatically converted are only partially covered, because each generating file is fired up in a separate Python instance, meaning for example the |
Sorry for the delay on this was having some computer issues (frequent BSOD) that I had to fix. Should get back into finishing this up. |
Follow up to #2468 , addressing issues brought up in #2665 and #2666 . (I finally figured out my problem with running
etg
without--nodoc
, so now I can finally test the doc building warnings).Issues addressed:
constraint
->raint
) no longer happens._from
,_is
, and_def
(Python reserved keywords)__bool__
returningint
: Special case handling done in the writing of the method. I'm not sure why we can't just change the definition in the sip file, but sip complains that it must return anint
.None
allowed forparent
argument onTopLevelWindow
subclasses.#define
directives which are boolean asbool
.variable = property(<getter>, <setter>)
syntax not being seen as the applicable type. This is atypeshed
issue (and not one easily solve). Addressed by using decorator syntax when a getter and type-hints are present on the getter and/or setter (setter-only properties still have to use thevariable = property(fset=<setter>)
syntax.SetAssertMode
. The clean-name code was inappropriately removing applying the "remove wx prefix" code to argument names:wx.DateTime
acceptsdatetime.datetime
anddatetime.date
objects in its constructor. Similarly,wx.Point
,wx.Size
, and other similar automated conversions are handled.Things I'd like extra eyes on:
None
forparent
argument: Are any of the changed type-stubs incorrect in allowingNone
there? Are there any missing?wx.DateTime
typing.Closes #2665
Closes #2666