From d4f0ef704119ce154b9d569ce4536b312b00880e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 23 Feb 2024 00:19:27 +0100 Subject: [PATCH] Catch ValueError - generator already executing (#9454) --- .pyenchant_pylint_custom_dict.txt | 1 + doc/whatsnew/fragments/9138.bugfix | 4 ++++ pylint/__init__.py | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 doc/whatsnew/fragments/9138.bugfix diff --git a/.pyenchant_pylint_custom_dict.txt b/.pyenchant_pylint_custom_dict.txt index 8a5f150739..712ab70cca 100644 --- a/.pyenchant_pylint_custom_dict.txt +++ b/.pyenchant_pylint_custom_dict.txt @@ -361,6 +361,7 @@ unicode Uninferable uninferable unittest +unraisablehook untriggered # prefix for string ur diff --git a/doc/whatsnew/fragments/9138.bugfix b/doc/whatsnew/fragments/9138.bugfix new file mode 100644 index 0000000000..cc48d11ab0 --- /dev/null +++ b/doc/whatsnew/fragments/9138.bugfix @@ -0,0 +1,4 @@ +Catch incorrect ValueError ``"generator already executing"`` for Python 3.12.0 - 3.12.2. +This is fixed upstream in Python 3.12.3. + +Closes #9138 diff --git a/pylint/__init__.py b/pylint/__init__.py index cc0f609aac..75cf2b6ee4 100644 --- a/pylint/__init__.py +++ b/pylint/__init__.py @@ -95,4 +95,25 @@ def modify_sys_path() -> None: sys.path.pop(1) +def _catch_valueerror(unraisable: sys.UnraisableHookArgs) -> None: # pragma: no cover + """Overwrite sys.unraisablehook to catch incorrect ValueError. + + Python 3.12 introduced changes that sometimes cause astroid to emit ValueErrors + with 'generator already executing'. Fixed in Python 3.12.3 and 3.13. + + https://github.com/pylint-dev/pylint/issues/9138 + """ + if ( + isinstance(unraisable.exc_value, ValueError) + and unraisable.exc_value.args[0] == "generator already executing" + ): + return + + sys.__unraisablehook__(unraisable) + + +if (3, 12, 0) <= sys.version_info[:3] < (3, 12, 3): + sys.unraisablehook = _catch_valueerror + + version = __version__