Skip to content

Commit

Permalink
Merge pull request #110 from isaacharrisholt/typing-fixes
Browse files Browse the repository at this point in the history
fix: correct typing for basemodel return types
  • Loading branch information
isaacharrisholt authored Jan 27, 2025
2 parents 65fe5ab + 5fffde3 commit 1868e8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions quiffen/core/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from abc import abstractmethod
from typing import Any, Dict, Generic, Iterable, List, Optional, Type, TypeVar
from typing import Any, Dict, Iterable, List, Optional, Type, TypeVar

from pydantic import BaseModel as PydanticBaseModel

T = TypeVar("T")


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


class BaseModel(PydanticBaseModel, Generic[T]):
TModel = TypeVar("TModel", bound="BaseModel")


class BaseModel(PydanticBaseModel):
class Config:
extra = "allow"

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

@classmethod
@abstractmethod
def from_list(cls, lst: List[str]) -> T:
def from_list(cls: Type[TModel], lst: List[str]) -> TModel:
pass

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

Expand Down
2 changes: 1 addition & 1 deletion quiffen/core/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def to_qif(
return qif

@classmethod
def from_list(
def from_list( # type: ignore - this one needs an incompatible return type
cls,
lst: List[str],
day_first: bool = False,
Expand Down

0 comments on commit 1868e8f

Please sign in to comment.