8000 Fix PathFinder.find_module AttributeError for Python 3.12 · python-mode/python-mode@afc201a · GitHub
[go: up one dir, main page]

Skip to content

Commit afc201a

Browse files
committed
Fix PathFinder.find_module AttributeError for Python 3.12
PathFinder.find_module() has been deprecated since Python 3.4 in favor of find_spec(), and it's finally removed in Python 3.12. This line will throw an AttributeError which makes pymode completely unusable with python 3.12. It was a hacky workaround introduced in #1028. Maybe we can completely remove this workaround because it's 4 years ago and the minimum supported python version is now 3.6+.
1 parent 57384b9 commit afc201a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pymode/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
import vim # noqa
77

88
if not hasattr(vim, 'find_module'):
9-
vim.find_module = _PathFinder.find_module
9+
try:
10+
vim.find_module = _PathFinder.find_module # deprecated
11+
except AttributeError:
12+
def _find_module(package_name):
13+
spec = _PathFinder.find_spec(package_name)
14+
return spec.loader if spec else None
15+
vim.find_module = _find_module
1016

1117

1218
def auto():

0 commit comments

Comments
 (0)
0