fixup: Non-generated core.pyi code

Since this is used to not only generate the type-stubs, but also the actual
wx/core.py, we need to ensure TypeVar and ParamSpec are imported there as
well. So, move the imports to the wx/core.py generator definition, and
remove the imports from the type-stub generator (these imports are only
used by CallAfter and CallLater).
This commit is contained in:
lojack5
2023-10-18 16:22:49 -06:00
parent 51675584d8
commit 17cbd02543
2 changed files with 13 additions and 8 deletions

View File

@@ -291,11 +291,16 @@ def run():
""") """)
module.addPyCode('import typing', order=10)
module.addPyCode("""\ module.addPyCode("""\
_T = TypeVar('_T') _T = typing.TypeVar('_T')
_P = ParamSpec('_P') try:
_P = typing.ParamSpec('_P')
except AttributeError:
import typing_extensions
_P = typing_extensions.ParamSpec('_P')
""") """)
module.addPyFunction('CallAfter', '(callableObj: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> None', doc="""\ module.addPyFunction('CallAfter', '(callableObj: typing.Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> None', doc="""\
Call the specified function after the current and pending event Call the specified function after the current and pending event
handlers have been completed. This is also good for making GUI handlers have been completed. This is also good for making GUI
method calls from non-GUI threads. Any extra positional or method calls from non-GUI threads. Any extra positional or
@@ -326,7 +331,7 @@ def run():
wx.PostEvent(app, evt)""") wx.PostEvent(app, evt)""")
module.addPyClass('CallLater', ['Generic[_P, _T]'], module.addPyClass('CallLater', ['typing.Generic[_P, _T]'],
doc="""\ doc="""\
A convenience class for :class:`wx.Timer`, that calls the given callable A convenience class for :class:`wx.Timer`, that calls the given callable
object once after the given amount of milliseconds, passing any object once after the given amount of milliseconds, passing any
@@ -346,7 +351,7 @@ def run():
""", """,
items = [ items = [
PyCodeDef('__instances = {}'), PyCodeDef('__instances = {}'),
PyFunctionDef('__init__', '(self, millis, callableObj: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> None', PyFunctionDef('__init__', '(self, millis, callableObj: typing.Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> None',
doc="""\ doc="""\
Constructs a new :class:`wx.CallLater` object. Constructs a new :class:`wx.CallLater` object.
@@ -370,7 +375,7 @@ def run():
PyFunctionDef('__del__', '(self)', 'self.Stop()'), PyFunctionDef('__del__', '(self)', 'self.Stop()'),
PyFunctionDef('Start', '(self, millis: int | None=None, *args: _P.args, **kwargs: _P.kwargs) -> None', PyFunctionDef('Start', '(self, millis: typing.Optional[int]=None, *args: _P.args, **kwargs: _P.kwargs) -> None',
doc="""\ doc="""\
(Re)start the timer (Re)start the timer

View File

@@ -81,7 +81,7 @@ header_pyi = """\
typing_imports = """\ typing_imports = """\
from __future__ import annotations from __future__ import annotations
from enum import IntEnum, IntFlag, auto from enum import IntEnum, IntFlag, auto
from typing import (Any, overload, TypeAlias, TypeVar, ParamSpec, Generic, from typing import (Any, overload, TypeAlias, Generic,
Union, Optional, List, Tuple, Callable Union, Optional, List, Tuple, Callable
) )
try: try: