Skip to content

Commit

Permalink
fix: Support Literal imported from typing_extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Apr 8, 2023
1 parent 1b940fd commit 3a16e58
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/griffe/agents/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def _get_name_annotation(node: NodeName, parent: Module | Class) -> Name:

def _get_subscript_annotation(node: NodeSubscript, parent: Module | Class) -> Expression:
left = _get_annotation(node.value, parent)
if left.full == "typing.Literal": # type: ignore[union-attr]
if left.full in {"typing.Literal", "typing_extensions.Literal"}: # type: ignore[union-attr]
_node_annotation_map[NodeConstant] = _get_literal_annotation
subscript = _get_annotation(node.slice, parent)
_node_annotation_map[NodeConstant] = _get_constant_annotation
Expand Down
2 changes: 2 additions & 0 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def _flat(expression: str | Name | Expression) -> list[str | Name]:
[
("import typing\nclass A: ...\na: typing.Literal['A']", False),
("from typing import Literal\nclass A: ...\na: Literal['A']", False),
("import typing_extensions\nclass A: ...\na: typing.Literal['A']", False),
("from typing_extensions import Literal\nclass A: ...\na: Literal['A']", False),
("from mod import A\na: 'A'", True),
("from mod import A\na: list['A']", True),
],
Expand Down

0 comments on commit 3a16e58

Please sign in to comment.