Closed guacs closed 7 months ago
I'm totally agree with this request. It would be much better to have annotated Generic.
@sobolevn I know that you have solid expertise with mypy and typing in general. What would you recommend to annotate lazy attributes?
I thought to solve this problem by adding a stub file for generic.py
like this:
import typing as t
from mimesis.locales import Locale
from mimesis.providers import Address, Datetime, Finance, Food, Person, Text
from mimesis.providers.base import BaseProvider
from mimesis.types import Seed
__all__ = ["Generic"]
class Generic(BaseProvider):
locale: Locale
# These attributes are lazy set in __init__ and __getattr_.
person: Person
text: Text
address: Address
finance: Finance
datetime: Datetime
food: Food
# ...
# ...
def __init__(self, locale: Locale = ..., seed: Seed = ...) -> None: ...
class Meta:
name: t.Final[str]
def __getattr__(self, attrname: str) -> t.Any: ...
def __dir__(self) -> list[str]: ...
def reseed(self, seed: Seed = ...) -> None: ...
def add_provider(self, cls: t.Type[BaseProvider], **kwargs: t.Any) -> None: ...
def add_providers(self, *providers: t.Type[BaseProvider]) -> None: ...
def __iadd__(self, other: t.Type[BaseProvider]) -> Generic: ...
But I'm not quite sure about this idea. Any advice or recommendation would be greatly appreciated.
seems fine :)
Fixed in 12.1.0
Feature request
Would it be possible to type hint the providers in the
Generic
class?Thesis
Reasoning
This allows for autocomplete in editors/IDEs, and static type checking by type checkers.