From dd924aa362a9d7a8c1f52c4c83f50bfa23c0a6be Mon Sep 17 00:00:00 2001 From: layday Date: Thu, 8 Jun 2023 23:33:14 +0300 Subject: [PATCH 1/2] Make `BaseValidationError` base static in Python < 3.11 Unsure if this worked in MyPy but Pyright failed to resolve the base of `BaseValidationError` subclasses leading to hard to trace type errors in custom note attributes from failing to narrow Iterable and ClassValidationError unions. --- src/cattrs/_compat.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cattrs/_compat.py b/src/cattrs/_compat.py index 9f82fbee..2bed4657 100644 --- a/src/cattrs/_compat.py +++ b/src/cattrs/_compat.py @@ -1,4 +1,3 @@ -import builtins import sys from collections import deque from collections.abc import MutableSet as AbcMutableSet @@ -62,10 +61,10 @@ def get_origin(cl): else: from typing import Final, Protocol, get_args, get_origin -if "ExceptionGroup" not in dir(builtins): - from exceptiongroup import ExceptionGroup -else: +if is_py311_plus: ExceptionGroup = ExceptionGroup +else: + from exceptiongroup import ExceptionGroup def has(cls): From 356b82c2e605a693767f607be966ce98779c9a41 Mon Sep 17 00:00:00 2001 From: layday Date: Fri, 9 Jun 2023 18:45:46 +0300 Subject: [PATCH 2/2] Silence lint error --- src/cattrs/_compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cattrs/_compat.py b/src/cattrs/_compat.py index 2bed4657..4fa222db 100644 --- a/src/cattrs/_compat.py +++ b/src/cattrs/_compat.py @@ -64,7 +64,7 @@ def get_origin(cl): if is_py311_plus: ExceptionGroup = ExceptionGroup else: - from exceptiongroup import ExceptionGroup + from exceptiongroup import ExceptionGroup as ExceptionGroup # noqa: PLC0414 def has(cls):