Leverages the `writeSection` machinery, with a tweak to specify to add a
new section to the beginning of a file, after the header. This ensures
the required imports gets updated (and also only imported once per file)
if new imports are needed for type-hints. Hint: there's a few more to come.
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).
The line-wrapping causes issues once the python signatures become too long,
as textwrap isn't smart enough to split the lines on valid continuation points
for code. I had one instance of splitting a line in the middle of a string ->
SyntaxError on next run of etg due to the generated PYI file having an
unterminated string.
Specificially, disable splitting for lines that start (ignoring spaces) with
a specific string - in this case any line starting with the name of the
function or method this is a docstring for.
When I added this code in 5e190eb, it was intended to be used in all cases
except for constructors and destructors. Instead, it was used in all cases.
This broke the wxRegion constructor and possibly other things.
Fixes#1878.
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']
```
In the implementation of wx.CustomData.SetData, we need to check the
sipSelfWasArg variable to determine whether to call the parent class
implementation of SetData. To do this, we switched to using addCppMethod_sip
which allows us to access the sipSelfWasArg variable. The sip generator
stuff for CppMethod_sip needed some additions to match the behavior of
CppMethod.
statements with the safer "with open(filename) as fid:" blocks.
Also removed unnecessary "try: ... finally: pass" statements
and refactored code from img2py function into _write_image and _replace_non_alphanumeric_with_underscore
Fixes#1574