diff --git a/etg/_core.py b/etg/_core.py index 67acbdc78a..3addfb5f75 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -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 @@ -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 @@ -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. @@ -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 diff --git a/etgtools/pi_generator.py b/etgtools/pi_generator.py index 85ca6929f7..8c1bd157e0 100644 --- a/etgtools/pi_generator.py +++ b/etgtools/pi_generator.py @@ -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: