From dba87a89a968e506fbc2db7652f01f0804ca3760 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 16 May 2024 13:01:29 +0100 Subject: [PATCH] Try to infer any variances that can be inferred Also avoid inferring variances repeatedly. --- mypy/subtypes.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mypy/subtypes.py b/mypy/subtypes.py index e1609717e160..a5523fbe0d45 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -2049,8 +2049,9 @@ def infer_class_variances(info: TypeInfo) -> bool: if not info.defn.type_args: return True tvs = info.defn.type_vars + success = True for i, tv in enumerate(tvs): - if isinstance(tv, TypeVarType): + if isinstance(tv, TypeVarType) and tv.variance == VARIANCE_NOT_READY: if not infer_variance(info, i): - return False - return True + success = False + return success