-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtypehint.py
More file actions
63 lines (48 loc) · 1.95 KB
/
typehint.py
File metadata and controls
63 lines (48 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Commonly used types."""
import sys
from typing import Union
from pathlib import Path
__all__ = ["Literal", "TypedDict", "final"]
if sys.version_info >= (3, 8):
from typing import Literal, TypedDict, final # type: ignore # pylint: disable=no-name-in-module
else:
from typing_extensions import Literal, TypedDict, final
class InstDictConf(TypedDict):
"""
InstDictConf is a Dict-based config to describe an instance
case 1)
{
'class': 'ClassName',
'kwargs': dict, # It is optional. {} will be used if not given
'model_path': path, # It is optional if module is given in the class
}
case 2)
{
'class': <The class it self>,
'kwargs': dict, # It is optional. {} will be used if not given
}
"""
# class: str # because class is a keyword of Python. We have to comment it
kwargs: dict # It is optional. {} will be used if not given
module_path: str # It is optional if module is given in the class
InstConf = Union[InstDictConf, str, object, Path]
"""
InstConf is a type to describe an instance; it will be passed into init_instance_by_config for Qlib
config : Union[str, dict, object, Path]
InstDictConf example.
please refer to the docs of InstDictConf
str example.
1) specify a pickle object
- path like 'file:///<path to pickle file>/obj.pkl'
2) specify a class name
- "ClassName": getattr(module, "ClassName")() will be used.
3) specify module path with class name
- "a.b.c.ClassName" getattr(<a.b.c.module>, "ClassName")() will be used.
object example:
instance of accept_types
Path example:
specify a pickle object
- it will be treated like 'file:///<path to pickle file>/obj.pkl'
"""