From 5ebe2aeb1f348b39b6bee20a1f7806c6a69940ab Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Sun, 10 Mar 2024 10:21:33 +0000 Subject: [PATCH] Use recursive types in `_parser` This makes use of more accurate type checking enabled by newer type checker versions. --- src/packaging/_parser.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/packaging/_parser.py b/src/packaging/_parser.py index 326a9e02..aca87387 100644 --- a/src/packaging/_parser.py +++ b/src/packaging/_parser.py @@ -7,7 +7,7 @@ from __future__ import annotations import ast -from typing import Any, List, NamedTuple, Tuple, Union +from typing import NamedTuple, Sequence, Tuple, Union from ._tokenizer import DEFAULT_RULES, Tokenizer @@ -43,12 +43,8 @@ def serialize(self) -> str: MarkerVar = Union[Variable, Value] MarkerItem = Tuple[MarkerVar, Op, MarkerVar] -# MarkerAtom = Union[MarkerItem, List["MarkerAtom"]] -# MarkerList = List[Union["MarkerList", MarkerAtom, str]] -# mypy does not support recursive type definition -# https://github.com/python/mypy/issues/731 -MarkerAtom = Any -MarkerList = List[Any] +MarkerAtom = Union[MarkerItem, Sequence["MarkerAtom"]] +MarkerList = Sequence[Union["MarkerList", MarkerAtom, str]] class ParsedRequirement(NamedTuple):