Skip to content

Commit 744801f

Browse files
authored
Merge pull request #2674 from echoix/typing-self-python-only
Add typing for context managers and methods returning `Self` in non-generated python code
2 parents 15c6e01 + 5ee3aa1 commit 744801f

File tree

11 files changed

+171
-124
lines changed

11 files changed

+171
-124
lines changed

etgtools/extractors.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
textfile_open
2424
from sphinxtools.utilities import findDescendants
2525

26+
if sys.version_info >= (3, 11):
27+
from typing import Self
28+
else:
29+
from typing_extensions import Self
30+
2631
#---------------------------------------------------------------------------
2732
# These classes simply hold various bits of information about the classes,
2833
# methods, functions and other items in the C/C++ API being wrapped.
@@ -98,7 +103,7 @@ def clearDeprecated(self):
98103
return
99104

100105

101-
def ignore(self, val=True):
106+
def ignore(self, val=True) -> Self:
102107
self.ignored = val
103108
return self
104109

@@ -426,7 +431,7 @@ def renameOverload(self, matchText, newName, **kw):
426431
return item
427432

428433

429-
def ignore(self, val=True):
434+
def ignore(self, val=True) -> Self:
430435
# In addition to ignoring this item, reorder any overloads to ensure
431436
# the primary overload is not ignored, if possible.
432437
super(FunctionDef, self).ignore(val)

requirements/devel.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Jinja2==2.10
2727
markupsafe==1.1.1
2828
doc2dash==2.3.0
2929
beautifulsoup4
30-
typing-extensions; python_version < '3.10'
30+
typing-extensions; python_version < '3.11'

requirements/install.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ numpy < 1.17 ; python_version <= '2.7'
33
numpy ; python_version >= '3.0' and python_version < '3.12'
44
# pillow < 3.0
55
six
6-
typing-extensions; python_version < '3.10'
6+
typing-extensions; python_version < '3.11'

sphinxtools/utilities.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
from .constants import RE_KEEP_SPACES, EXTERN_INHERITANCE
3333
from .constants import DOXYROOT, SPHINXROOT, WIDGETS_IMAGES_ROOT
3434

35+
if sys.version_info >= (3, 11):
36+
from typing import Self
37+
else:
38+
from typing_extensions import Self
3539

3640
# ----------------------------------------------------------------------- #
3741

@@ -622,7 +626,7 @@ class PickleFile(object):
622626
def __init__(self, fileName):
623627
self.fileName = fileName
624628

625-
def __enter__(self):
629+
def __enter__(self) -> Self:
626630
self.read()
627631
return self
628632

wx/lib/agw/aui/aui_switcherdialog.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,17 @@ def OnSwitchPane(self, event):
158158
159159
"""
160160

161+
import sys
161162
import wx
162163

163164
from . import auibook
164165
from .aui_utilities import FindFocusDescendant
165166
from .aui_constants import SWITCHER_TEXT_MARGIN_X, SWITCHER_TEXT_MARGIN_Y
166167

168+
if sys.version_info >= (3, 11):
169+
from typing import Self
170+
else:
171+
from typing_extensions import Self
167172

168173
# Define a translation function
169174
_ = wx.GetTranslation
@@ -213,7 +218,7 @@ def Copy(self, item):
213218
self._window = item._window
214219

215220

216-
def SetTitle(self, title):
221+
def SetTitle(self, title) -> Self:
217222

218223
self._title = title
219224
return self
@@ -224,7 +229,7 @@ def GetTitle(self):
224229
return self._title
225230

226231

227-
def SetName(self, name):
232+
def SetName(self, name) -> Self:
228233

229234
self._name = name
230235
return self
@@ -235,7 +240,7 @@ def GetName(self):
235240
return self._name
236241

237242

238-
def SetDescription(self, descr):
243+
def SetDescription(self, descr) -> Self:
239244

240245
self._description = descr
241246
return self
@@ -246,7 +251,7 @@ def GetDescription(self):
246251
return self._description
247252

248253

249-
def SetId(self, id):
254+
def SetId(self, id) -> Self:
250255

251256
self._id = id
252257
return self
@@ -257,7 +262,7 @@ def GetId(self):
257262
return self._id
258263

259264

260-
def SetIsGroup(self, isGroup):
265+
def SetIsGroup(self, isGroup) -> Self:
261266

262267
self._isGroup = isGroup
263268
return self
@@ -268,7 +273,7 @@ def GetIsGroup(self):
268273
return self._isGroup
269274

270275

271-
def BreakColumn(self, breakCol=True):
276+
def BreakColumn(self, breakCol=True) -> Self:
272277

273278
self._breakColumn = breakCol
274279
return self
@@ -279,7 +284,7 @@ def GetBreakColumn(self):
279284
return self._breakColumn
280285

281286

282-
def SetRect(self, rect):
287+
def SetRect(self, rect) -> Self:
283288

284289
self._rect = rect
285290
return self
@@ -290,7 +295,7 @@ def GetRect(self):
290295
return self._rect
291296

292297

293-
def SetTextColour(self, colour):
298+
def SetTextColour(self, colour) -> Self:
294299

295300
self._textColour = colour
296301
return self
@@ -301,7 +306,7 @@ def GetTextColour(self):
301306
return self._textColour
302307

303308

304-
def SetFont(self, font):
309+
def SetFont(self, font) -> Self:
305310

306311
self._font = font
307312
return self
@@ -312,7 +317,7 @@ def GetFont(self):
312317
return self._font
313318

314319

315-
def SetBitmap(self, bitmap):
320+
def SetBitmap(self, bitmap) -> Self:
316321

317322
self._bitmap = bitmap
318323
return self
@@ -323,7 +328,7 @@ def GetBitmap(self):
323328
return self._bitmap
324329

325330

326-
def SetRowPos(self, pos):
331+
def SetRowPos(self, pos) -> Self:
327332

328333
self._rowPos = pos
329334
return self
@@ -334,7 +339,7 @@ def GetRowPos(self):
334339
return self._rowPos
335340

336341

337-
def SetColPos(self, pos):
342+
def SetColPos(self, pos) -> Self:
338343

339344
self._colPos = pos
340345
return self
@@ -345,7 +350,7 @@ def GetColPos(self):
345350
return self._colPos
346351

347352

348-
def SetWindow(self, win):
353+
def SetWindow(self, win) -> Self:
349354

350355
self._window = win
351356
return self

0 commit comments

Comments
 (0)