解析并导入点分表示法的对象
(
obj_str: str, default_attr: str, default_prefix: str | None = None
)
| 357 | |
| 358 | |
| 359 | def resolve_dot_notation( |
| 360 | obj_str: str, default_attr: str, default_prefix: str | None = None |
| 361 | ) -> Any: |
| 362 | """解析并导入点分表示法的对象""" |
| 363 | modulename, _, cls = obj_str.partition(":") |
| 364 | if default_prefix is not None and modulename.startswith("~"): |
| 365 | modulename = default_prefix + modulename[1:] |
| 366 | module = importlib.import_module(modulename) |
| 367 | if not cls: |
| 368 | return getattr(module, default_attr) |
| 369 | instance = module |
| 370 | for attr_str in cls.split("."): |
| 371 | instance = getattr(instance, attr_str) |
| 372 | return instance |
| 373 | |
| 374 | |
| 375 | class classproperty(Generic[T]): |
no outgoing calls
no test coverage detected