liniting, black, mypy fixes
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
from typing import Any, List, Optional, TYPE_CHECKING, Type, Union, Sequence
|
from typing import Any, List, Optional, Sequence, TYPE_CHECKING, Type, Union
|
||||||
|
|
||||||
from ormar.fields import BaseField
|
from ormar.fields import BaseField
|
||||||
from ormar.fields.foreign_key import ForeignKeyField
|
from ormar.fields.foreign_key import ForeignKeyField
|
||||||
@ -50,7 +50,8 @@ def ManyToMany(
|
|||||||
class ManyToManyField(ForeignKeyField):
|
class ManyToManyField(ForeignKeyField):
|
||||||
through: Type["Model"]
|
through: Type["Model"]
|
||||||
|
|
||||||
if TYPE_CHECKING: # pragma nocover
|
if TYPE_CHECKING: # noqa: C901; pragma nocover
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def add(item: "Model") -> None:
|
async def add(item: "Model") -> None:
|
||||||
pass
|
pass
|
||||||
@ -62,7 +63,7 @@ class ManyToManyField(ForeignKeyField):
|
|||||||
from ormar import QuerySet
|
from ormar import QuerySet
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def filter(**kwargs: Any) -> "QuerySet": # noqa: A003
|
def filter(**kwargs: Any) -> "QuerySet": # noqa: A003, A001
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -70,15 +71,15 @@ class ManyToManyField(ForeignKeyField):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def exists(self) -> bool:
|
async def exists() -> bool:
|
||||||
return await self.queryset.exists()
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def count(self) -> int:
|
async def count() -> int:
|
||||||
return await self.queryset.count()
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def clear(self) -> int:
|
async def clear() -> int:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -86,21 +87,21 @@ class ManyToManyField(ForeignKeyField):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def offset(self, offset: int) -> "QuerySet":
|
def offset(offset: int) -> "QuerySet":
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def first(self, **kwargs: Any) -> "Model":
|
async def first(**kwargs: Any) -> "Model":
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get(self, **kwargs: Any) -> "Model":
|
async def get(**kwargs: Any) -> "Model":
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def all(self, **kwargs: Any) -> Sequence[Optional["Model"]]: # noqa: A003
|
async def all(**kwargs: Any) -> Sequence[Optional["Model"]]: # noqa: A003, A001
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def create(self, **kwargs: Any) -> "Model":
|
async def create(**kwargs: Any) -> "Model":
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -208,8 +208,14 @@ def extract_field_from_annotation_or_value(
|
|||||||
|
|
||||||
def populate_pydantic_default_values(attrs: Dict) -> Tuple[Dict, Dict]:
|
def populate_pydantic_default_values(attrs: Dict) -> Tuple[Dict, Dict]:
|
||||||
model_fields = {}
|
model_fields = {}
|
||||||
potential_fields = {k: v for k, v in attrs["__annotations__"].items() if lenient_issubclass(v, BaseField)}
|
potential_fields = {
|
||||||
potential_fields.update({k: v for k, v in attrs.items() if lenient_issubclass(v, BaseField)})
|
k: v
|
||||||
|
for k, v in attrs["__annotations__"].items()
|
||||||
|
if lenient_issubclass(v, BaseField)
|
||||||
|
}
|
||||||
|
potential_fields.update(
|
||||||
|
{k: v for k, v in attrs.items() if lenient_issubclass(v, BaseField)}
|
||||||
|
)
|
||||||
for field_name, field in potential_fields.items():
|
for field_name, field in potential_fields.items():
|
||||||
# ormar fields can be used as annotation or as default value
|
# ormar fields can be used as annotation or as default value
|
||||||
if check_if_field_annotation_or_value_is_ormar(field, field_name, attrs):
|
if check_if_field_annotation_or_value_is_ormar(field, field_name, attrs):
|
||||||
@ -226,10 +232,8 @@ def populate_pydantic_default_values(attrs: Dict) -> Tuple[Dict, Dict]:
|
|||||||
return attrs, model_fields
|
return attrs, model_fields
|
||||||
|
|
||||||
|
|
||||||
def extract_annotations_and_default_vals(
|
def extract_annotations_and_default_vals(attrs: dict) -> Tuple[Dict, Dict]:
|
||||||
attrs: dict
|
key = "__annotations__"
|
||||||
) -> Tuple[Dict, Dict]:
|
|
||||||
key = '__annotations__'
|
|
||||||
attrs[key] = attrs.get(key, {})
|
attrs[key] = attrs.get(key, {})
|
||||||
attrs, model_fields = populate_pydantic_default_values(attrs)
|
attrs, model_fields = populate_pydantic_default_values(attrs)
|
||||||
return attrs, model_fields
|
return attrs, model_fields
|
||||||
|
|||||||
@ -38,9 +38,7 @@ class Artist(ormar.Model):
|
|||||||
first_name = ormar.String(name="fname", max_length=100)
|
first_name = ormar.String(name="fname", max_length=100)
|
||||||
last_name = ormar.String(name="lname", max_length=100)
|
last_name = ormar.String(name="lname", max_length=100)
|
||||||
born_year = ormar.Integer(name="year")
|
born_year = ormar.Integer(name="year")
|
||||||
children = ormar.ManyToMany(
|
children = ormar.ManyToMany(Child, through=ArtistChildren)
|
||||||
Child, through=ArtistChildren
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Album(ormar.Model):
|
class Album(ormar.Model):
|
||||||
|
|||||||
@ -53,9 +53,7 @@ class Item(ormar.Model):
|
|||||||
|
|
||||||
id = ormar.Integer(primary_key=True)
|
id = ormar.Integer(primary_key=True)
|
||||||
name = ormar.String(max_length=100)
|
name = ormar.String(max_length=100)
|
||||||
categories = ormar.ManyToMany(
|
categories = ormar.ManyToMany(Category, through=ItemsXCategories)
|
||||||
Category, through=ItemsXCategories
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, scope="module")
|
@pytest.fixture(autouse=True, scope="module")
|
||||||
|
|||||||
@ -49,9 +49,7 @@ class Post(ormar.Model):
|
|||||||
|
|
||||||
id = ormar.Integer(primary_key=True)
|
id = ormar.Integer(primary_key=True)
|
||||||
title = ormar.String(max_length=200)
|
title = ormar.String(max_length=200)
|
||||||
categories = ormar.ManyToMany(
|
categories = ormar.ManyToMany(Category, through=PostCategory)
|
||||||
Category, through=PostCategory
|
|
||||||
)
|
|
||||||
author = ormar.ForeignKey(Author)
|
author = ormar.ForeignKey(Author)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -139,6 +139,7 @@ def test_sqlalchemy_table_is_created(example):
|
|||||||
@typing.no_type_check
|
@typing.no_type_check
|
||||||
def test_no_pk_in_model_definition(): # type: ignore
|
def test_no_pk_in_model_definition(): # type: ignore
|
||||||
with pytest.raises(ModelDefinitionError): # type: ignore
|
with pytest.raises(ModelDefinitionError): # type: ignore
|
||||||
|
|
||||||
class ExampleModel2(Model): # type: ignore
|
class ExampleModel2(Model): # type: ignore
|
||||||
class Meta:
|
class Meta:
|
||||||
tablename = "example2"
|
tablename = "example2"
|
||||||
@ -150,6 +151,7 @@ def test_no_pk_in_model_definition(): # type: ignore
|
|||||||
@typing.no_type_check
|
@typing.no_type_check
|
||||||
def test_two_pks_in_model_definition():
|
def test_two_pks_in_model_definition():
|
||||||
with pytest.raises(ModelDefinitionError):
|
with pytest.raises(ModelDefinitionError):
|
||||||
|
|
||||||
@typing.no_type_check
|
@typing.no_type_check
|
||||||
class ExampleModel2(Model):
|
class ExampleModel2(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -163,6 +165,7 @@ def test_two_pks_in_model_definition():
|
|||||||
@typing.no_type_check
|
@typing.no_type_check
|
||||||
def test_setting_pk_column_as_pydantic_only_in_model_definition():
|
def test_setting_pk_column_as_pydantic_only_in_model_definition():
|
||||||
with pytest.raises(ModelDefinitionError):
|
with pytest.raises(ModelDefinitionError):
|
||||||
|
|
||||||
class ExampleModel2(Model):
|
class ExampleModel2(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
tablename = "example4"
|
tablename = "example4"
|
||||||
@ -174,6 +177,7 @@ def test_setting_pk_column_as_pydantic_only_in_model_definition():
|
|||||||
@typing.no_type_check
|
@typing.no_type_check
|
||||||
def test_decimal_error_in_model_definition():
|
def test_decimal_error_in_model_definition():
|
||||||
with pytest.raises(ModelDefinitionError):
|
with pytest.raises(ModelDefinitionError):
|
||||||
|
|
||||||
class ExampleModel2(Model):
|
class ExampleModel2(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
tablename = "example5"
|
tablename = "example5"
|
||||||
@ -185,6 +189,7 @@ def test_decimal_error_in_model_definition():
|
|||||||
@typing.no_type_check
|
@typing.no_type_check
|
||||||
def test_string_error_in_model_definition():
|
def test_string_error_in_model_definition():
|
||||||
with pytest.raises(ModelDefinitionError):
|
with pytest.raises(ModelDefinitionError):
|
||||||
|
|
||||||
class ExampleModel2(Model):
|
class ExampleModel2(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
tablename = "example6"
|
tablename = "example6"
|
||||||
|
|||||||
@ -71,9 +71,7 @@ class Country(ormar.Model):
|
|||||||
database = database
|
database = database
|
||||||
|
|
||||||
id = ormar.Integer(primary_key=True)
|
id = ormar.Integer(primary_key=True)
|
||||||
name = ormar.String(
|
name = ormar.String(max_length=9, choices=country_name_choices, default="Canada",)
|
||||||
max_length=9, choices=country_name_choices, default="Canada",
|
|
||||||
)
|
|
||||||
taxed = ormar.Boolean(choices=country_taxed_choices, default=True)
|
taxed = ormar.Boolean(choices=country_taxed_choices, default=True)
|
||||||
country_code = ormar.Integer(
|
country_code = ormar.Integer(
|
||||||
minimum=0, maximum=1000, choices=country_country_code_choices, default=1
|
minimum=0, maximum=1000, choices=country_country_code_choices, default=1
|
||||||
|
|||||||
Reference in New Issue
Block a user