- 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)
Named enums with 'Flags' in the name use `enum.IntFlag`, all other enums
use `enum.IntEnum`. We have to bring the enum members into the containing
scope to match the original behaviour. Further, since these enums are typing
information only, and not actually in wx proper, we prevent them from appearing
to leak the the user by marking as non-exported (prepend '_' to the name), then
make a TypeAlias to the enum or an int. This way type signatures still claim
to accept integers as appropriate.
I like this solution best, because we preserved the information about which
enum members are expected for method/function parameters, while not leaking
non-existant classes out of the type-stubs, and not complaining about using
integers.
There's still a few undefined but referenced enums (ex:
richtext.TextAttrDimensionFlags). These are most likely a union of some of
the other flags/enum types already defined, but the work to pull that information
from the C++ source is probably too much.
These will be changing to annotation statements, so FixWxPrefix needs to
be able to detect this still (proper thing to look for in this case is
`ast.AnnAssign`).
One unexpected type of '...' required adding a new transformation
that modifies both the name and the type to just '*args', so added
a preferred method `FixWxPrefix.parseNameAndType` which processes
both strings at once.
Also fixes cleanType to recursively call cleanType on sub-types
(was improperly calling cleanName).
With this, method and function signatures now have type annotations
which are mostly correct (100% correct in the "it compiles" sense).
Thankfully, the incorrect type-hints don't cause errors due to using
stringized annotations (by importing annotations from __future__).
Importantly, the overload signatures now have been fully sanitized.
Before this, there was one instance of a variable named `is`, and another
named `/Transfer/` - both invalid identifiers. I stopped looking after
those. Since theses signatures are valid Python code, this opens up the
opportunity to use `typing.overload` to fully expose those.
Edge-cases in type-hints will be addressed in later commits.
This allows for building `FixWxPrefix.cleanType` on top of it, for use
in processing type-hint strings in the future. It also exposes the method
to `FunctionDef.makePyArgString` in the future, which has easier access to
the types of arguments and returns. And possibly further in the future,
other `***Def` classes can make use of it (constant definitions, etc).
Parameter names should not be mangled, as this causes mismatches between
extractor and xml data:
```
SEVERE: Incompatibility between function/method signature and list of parameters in `wx.html.HtmlHelpWindow.__init__`:
The parameter `WindowID` appears in the method signature but could not be found in the parameter list.
==> Function/Method signature from `extractors`: __init__(parent, WindowID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.BORDER_NONE, helpStyle=HF_DEFAULT_STYLE, data=None)
==> Parameter list from wxWidgets XML items: ['parent', 'wxWindowID', 'pos', 'size', 'style', 'helpStyle', 'data']
```
```
==> Function/Method signature from `extractors`: SetAssertMode(AppAssertMode)
==> Parameter list from wxWidgets XML items: ['wxAppAssertMode']
```
This solves problems where an array that is the return value of some method call is indexed immediately and a reference to the array is not held, which could result in garbage values for the indexed item. Currently this is turned on for just GridCellCoordsArray, but others can be switched in the future if needed.
Many do not actually have it, but the docs only declare it in wx.Window so we will miss the ones that really do have one unless we let sip know about them.