Skip to content

Commit 1868e8f

Browse files
Merge pull request #110 from isaacharrisholt/typing-fixes
fix: correct typing for basemodel return types
2 parents 65fe5ab + 5fffde3 commit 1868e8f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

quiffen/core/base.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from abc import abstractmethod
2-
from typing import Any, Dict, Generic, Iterable, List, Optional, Type, TypeVar
2+
from typing import Any, Dict, Iterable, List, Optional, Type, TypeVar
33

44
from pydantic import BaseModel as PydanticBaseModel
55

6-
T = TypeVar("T")
7-
86

97
class Field(PydanticBaseModel):
108
"""A custom field for a QIF object.
@@ -38,7 +36,10 @@ def __lt__(self, other) -> bool:
3836
)
3937

4038

41-
class BaseModel(PydanticBaseModel, Generic[T]):
39+
TModel = TypeVar("TModel", bound="BaseModel")
40+
41+
42+
class BaseModel(PydanticBaseModel):
4243
class Config:
4344
extra = "allow"
4445

@@ -85,11 +86,11 @@ def _get_custom_fields(cls) -> List[Field]:
8586

8687
@classmethod
8788
@abstractmethod
88-
def from_list(cls, lst: List[str]) -> T:
89+
def from_list(cls: Type[TModel], lst: List[str]) -> TModel:
8990
pass
9091

9192
@classmethod
92-
def from_string(cls, string: str, separator: str = "\n") -> T:
93+
def from_string(cls: Type[TModel], string: str, separator: str = "\n") -> TModel:
9394
"""Create a class instance from a string."""
9495
return cls.from_list(string.split(separator))
9596

quiffen/core/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def to_qif(
319319
return qif
320320

321321
@classmethod
322-
def from_list(
322+
def from_list( # type: ignore - this one needs an incompatible return type
323323
cls,
324324
lst: List[str],
325325
day_first: bool = False,

0 commit comments

Comments
 (0)