From ae05dfeeb412afbf08e8e80e37fc7f0330de19a1 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 23 Oct 2024 16:29:11 -0400 Subject: [PATCH 1/2] Fixed Pythonwin's editor failing due to invalid regex import --- .github/workflows/main.yml | 4 ++-- CHANGES.txt | 1 + Pythonwin/pywin/framework/editor/editor.py | 12 ++++++------ Pythonwin/pywin/framework/mdi_pychecker.py | 3 +-- Pythonwin/pywin/framework/sgrepmdi.py | 2 -- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index db40b4254..88e5ae6ca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -143,7 +143,7 @@ jobs: cache: pip cache-dependency-path: .github/workflows/main.yml check-latest: true - - run: pip install types-regex types-setuptools PyOpenGL mypy==1.11 + - run: pip install types-setuptools PyOpenGL mypy==1.11 - run: mypy . --python-version=${{ matrix.python-version }} pyright: @@ -162,7 +162,7 @@ jobs: cache-dependency-path: .github/workflows/main.yml check-latest: true # pyright vendors typeshed, but let's make sure we have the most up to date stubs - - run: pip install types-regex types-setuptools PyOpenGL + - run: pip install types-setuptools PyOpenGL - uses: jakebailey/pyright-action@v2 with: python-version: ${{ matrix.python-version }} diff --git a/CHANGES.txt b/CHANGES.txt index 82cf59213..61ee2e101 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,7 @@ https://mhammond.github.io/pywin32_installers.html. Coming in build 309, as yet unreleased -------------------------------------- +* Fixed Pythonwin's editor failing due to invalid regex import (#, @Avasam) * Dropped support for Python 3.7 (#2207, @Avasam) * Implement the creation of SAFEARRAY(VT_RECORD) from a sequence of COM Records (#2317, @geppi) * Implement record pointers as [in, out] method parameters of a Dispatch Interface (#2304, #2310, @geppi) diff --git a/Pythonwin/pywin/framework/editor/editor.py b/Pythonwin/pywin/framework/editor/editor.py index facb5b23f..a83f20312 100644 --- a/Pythonwin/pywin/framework/editor/editor.py +++ b/Pythonwin/pywin/framework/editor/editor.py @@ -9,7 +9,7 @@ # We now support reloading of externally modified documented # (eg, presumably by some other process, such as source control or # another editor. -# We also suport auto-loading of externally modified files. +# We also support auto-loading of externally modified files. # - if the current document has not been modified in this # editor, but has been modified on disk, then the file # can be automatically reloaded. @@ -19,7 +19,6 @@ import re -import regex import win32api import win32con import win32ui @@ -36,8 +35,8 @@ # from pywin.mfc.docview import EditView as ParentEditorView # from pywin.mfc.docview import Document as ParentEditorDocument -patImport = regex.symcomp(r"import \(.*\)") -patIndent = regex.compile(r"^\([ \t]*[~ \t]\)") +patImport = re.compile(r"import (?P.*)") +patIndent = re.compile(r"^([ \t]*[~ \t])") ID_LOCATE_FILE = 0xE200 ID_GOTO_LINE = 0xE2001 @@ -364,9 +363,10 @@ def OnRClick(self, params): # look for a module name line = self._obj_.GetLine().strip() flags = win32con.MF_STRING | win32con.MF_ENABLED - if patImport.match(line) == len(line): + matchResult = patImport.match(line) + if matchResult and matchResult[0] == line: menu.AppendMenu( - flags, ID_LOCATE_FILE, "&Locate %s.py" % patImport.group("name") + flags, ID_LOCATE_FILE, "&Locate %s.py" % matchResult.group("name") ) menu.AppendMenu(win32con.MF_SEPARATOR) menu.AppendMenu(flags, win32ui.ID_EDIT_UNDO, "&Undo") diff --git a/Pythonwin/pywin/framework/mdi_pychecker.py b/Pythonwin/pywin/framework/mdi_pychecker.py index cd31a9a18..3108c2e81 100644 --- a/Pythonwin/pywin/framework/mdi_pychecker.py +++ b/Pythonwin/pywin/framework/mdi_pychecker.py @@ -145,8 +145,7 @@ def __radd__(self, other): # Group(1) is the filename, group(2) is the lineno. -# regexGrepResult=regex.compile(r"^\([a-zA-Z]:.*\)(\([0-9]+\))") -# regexGrep=re.compile(r"^([a-zA-Z]:[^(]*)\((\d+)\)") +# regexGrep = re.compile(r"^([a-zA-Z]:[^(]*)\((\d+)\)") regexGrep = re.compile(r"^(..[^\(:]+)?[\(:](\d+)[\):]:?\s*(.*)") # these are the atom numbers defined by Windows for basic dialog controls diff --git a/Pythonwin/pywin/framework/sgrepmdi.py b/Pythonwin/pywin/framework/sgrepmdi.py index f318f731f..0016cc854 100644 --- a/Pythonwin/pywin/framework/sgrepmdi.py +++ b/Pythonwin/pywin/framework/sgrepmdi.py @@ -127,8 +127,6 @@ def __radd__(self, other): # Group(1) is the filename, group(2) is the lineno. -# regexGrepResult=regex.compile(r"^\([a-zA-Z]:.*\)(\([0-9]+\))") - regexGrep = re.compile(r"^([a-zA-Z]:[^(]*)\(([0-9]+)\)") # these are the atom numbers defined by Windows for basic dialog controls From 85ed0f0797534750865f0f50407a010228b930ed Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 23 Oct 2024 16:39:08 -0400 Subject: [PATCH 2/2] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 61ee2e101..fd957b7d6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,7 +14,7 @@ https://mhammond.github.io/pywin32_installers.html. Coming in build 309, as yet unreleased -------------------------------------- -* Fixed Pythonwin's editor failing due to invalid regex import (#, @Avasam) +* Fixed Pythonwin's editor failing due to invalid regex import (#2419, @Avasam) * Dropped support for Python 3.7 (#2207, @Avasam) * Implement the creation of SAFEARRAY(VT_RECORD) from a sequence of COM Records (#2317, @geppi) * Implement record pointers as [in, out] method parameters of a Dispatch Interface (#2304, #2310, @geppi)