Skip to content

Commit

Permalink
feat: Found a way to type instantiating metaclass
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan committed Feb 16, 2022
1 parent af00c7e commit a58c11b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions factory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def resolve_attribute(name, bases, default=None):
return default


class FactoryMetaClass(type):
class FactoryMetaClass(Generic[T], type):
"""Factory metaclass for handling ordered declarations."""

def __call__(cls, **kwargs):
Expand All @@ -47,7 +47,7 @@ def __call__(cls, **kwargs):
raise errors.UnknownStrategy('Unknown Meta.strategy: {}'.format(
cls._meta.strategy))

def __new__(mcs, class_name, bases, attrs):
def __new__(mcs, class_name, bases, attrs) -> T:
"""Record attributes as a pattern for later instance construction.
This is called when a new Factory subclass is defined; it will collect
Expand Down Expand Up @@ -415,7 +415,7 @@ class BaseFactory(Generic[T]):
UnknownStrategy = errors.UnknownStrategy
UnsupportedStrategy = errors.UnsupportedStrategy

def __new__(cls, *args, **kwargs):
def __new__(cls, *args, **kwargs) -> T:
"""Would be called if trying to instantiate the class."""
raise errors.FactoryError('You cannot instantiate BaseFactory')

Expand Down

0 comments on commit a58c11b

Please sign in to comment.