From 1d60f5436283aaf3637e9ebdd3358621cf10e7e9 Mon Sep 17 00:00:00 2001 From: jsh9 <25124332+jsh9@users.noreply.github.com> Date: Thu, 24 Aug 2023 02:37:32 -0700 Subject: [PATCH] Fix issue of yield type in Python 3.8 --- pydoclint/visitor.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pydoclint/visitor.py b/pydoclint/visitor.py index 774dffa..9373248 100644 --- a/pydoclint/visitor.py +++ b/pydoclint/visitor.py @@ -1,4 +1,5 @@ import ast +import sys from typing import List, Optional, Set from pydoclint.utils.annotation import unparseAnnotation @@ -667,12 +668,23 @@ def checkYields( # noqa: C901 # type annotation (Generator[YieldType, SendType, # ReturnType]) # https://docs.python.org/3/library/typing.html#typing.Generator - yieldType: str = ( - ast.parse(returnAnno.annotation) - .body[0] - .value.slice.elts[0] - .id - ) + yieldType: str + + if sys.version_info >= (3, 9): + yieldType = ( + ast.parse(returnAnno.annotation) + .body[0] + .value.slice.elts[0] + .id + ) + else: + yieldType = ( + ast.parse(returnAnno.annotation) + .body[0] + .value.slice.value.elts[0] # here is different + .id + ) + except Exception: yieldType = returnAnno.annotation