Skip to content

Commit

Permalink
Merge pull request #237 from Toloka/fix-module-name-in-metaclasses
Browse files Browse the repository at this point in the history
Fix __module__ in metaclasses
  • Loading branch information
alexdrydew authored Sep 15, 2023
2 parents cd05aa2 + 9f8c9de commit f0be614
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
20 changes: 10 additions & 10 deletions src/client/aggregation.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ class PoolAggregatedSolutionRequest(toloka.client.primitives.base.BaseTolokaObje
fields: Output data fields to aggregate. For the best results, each of these fields should have limited number of response options.
If the `DAWID_SKENE` aggregation type is selected, you can only specify one value.
Example:
>>> aggregation_operation = toloka_client.aggregate_solutions_by_pool(
>>> type=toloka.client.aggregation.AggregatedSolutionType.WEIGHTED_DYNAMIC_OVERLAP,
>>> pool_id='1080020',
>>> answer_weight_skill_id='11294',
>>> fields=[toloka.client.aggregation.PoolAggregatedSolutionRequest.Field(name='result')]
>>> )
>>> aggregation_operation = toloka_client.wait_operation(aggregation_operation)
>>> aggregation_results = list(toloka_client.get_aggregated_solutions(aggregation_operation.id))
...
Example:
>>> aggregation_operation = toloka_client.aggregate_solutions_by_pool(
>>> type=toloka.client.aggregation.AggregatedSolutionType.WEIGHTED_DYNAMIC_OVERLAP,
>>> pool_id='1080020',
>>> answer_weight_skill_id='11294',
>>> fields=[toloka.client.aggregation.PoolAggregatedSolutionRequest.Field(name='result')]
>>> )
>>> aggregation_operation = toloka_client.wait_operation(aggregation_operation)
>>> aggregation_results = list(toloka_client.get_aggregated_solutions(aggregation_operation.id))
...
"""

class Field(toloka.client.primitives.base.BaseTolokaObject):
Expand Down
12 changes: 6 additions & 6 deletions src/client/search_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ def _create_sort_field_enum(qualname: str, sort_fields: List[str]):
return unique(Enum(qualname.split('.')[-1], namespace)) # type: ignore

@classmethod
def for_fields(cls, qualname: str, sort_fields: List[str]):
def for_fields(cls, qualname: str, sort_fields: List[str], module_name: str = __name__):
sort_field_enum = cls._create_sort_field_enum(f'{qualname}.SortField', sort_fields)
sort_field_enum.__module__ = module_name
namespace = {
'SortField': sort_field_enum,
'order': SortOrder.ASCENDING,
Expand All @@ -111,7 +112,7 @@ def for_fields(cls, qualname: str, sort_fields: List[str]):
}

subclass = BaseTolokaObjectMetaclass(qualname.split('.')[-1], (cls,), namespace, kw_only=False)
subclass.__module__ = __name__
subclass.__module__ = module_name
return subclass


Expand All @@ -127,8 +128,8 @@ def structure(cls, items):
return cls(items=items)

@classmethod
def for_fields(cls, qualname: str, sort_fields: List[str], docstring: Optional[str] = None):
sort_item_class: Type = BaseSortItem.for_fields(f'{qualname}.SortItem', sort_fields)
def for_fields(cls, qualname: str, sort_fields: List[str], docstring: Optional[str] = None, module_name: str = __name__):
sort_item_class: Type = BaseSortItem.for_fields(f'{qualname}.SortItem', sort_fields, module_name=module_name)

def items_converter(items):
if isinstance(items, sort_items_class):
Expand All @@ -144,7 +145,7 @@ def items_converter(items):
'__qualname__': qualname,
}
sort_items_class = BaseTolokaObjectMetaclass(qualname.split('.')[-1], (BaseSortItems,), namespace, kw_only=False)
sort_items_class.__module__ = __name__
sort_items_class.__module__ = module_name
sort_items_class.__doc__ = docstring
return sort_items_class

Expand All @@ -164,7 +165,6 @@ def __new__(mcs, name, bases, namespace, kw_only=False, **kwargs):

# Building class
subclass = super().__new__(mcs, name, bases, namespace, kw_only=kw_only, **kwargs)
subclass.__module__ = __name__
return subclass


Expand Down
6 changes: 4 additions & 2 deletions src/client/search_requests.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class BaseSortItem(toloka.client.primitives.base.BaseTolokaObject):
def for_fields(
cls,
qualname: str,
sort_fields: typing.List[str]
sort_fields: typing.List[str],
module_name: str = 'toloka.client.search_requests'
): ...

def __init__(self) -> None:
Expand All @@ -105,7 +106,8 @@ class BaseSortItems(toloka.client.primitives.base.BaseTolokaObject):
cls,
qualname: str,
sort_fields: typing.List[str],
docstring: typing.Optional[str] = None
docstring: typing.Optional[str] = None,
module_name: str = 'toloka.client.search_requests'
): ...

def __init__(self) -> None:
Expand Down

0 comments on commit f0be614

Please sign in to comment.