Skip to content

Commit

Permalink
Fix 3.6 Literal issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Dec 30, 2021
1 parent e00f5a9 commit 5f6a7e1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apischema/discriminators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import operator
import sys
from dataclasses import dataclass
from functools import reduce
from typing import (
Expand Down Expand Up @@ -38,7 +39,11 @@ def get_discriminated(alias: str, tp: AnyType) -> Sequence[str]:
has_field = True
field_type = no_annotated(field.type)
if is_literal(field_type):
return [v for v in get_args(field_type) if isinstance(v, str)]
if sys.version_info < (3, 7): # py36
literal_args = field_type.__values__
else:
literal_args = get_args(field_type)
return [v for v in literal_args if isinstance(v, str)]
if (
is_typed_dict(cls) and not has_field
): # TypedDict must have a discriminator field
Expand Down

0 comments on commit 5f6a7e1

Please sign in to comment.