add misin literal in 3.6-3.7

This commit is contained in:
collerek
2021-05-18 16:27:06 +02:00
parent a28ab0a8a2
commit 68149dc32a
2 changed files with 14 additions and 10 deletions

View File

@ -1,7 +1,7 @@
import datetime
import decimal
import uuid
from typing import Any, List, Literal, Optional, TYPE_CHECKING, Union, overload
from typing import Any, Optional, TYPE_CHECKING, Union, overload
import pydantic
import sqlalchemy
@ -11,6 +11,11 @@ from ormar.fields import sqlalchemy_uuid
from ormar.fields.base import BaseField # noqa I101
from ormar.fields.sqlalchemy_encrypted import EncryptBackends
try:
from typing import Literal
except ImportError: # pragma: no cover
from typing_extensions import Literal # type: ignore
def is_field_nullable(
nullable: Optional[bool],
@ -426,23 +431,23 @@ class JSON(ModelFieldFactory, pydantic.Json):
return sqlalchemy.JSON()
if TYPE_CHECKING: # pragma: nocover
if TYPE_CHECKING: # pragma: nocover # noqa: C901
@overload
def LargeBinary(
max_length: int, *, represent_as_base64_str: Literal[True], **kwargs
max_length: int, *, represent_as_base64_str: Literal[True], **kwargs: Any
) -> str:
...
@overload
def LargeBinary(
max_length: int, *, represent_as_base64_str: Literal[False], **kwargs
max_length: int, *, represent_as_base64_str: Literal[False], **kwargs: Any
) -> bytes:
...
@overload
def LargeBinary(
max_length: int, represent_as_base64_str: Literal[False] = ..., **kwargs
max_length: int, represent_as_base64_str: Literal[False] = ..., **kwargs: Any
) -> bytes:
...
@ -456,7 +461,8 @@ else:
class LargeBinary(ModelFieldFactory, bytes):
"""
LargeBinary field factory that construct Field classes and populated their values.
LargeBinary field factory that construct Field classes
and populated their values.
"""
_type = bytes

View File

@ -142,10 +142,8 @@ def generate_model_example(model: Type["Model"], relation_map: Dict = None) -> D
)
for name, field in model.Meta.model_fields.items():
if not field.is_relation:
if field.__type__ == bytes and field.represent_as_base64_str:
example[name] = "string"
else:
example[name] = field.__sample__
is_bytes_str = field.__type__ == bytes and field.represent_as_base64_str
example[name] = field.__sample__ if not is_bytes_str else "string"
elif isinstance(relation_map, dict) and name in relation_map:
example[name] = get_nested_model_example(
name=name, field=field, relation_map=relation_map