add misin literal in 3.6-3.7
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
import uuid
|
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 pydantic
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
@ -11,6 +11,11 @@ from ormar.fields import sqlalchemy_uuid
|
|||||||
from ormar.fields.base import BaseField # noqa I101
|
from ormar.fields.base import BaseField # noqa I101
|
||||||
from ormar.fields.sqlalchemy_encrypted import EncryptBackends
|
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(
|
def is_field_nullable(
|
||||||
nullable: Optional[bool],
|
nullable: Optional[bool],
|
||||||
@ -426,23 +431,23 @@ class JSON(ModelFieldFactory, pydantic.Json):
|
|||||||
return sqlalchemy.JSON()
|
return sqlalchemy.JSON()
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING: # pragma: nocover
|
if TYPE_CHECKING: # pragma: nocover # noqa: C901
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def LargeBinary(
|
def LargeBinary(
|
||||||
max_length: int, *, represent_as_base64_str: Literal[True], **kwargs
|
max_length: int, *, represent_as_base64_str: Literal[True], **kwargs: Any
|
||||||
) -> str:
|
) -> str:
|
||||||
...
|
...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def LargeBinary(
|
def LargeBinary(
|
||||||
max_length: int, *, represent_as_base64_str: Literal[False], **kwargs
|
max_length: int, *, represent_as_base64_str: Literal[False], **kwargs: Any
|
||||||
) -> bytes:
|
) -> bytes:
|
||||||
...
|
...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def LargeBinary(
|
def LargeBinary(
|
||||||
max_length: int, represent_as_base64_str: Literal[False] = ..., **kwargs
|
max_length: int, represent_as_base64_str: Literal[False] = ..., **kwargs: Any
|
||||||
) -> bytes:
|
) -> bytes:
|
||||||
...
|
...
|
||||||
|
|
||||||
@ -456,7 +461,8 @@ else:
|
|||||||
|
|
||||||
class LargeBinary(ModelFieldFactory, bytes):
|
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
|
_type = bytes
|
||||||
|
|||||||
@ -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():
|
for name, field in model.Meta.model_fields.items():
|
||||||
if not field.is_relation:
|
if not field.is_relation:
|
||||||
if field.__type__ == bytes and field.represent_as_base64_str:
|
is_bytes_str = field.__type__ == bytes and field.represent_as_base64_str
|
||||||
example[name] = "string"
|
example[name] = field.__sample__ if not is_bytes_str else "string"
|
||||||
else:
|
|
||||||
example[name] = field.__sample__
|
|
||||||
elif isinstance(relation_map, dict) and name in relation_map:
|
elif isinstance(relation_map, dict) and name in relation_map:
|
||||||
example[name] = get_nested_model_example(
|
example[name] = get_nested_model_example(
|
||||||
name=name, field=field, relation_map=relation_map
|
name=name, field=field, relation_map=relation_map
|
||||||
|
|||||||
Reference in New Issue
Block a user