mypy m2m iterator fix (#655)
* feat: add type hint for items in iterators for m2m relations * chore: make flake8 happy - rename some variables - reorder some imports * switch to typing.List Co-authored-by: Benjamin Mollier <benjamin.mollier@meetap.de> Co-authored-by: collerek <collerek@gmail.com>
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
import decimal
|
||||
import uuid
|
||||
from enum import EnumMeta, Enum as E
|
||||
from enum import Enum as E, EnumMeta
|
||||
from typing import Any, Optional, Set, TYPE_CHECKING, Type, TypeVar, Union, overload
|
||||
|
||||
import pydantic
|
||||
|
||||
@ -79,9 +79,9 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
|
||||
|
||||
@classmethod
|
||||
def translate_enum_columns(cls, new_kwargs: dict) -> dict:
|
||||
for k, v in new_kwargs.items():
|
||||
if isinstance(v, Enum):
|
||||
new_kwargs[k] = v.name
|
||||
for key, value in new_kwargs.items():
|
||||
if isinstance(value, Enum):
|
||||
new_kwargs[key] = value.name
|
||||
return new_kwargs
|
||||
|
||||
@classmethod
|
||||
|
||||
@ -22,8 +22,6 @@ from typing import (
|
||||
import databases
|
||||
import pydantic
|
||||
import sqlalchemy
|
||||
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import Any, Generic, Optional, TYPE_CHECKING, Type, TypeVar
|
||||
from typing import Any, Generic, List, Optional, TYPE_CHECKING, Type, TypeVar
|
||||
|
||||
import ormar
|
||||
from ormar.exceptions import NoMatch, RelationshipInstanceError
|
||||
@ -13,7 +13,7 @@ else:
|
||||
T = TypeVar("T", bound="Model")
|
||||
|
||||
|
||||
class RelationProxy(Generic[T], list):
|
||||
class RelationProxy(Generic[T], List[T]):
|
||||
"""
|
||||
Proxy of the Relation that is a list with special methods.
|
||||
"""
|
||||
|
||||
@ -86,6 +86,7 @@ async def test_types() -> None:
|
||||
# reveal_type(publisher) # model method
|
||||
# reveal_type(publishers) # many to many
|
||||
# reveal_type(publishers[0]) # item in m2m list
|
||||
# reveal_type(next(p for p in publishers)) # item in m2m iterator
|
||||
# # getting relation without __getattribute__
|
||||
# reveal_type(authors) # reverse many to many # TODO: wrong
|
||||
# reveal_type(book2) # queryset get
|
||||
|
||||
Reference in New Issue
Block a user