Skip to content

Commit

Permalink
Comments after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
neNasko1 committed Dec 4, 2024
1 parent 0c3de9f commit 8644df5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/spox/_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import enum
from collections.abc import Iterable, Iterator, Sequence
from dataclasses import Field, dataclass
from typing import Any, Optional, Union
from typing import Any, Optional, Union, get_type_hints

from ._attributes import Attr
from ._var import Var
Expand Down Expand Up @@ -61,13 +61,14 @@ def __post_init__(self) -> None:
@classmethod
def _get_field_type(cls, field: Field) -> VarFieldKind:
"""Access the kind of the field (single, optional, variadic) based on its type annotation."""
# The field may be unannotated as per
# The field.type may be unannotated as per
field_type = get_type_hints(cls)[field.name]
# from __future__ import annotations
if field.type in [Var, "Var"]:
if field_type == Var:
return VarFieldKind.SINGLE
elif field.type in [Optional[Var], "Optional[Var]"]:
elif field_type == Optional[Var]:
return VarFieldKind.OPTIONAL
elif field.type in [Sequence[Var], "Sequence[Var]"]:
elif field_type == Sequence[Var]:
return VarFieldKind.VARIADIC
raise ValueError(f"Bad field type: '{field.type}'.")

Expand Down

0 comments on commit 8644df5

Please sign in to comment.