Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typing for context managers and methods returning Self in non-generated python code #2674

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions etgtools/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
textfile_open
from sphinxtools.utilities import findDescendants

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

#---------------------------------------------------------------------------
# These classes simply hold various bits of information about the classes,
# methods, functions and other items in the C/C++ API being wrapped.
Expand Down Expand Up @@ -98,7 +103,7 @@ def clearDeprecated(self):
return


def ignore(self, val=True):
def ignore(self, val=True) -> Self:
self.ignored = val
return self

Expand Down Expand Up @@ -426,7 +431,7 @@ def renameOverload(self, matchText, newName, **kw):
return item


def ignore(self, val=True):
def ignore(self, val=True) -> Self:
# In addition to ignoring this item, reorder any overloads to ensure
# the primary overload is not ignored, if possible.
super(FunctionDef, self).ignore(val)
Expand Down
2 changes: 1 addition & 1 deletion requirements/devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Jinja2==2.10
markupsafe==1.1.1
doc2dash==2.3.0
beautifulsoup4
typing-extensions; python_version < '3.10'
typing-extensions; python_version < '3.11'
2 changes: 1 addition & 1 deletion requirements/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ numpy < 1.17 ; python_version <= '2.7'
numpy ; python_version >= '3.0' and python_version < '3.12'
# pillow < 3.0
six
typing-extensions; python_version < '3.10'
typing-extensions; python_version < '3.11'
6 changes: 5 additions & 1 deletion sphinxtools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
from .constants import RE_KEEP_SPACES, EXTERN_INHERITANCE
from .constants import DOXYROOT, SPHINXROOT, WIDGETS_IMAGES_ROOT

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

# ----------------------------------------------------------------------- #

Expand Down Expand Up @@ -622,7 +626,7 @@ class PickleFile(object):
def __init__(self, fileName):
self.fileName = fileName

def __enter__(self):
def __enter__(self) -> Self:
self.read()
return self

Expand Down
31 changes: 18 additions & 13 deletions wx/lib/agw/aui/aui_switcherdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ def OnSwitchPane(self, event):

"""

import sys
import wx

from . import auibook
from .aui_utilities import FindFocusDescendant
from .aui_constants import SWITCHER_TEXT_MARGIN_X, SWITCHER_TEXT_MARGIN_Y

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

# Define a translation function
_ = wx.GetTranslation
Expand Down Expand Up @@ -213,7 +218,7 @@ def Copy(self, item):
self._window = item._window


def SetTitle(self, title):
def SetTitle(self, title) -> Self:

self._title = title
return self
Expand All @@ -224,7 +229,7 @@ def GetTitle(self):
return self._title


def SetName(self, name):
def SetName(self, name) -> Self:

self._name = name
return self
Expand All @@ -235,7 +240,7 @@ def GetName(self):
return self._name


def SetDescription(self, descr):
def SetDescription(self, descr) -> Self:

self._description = descr
return self
Expand All @@ -246,7 +251,7 @@ def GetDescription(self):
return self._description


def SetId(self, id):
def SetId(self, id) -> Self:

self._id = id
return self
Expand All @@ -257,7 +262,7 @@ def GetId(self):
return self._id


def SetIsGroup(self, isGroup):
def SetIsGroup(self, isGroup) -> Self:

self._isGroup = isGroup
return self
Expand All @@ -268,7 +273,7 @@ def GetIsGroup(self):
return self._isGroup


def BreakColumn(self, breakCol=True):
def BreakColumn(self, breakCol=True) -> Self:

self._breakColumn = breakCol
return self
Expand All @@ -279,7 +284,7 @@ def GetBreakColumn(self):
return self._breakColumn


def SetRect(self, rect):
def SetRect(self, rect) -> Self:

self._rect = rect
return self
Expand All @@ -290,7 +295,7 @@ def GetRect(self):
return self._rect


def SetTextColour(self, colour):
def SetTextColour(self, colour) -> Self:

self._textColour = colour
return self
Expand All @@ -301,7 +306,7 @@ def GetTextColour(self):
return self._textColour


def SetFont(self, font):
def SetFont(self, font) -> Self:

self._font = font
return self
Expand All @@ -312,7 +317,7 @@ def GetFont(self):
return self._font


def SetBitmap(self, bitmap):
def SetBitmap(self, bitmap) -> Self:

self._bitmap = bitmap
return self
Expand All @@ -323,7 +328,7 @@ def GetBitmap(self):
return self._bitmap


def SetRowPos(self, pos):
def SetRowPos(self, pos) -> Self:

self._rowPos = pos
return self
Expand All @@ -334,7 +339,7 @@ def GetRowPos(self):
return self._rowPos


def SetColPos(self, pos):
def SetColPos(self, pos) -> Self:

self._colPos = pos
return self
Expand All @@ -345,7 +350,7 @@ def GetColPos(self):
return self._colPos


def SetWindow(self, win):
def SetWindow(self, win) -> Self:

self._window = win
return self
Expand Down
Loading