Skip to content

Commit

Permalink
fixup: Non-generated core.pyi code
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
lojack5 committed Oct 19, 2023
1 parent 5167558 commit 17cbd02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions etg/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,16 @@ def run():
""")


module.addPyCode('import typing', order=10)
module.addPyCode("""\
_T = TypeVar('_T')
_P = ParamSpec('_P')
""")
module.addPyFunction('CallAfter', '(callableObj: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> None', doc="""\
_T = typing.TypeVar('_T')
try:
_P = typing.ParamSpec('_P')
except AttributeError:
import typing_extensions
_P = typing_extensions.ParamSpec('_P')
""")
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
handlers have been completed. This is also good for making GUI
method calls from non-GUI threads. Any extra positional or
Expand Down Expand Up @@ -326,7 +331,7 @@ def run():
wx.PostEvent(app, evt)""")


module.addPyClass('CallLater', ['Generic[_P, _T]'],
module.addPyClass('CallLater', ['typing.Generic[_P, _T]'],
doc="""\
A convenience class for :class:`wx.Timer`, that calls the given callable
object once after the given amount of milliseconds, passing any
Expand All @@ -346,7 +351,7 @@ def run():
""",
items = [
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="""\
Constructs a new :class:`wx.CallLater` object.
Expand All @@ -370,7 +375,7 @@ def run():

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="""\
(Re)start the timer
Expand Down
2 changes: 1 addition & 1 deletion etgtools/pi_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
typing_imports = """\
from __future__ import annotations
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
)
try:
Expand Down

0 comments on commit 17cbd02

Please sign in to comment.