From 1cd9204665767e05b480fc3fbfd9d820a340772b Mon Sep 17 00:00:00 2001 From: collerek Date: Fri, 2 Aug 2024 09:38:52 +0200 Subject: [PATCH] bump ruff and minor fixes (#1390) --- Makefile | 2 +- ormar/models/helpers/models.py | 2 +- ormar/models/helpers/relations.py | 2 +- ormar/models/helpers/validation.py | 4 ++-- ormar/models/metaclass.py | 2 +- ormar/queryset/actions/order_action.py | 2 +- ormar/relations/querysetproxy.py | 3 +-- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 5b1f0e3..5513ab7 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ type_check: mkdir -p .mypy_cache && poetry run python -m mypy ormar tests --ignore-missing-imports --install-types --non-interactive lint: - poetry run python -m ruff . --fix + poetry run python -m ruff check . --fix fmt: poetry run python -m black . diff --git a/ormar/models/helpers/models.py b/ormar/models/helpers/models.py index e05ed16..c7ccefc 100644 --- a/ormar/models/helpers/models.py +++ b/ormar/models/helpers/models.py @@ -53,7 +53,7 @@ def populate_default_options_values( # noqa: CCR001 name for name, field in model_fields.items() if field.__type__ == pydantic.Json } 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 diff --git a/ormar/models/helpers/relations.py b/ormar/models/helpers/relations.py index 1525580..058df25 100644 --- a/ormar/models/helpers/relations.py +++ b/ormar/models/helpers/relations.py @@ -214,7 +214,7 @@ def replace_models_with_copy( if inspect.isclass(annotation) and issubclass(annotation, ormar.Model): return create_copy_to_avoid_circular_references(model=annotation) elif hasattr(annotation, "__origin__") and annotation.__origin__ in {list, Union}: - if annotation.__origin__ == list: + if annotation.__origin__ is list: return List[ # type: ignore replace_models_with_copy( annotation=annotation.__args__[0], diff --git a/ormar/models/helpers/validation.py b/ormar/models/helpers/validation.py index f284ce8..6461a09 100644 --- a/ormar/models/helpers/validation.py +++ b/ormar/models/helpers/validation.py @@ -76,7 +76,7 @@ def populates_sample_fields_values( :type relation_map: Optional[Dict] """ 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" elif isinstance(relation_map, dict) and name in relation_map: example[name] = get_nested_model_example( @@ -153,7 +153,7 @@ def generate_example_for_nested_types(type_: Any) -> Any: """ if type_.__origin__ == Union: return generate_example_for_union(type_=type_) - if type_.__origin__ == list: + if type_.__origin__ is list: return [get_pydantic_example_repr(type_.__args__[0])] diff --git a/ormar/models/metaclass.py b/ormar/models/metaclass.py index 64dfbeb..849d188 100644 --- a/ormar/models/metaclass.py +++ b/ormar/models/metaclass.py @@ -544,7 +544,7 @@ def add_field_descriptor( setattr(new_model, name, RelationDescriptor(name=name)) elif field.__type__ == pydantic.Json: setattr(new_model, name, JsonDescriptor(name=name)) - elif field.__type__ == bytes: + elif field.__type__ is bytes: setattr(new_model, name, BytesDescriptor(name=name)) else: setattr(new_model, name, PydanticDescriptor(name=name)) diff --git a/ormar/queryset/actions/order_action.py b/ormar/queryset/actions/order_action.py index a77563c..b2bffc2 100644 --- a/ormar/queryset/actions/order_action.py +++ b/ormar/queryset/actions/order_action.py @@ -40,7 +40,7 @@ class OrderAction(QueryAction): field_type = self.target_model.ormar_config.model_fields[ self.field_name ].__type__ - return dialect == "postgresql" and field_type == bool + return dialect == "postgresql" and field_type is bool def get_field_name_text(self) -> str: """ diff --git a/ormar/relations/querysetproxy.py b/ormar/relations/querysetproxy.py index 1a767aa..4eb4713 100644 --- a/ormar/relations/querysetproxy.py +++ b/ormar/relations/querysetproxy.py @@ -1,3 +1,4 @@ +from _weakref import CallableProxyType from typing import ( # noqa: I100, I201 TYPE_CHECKING, Any, @@ -16,8 +17,6 @@ from typing import ( # noqa: I100, I201 cast, ) -from _weakref import CallableProxyType - import ormar # noqa: I100, I202 from ormar.exceptions import ModelPersistenceError, NoMatch, QueryDefinitionError