mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-07 04:20:07 +01:00
Add typing to handwritten code for core.pyi
This commit is contained in:
28
etg/_core.py
28
etg/_core.py
@@ -291,7 +291,11 @@ def run():
|
||||
""")
|
||||
|
||||
|
||||
module.addPyFunction('CallAfter', '(callableObj, *args, **kw)', doc="""\
|
||||
module.addPyCode("""\
|
||||
_T = TypeVar('_T')
|
||||
_P = ParamSpec('_P')
|
||||
""")
|
||||
module.addPyFunction('CallAfter', '(callableObj: 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
|
||||
@@ -322,7 +326,7 @@ def run():
|
||||
wx.PostEvent(app, evt)""")
|
||||
|
||||
|
||||
module.addPyClass('CallLater', ['object'],
|
||||
module.addPyClass('CallLater', ['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
|
||||
@@ -342,7 +346,7 @@ def run():
|
||||
""",
|
||||
items = [
|
||||
PyCodeDef('__instances = {}'),
|
||||
PyFunctionDef('__init__', '(self, millis, callableObj, *args, **kwargs)',
|
||||
PyFunctionDef('__init__', '(self, millis, callableObj: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> None',
|
||||
doc="""\
|
||||
Constructs a new :class:`wx.CallLater` object.
|
||||
|
||||
@@ -366,7 +370,7 @@ def run():
|
||||
|
||||
PyFunctionDef('__del__', '(self)', 'self.Stop()'),
|
||||
|
||||
PyFunctionDef('Start', '(self, millis=None, *args, **kwargs)',
|
||||
PyFunctionDef('Start', '(self, millis: int | None=None, *args: _P.args, **kwargs: _P.kwargs) -> None',
|
||||
doc="""\
|
||||
(Re)start the timer
|
||||
|
||||
@@ -388,7 +392,7 @@ def run():
|
||||
self.running = True"""),
|
||||
PyCodeDef('Restart = Start'),
|
||||
|
||||
PyFunctionDef('Stop', '(self)',
|
||||
PyFunctionDef('Stop', '(self) -> None',
|
||||
doc="Stop and destroy the timer.",
|
||||
body="""\
|
||||
if self in CallLater.__instances:
|
||||
@@ -397,16 +401,16 @@ def run():
|
||||
self.timer.Stop()
|
||||
self.timer = None"""),
|
||||
|
||||
PyFunctionDef('GetInterval', '(self)', """\
|
||||
PyFunctionDef('GetInterval', '(self) -> int', """\
|
||||
if self.timer is not None:
|
||||
return self.timer.GetInterval()
|
||||
else:
|
||||
return 0"""),
|
||||
|
||||
PyFunctionDef('IsRunning', '(self)',
|
||||
PyFunctionDef('IsRunning', '(self) -> bool',
|
||||
"""return self.timer is not None and self.timer.IsRunning()"""),
|
||||
|
||||
PyFunctionDef('SetArgs', '(self, *args, **kwargs)',
|
||||
PyFunctionDef('SetArgs', '(self, *args: _P.args, **kwargs: _P.kwargs) -> None',
|
||||
doc="""\
|
||||
(Re)set the args passed to the callable object. This is
|
||||
useful in conjunction with :meth:`Start` if
|
||||
@@ -421,7 +425,7 @@ def run():
|
||||
self.args = args
|
||||
self.kwargs = kwargs"""),
|
||||
|
||||
PyFunctionDef('HasRun', '(self)', 'return self.hasRun',
|
||||
PyFunctionDef('HasRun', '(self) -> bool', 'return self.hasRun',
|
||||
doc="""\
|
||||
Returns whether or not the callable has run.
|
||||
|
||||
@@ -429,7 +433,7 @@ def run():
|
||||
|
||||
"""),
|
||||
|
||||
PyFunctionDef('GetResult', '(self)', 'return self.result',
|
||||
PyFunctionDef('GetResult', '(self) -> _T', 'return self.result',
|
||||
doc="""\
|
||||
Returns the value of the callable.
|
||||
|
||||
@@ -437,7 +441,7 @@ def run():
|
||||
:return: result from callable
|
||||
"""),
|
||||
|
||||
PyFunctionDef('Notify', '(self)',
|
||||
PyFunctionDef('Notify', '(self) -> None',
|
||||
doc="The timer has expired so call the callable.",
|
||||
body="""\
|
||||
if self.callable and getattr(self.callable, 'im_self', True):
|
||||
@@ -456,7 +460,7 @@ def run():
|
||||
module.addPyCode("FutureCall = deprecated(CallLater, 'Use CallLater instead.')")
|
||||
|
||||
module.addPyCode("""\
|
||||
def GetDefaultPyEncoding():
|
||||
def GetDefaultPyEncoding() -> str:
|
||||
return "utf-8"
|
||||
GetDefaultPyEncoding = deprecated(GetDefaultPyEncoding, msg="wxPython now always uses utf-8")
|
||||
""")
|
||||
|
||||
@@ -79,8 +79,9 @@ header_pyi = """\
|
||||
|
||||
typing_imports = """\
|
||||
from __future__ import annotations
|
||||
from collections.abc import Callable
|
||||
from enum import IntEnum, IntFlag, auto
|
||||
from typing import Any, overload, TypeAlias
|
||||
from typing import Any, overload, TypeAlias, TypeVar, ParamSpec, Generic
|
||||
|
||||
"""
|
||||
|
||||
@@ -371,7 +372,7 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
if pc.bases:
|
||||
stream.write('(%s):\n' % ', '.join(pc.bases))
|
||||
else:
|
||||
stream.write('(object):\n')
|
||||
stream.write(':\n')
|
||||
indent2 = indent + ' '*4
|
||||
if pc.briefDoc:
|
||||
stream.write('%s"""\n' % indent2)
|
||||
@@ -465,8 +466,6 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
bases = [self.fixWxPrefix(b, True) for b in bases]
|
||||
stream.write(', '.join(bases))
|
||||
stream.write(')')
|
||||
else:
|
||||
stream.write('(object)')
|
||||
stream.write(':\n')
|
||||
indent2 = indent + ' '*4
|
||||
|
||||
|
||||
Reference in New Issue
Block a user