refactor: @cause_by.setter

This commit is contained in:
莘权 马 2023-11-04 16:46:32 +08:00
parent 1febf168e7
commit d9775037b6
21 changed files with 73 additions and 123 deletions

View file

@ -315,3 +315,13 @@ def get_object_name(obj) -> str:
"""Return class name of the object"""
cls = type(obj)
return f"{cls.__module__}.{cls.__name__}"
def any_to_str(val) -> str:
"""Return the class name or the class name of the object, or 'val' if it's a string type."""
if isinstance(val, str):
return val
if not callable(val):
return get_object_name(val)
return get_class_name(val)

View file

@ -1,21 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023/11/1
@Author : mashenquan
@File : named.py
"""
class Named:
"""A base class with functions for converting classes to names and objects to class names."""
@classmethod
def get_class_name(cls):
"""Return class name"""
return f"{cls.__module__}.{cls.__name__}"
def get_object_name(self):
"""Return class name of the object"""
cls = type(self)
return f"{cls.__module__}.{cls.__name__}"