Skip to content

Commit

Permalink
Check whether node is ast.TypeAlias only if version is at least 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
chopan050 committed Dec 6, 2024
1 parent da3dab0 commit 9dd2c2e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions manim/utils/docbuild/module_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import ast
import sys
from pathlib import Path

from typing_extensions import TypeAlias
Expand Down Expand Up @@ -160,19 +161,18 @@ def parse_module_attributes() -> tuple[AliasDocsDict, DataDict, TypeVarDict]:
for node in inner_nodes:
# Check if this node is a TypeAlias (type <name> = <value>)
# or an AnnAssign annotated as TypeAlias (<target>: TypeAlias = <value>).
is_type_alias = (
sys.version_info >= (3, 12) and type(node) is ast.TypeAlias
)
is_annotated_assignment_with_value = (
type(node) is ast.AnnAssign
and type(node.annotation) is ast.Name
and node.annotation.id == "TypeAlias"
and type(node.target) is ast.Name
and node.value is not None
)
if type(node) is ast.TypeAlias or is_annotated_assignment_with_value:
alias_name = (
node.target.id
if is_annotated_assignment_with_value
else node.name.id
)
if is_type_alias or is_annotated_assignment_with_value:
alias_name = node.name.id if is_type_alias else node.target.id
definition_node = node.value

# If the definition is an Union, replace with vertical bar notation.
Expand Down

0 comments on commit 9dd2c2e

Please sign in to comment.