bump ruff and minor fixes (#1390)

This commit is contained in:
collerek
2024-08-02 09:38:52 +02:00
committed by GitHub
parent e18caa31e6
commit 1cd9204665
7 changed files with 8 additions and 9 deletions

View File

@ -28,7 +28,7 @@ type_check:
mkdir -p .mypy_cache && poetry run python -m mypy ormar tests --ignore-missing-imports --install-types --non-interactive mkdir -p .mypy_cache && poetry run python -m mypy ormar tests --ignore-missing-imports --install-types --non-interactive
lint: lint:
poetry run python -m ruff . --fix poetry run python -m ruff check . --fix
fmt: fmt:
poetry run python -m black . poetry run python -m black .

View File

@ -53,7 +53,7 @@ def populate_default_options_values( # noqa: CCR001
name for name, field in model_fields.items() if field.__type__ == pydantic.Json name for name, field in model_fields.items() if field.__type__ == pydantic.Json
} }
new_model._bytes_fields = { new_model._bytes_fields = {
name for name, field in model_fields.items() if field.__type__ == bytes name for name, field in model_fields.items() if field.__type__ is bytes
} }
new_model.__relation_map__ = None new_model.__relation_map__ = None

View File

@ -214,7 +214,7 @@ def replace_models_with_copy(
if inspect.isclass(annotation) and issubclass(annotation, ormar.Model): if inspect.isclass(annotation) and issubclass(annotation, ormar.Model):
return create_copy_to_avoid_circular_references(model=annotation) return create_copy_to_avoid_circular_references(model=annotation)
elif hasattr(annotation, "__origin__") and annotation.__origin__ in {list, Union}: elif hasattr(annotation, "__origin__") and annotation.__origin__ in {list, Union}:
if annotation.__origin__ == list: if annotation.__origin__ is list:
return List[ # type: ignore return List[ # type: ignore
replace_models_with_copy( replace_models_with_copy(
annotation=annotation.__args__[0], annotation=annotation.__args__[0],

View File

@ -76,7 +76,7 @@ def populates_sample_fields_values(
:type relation_map: Optional[Dict] :type relation_map: Optional[Dict]
""" """
if not field.is_relation: if not field.is_relation:
is_bytes_str = field.__type__ == bytes and field.represent_as_base64_str is_bytes_str = field.__type__ is bytes and field.represent_as_base64_str
example[name] = field.__sample__ if not is_bytes_str else "string" example[name] = field.__sample__ if not is_bytes_str else "string"
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(
@ -153,7 +153,7 @@ def generate_example_for_nested_types(type_: Any) -> Any:
""" """
if type_.__origin__ == Union: if type_.__origin__ == Union:
return generate_example_for_union(type_=type_) return generate_example_for_union(type_=type_)
if type_.__origin__ == list: if type_.__origin__ is list:
return [get_pydantic_example_repr(type_.__args__[0])] return [get_pydantic_example_repr(type_.__args__[0])]

View File

@ -544,7 +544,7 @@ def add_field_descriptor(
setattr(new_model, name, RelationDescriptor(name=name)) setattr(new_model, name, RelationDescriptor(name=name))
elif field.__type__ == pydantic.Json: elif field.__type__ == pydantic.Json:
setattr(new_model, name, JsonDescriptor(name=name)) setattr(new_model, name, JsonDescriptor(name=name))
elif field.__type__ == bytes: elif field.__type__ is bytes:
setattr(new_model, name, BytesDescriptor(name=name)) setattr(new_model, name, BytesDescriptor(name=name))
else: else:
setattr(new_model, name, PydanticDescriptor(name=name)) setattr(new_model, name, PydanticDescriptor(name=name))

View File

@ -40,7 +40,7 @@ class OrderAction(QueryAction):
field_type = self.target_model.ormar_config.model_fields[ field_type = self.target_model.ormar_config.model_fields[
self.field_name self.field_name
].__type__ ].__type__
return dialect == "postgresql" and field_type == bool return dialect == "postgresql" and field_type is bool
def get_field_name_text(self) -> str: def get_field_name_text(self) -> str:
""" """

View File

@ -1,3 +1,4 @@
from _weakref import CallableProxyType
from typing import ( # noqa: I100, I201 from typing import ( # noqa: I100, I201
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
@ -16,8 +17,6 @@ from typing import ( # noqa: I100, I201
cast, cast,
) )
from _weakref import CallableProxyType
import ormar # noqa: I100, I202 import ormar # noqa: I100, I202
from ormar.exceptions import ModelPersistenceError, NoMatch, QueryDefinitionError from ormar.exceptions import ModelPersistenceError, NoMatch, QueryDefinitionError