Skip to content

Commit

Permalink
Fix issue of yield type in Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 committed Aug 24, 2023
1 parent f81e889 commit 1d60f54
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions pydoclint/visitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast
import sys
from typing import List, Optional, Set

from pydoclint.utils.annotation import unparseAnnotation
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 1d60f54

Please sign in to comment.