MCPcopy Index your code
hub / github.com/piccolo-orm/piccolo / repr_class_instance

Function repr_class_instance

piccolo/utils/repr.py:4–26  ·  view source on GitHub ↗

Piccolo uses code generation for creating migrations. This function takes a class instance, and generates a string representation for it, which can be used in a migration file.

(class_instance: object)

Source from the content-addressed store, hash-verified

2
3
4def repr_class_instance(class_instance: object) -> str:
5 """
6 Piccolo uses code generation for creating migrations. This function takes
7 a class instance, and generates a string representation for it, which can
8 be used in a migration file.
9 """
10 init_arg_names = [
11 i
12 for i in inspect.signature(
13 class_instance.__class__.__init__
14 ).parameters.keys()
15 if i not in ("self", "args", "kwargs")
16 ]
17 args_dict = {}
18 for arg_name in init_arg_names:
19 value = class_instance.__dict__.get(arg_name)
20 args_dict[arg_name] = value
21
22 args_str = ", ".join(
23 f"{key}={value.__repr__()}" for key, value in args_dict.items()
24 )
25
26 return f"{class_instance.__class__.__name__}({args_str})"

Callers 2

__repr__Method · 0.90
__repr__Method · 0.90

Calls 2

getMethod · 0.80
__repr__Method · 0.45

Tested by

no test coverage detected