-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserving of optimisation results implemented #37
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,13 +62,15 @@ def _get_coder_by_type(coder_type: Type, coder_aim: str): | |
|
||
@staticmethod | ||
def dump_path_to_obj(obj: INSTANCE_OR_CALLABLE) -> Dict[str, str]: | ||
""" | ||
Dumps the full path (module + name) to the input object into the dict | ||
"""Dumps the full path (module + name) to the input object into the dict | ||
|
||
:param obj: object which path should be resolved (class, function or method) | ||
Args: | ||
obj: object which path should be resolved (class, function or method) | ||
|
||
:return: dict[str, str] with path to the object | ||
Returns: | ||
dictionary with path to the object | ||
""" | ||
|
||
if isclass(obj) or isfunction(obj) or ismethod(obj): | ||
obj_name = obj.__qualname__ | ||
else: | ||
|
@@ -83,12 +85,13 @@ def dump_path_to_obj(obj: INSTANCE_OR_CALLABLE) -> Dict[str, str]: | |
} | ||
|
||
def default(self, obj: INSTANCE_OR_CALLABLE) -> Dict[str, Any]: | ||
""" | ||
Tries to encode objects that are not simply json-encodable to JSON-object | ||
"""Tries to encode objects that are not simply json-encodable to JSON-object | ||
|
||
:param obj: object to be encoded (class, function or method) | ||
Args: | ||
obj: object to be encoded (class, function or method) | ||
|
||
:return: dict[str, Any] which is in fact json object | ||
Returns: | ||
json object | ||
""" | ||
if isfunction(obj) or ismethod(obj): | ||
return Serializer.dump_path_to_obj(obj) | ||
|
@@ -100,28 +103,32 @@ def default(self, obj: INSTANCE_OR_CALLABLE) -> Dict[str, Any]: | |
|
||
@staticmethod | ||
def _get_class(class_path: str) -> Type[INSTANCE_OR_CALLABLE]: | ||
""" | ||
Gets the object type from the class_path | ||
"""Gets the object type from the class_path | ||
|
||
:param class_path: full path (module + name) of the class | ||
Args: | ||
class_path: full path (module + name) of the class | ||
|
||
:return: class, function or method type | ||
Returns: | ||
class, function or method type | ||
""" | ||
|
||
module_name, class_name = class_path.split(MODULE_X_NAME_DELIMITER) | ||
obj_cls = import_module(module_name) | ||
for sub in class_name.split('.'): | ||
obj_cls = getattr(obj_cls, sub) | ||
return obj_cls | ||
|
||
def object_hook(self, json_obj: Dict[str, Any]) -> Union[INSTANCE_OR_CALLABLE, dict]: | ||
""" | ||
Decodes every JSON-object to python class/func object or just returns dict | ||
"""Decodes every JSON-object to python class/func object or just returns dict | ||
|
||
:param json_obj: dict[str, Any] to be decoded into Python class, function or | ||
Args: | ||
json_obj: dict[str, Any] to be decoded into Python class, function or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. типы объектов принималось обозначать через There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. при этом сами объекты, например Point, Domain и прочее, вот так -> :obj: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Пока просто убрал дублирующую type hint-ы типизацию. |
||
method object only if it has some special fields | ||
|
||
:return: Python class, function or method object OR input if it's just a regular dict | ||
Returns: | ||
Python class, function or method object OR input if it's just a regular dict | ||
""" | ||
|
||
if CLASS_PATH_KEY in json_obj: | ||
obj_cls = Serializer._get_class(json_obj[CLASS_PATH_KEY]) | ||
del json_obj[CLASS_PATH_KEY] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
этот метод скрытый, зачем его документировать докстрингами?
если им можно пользоваться, то почему он не может быть обычным?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Документировать не обязательно, но лишним не будет. В таком виде взял из FEDOT-а.