|
18 | 18 | # along with python-transip. If not, see <https://www.gnu.org/licenses/>. |
19 | 19 | """Wrapper for the TransIP API.""" |
20 | 20 |
|
21 | | -from typing import Dict, Optional, Any, Type, Union |
| 21 | +from typing import Dict, Optional, Any, Type, Union, TYPE_CHECKING |
| 22 | +from types import ModuleType |
22 | 23 |
|
23 | 24 | import importlib |
24 | 25 | import requests |
|
36 | 37 | __license__ = "LGPL3" |
37 | 38 |
|
38 | 39 |
|
| 40 | +if TYPE_CHECKING: |
| 41 | + # Imports only needed for type checking. These will not be imported at |
| 42 | + # runtime. |
| 43 | + from transip.base import ApiService |
| 44 | + |
| 45 | + |
39 | 46 | class TransIP: |
40 | 47 | """Represents a TransIP server connection. |
41 | 48 |
|
@@ -76,17 +83,28 @@ def __init__( |
76 | 83 | self._set_auth_info() |
77 | 84 |
|
78 | 85 | # Dynamically import the services for the specified API version |
79 | | - objects = importlib.import_module(f"transip.v{api_version}.objects") |
| 86 | + objects: ModuleType = ( |
| 87 | + importlib.import_module(f"transip.v{api_version}.objects") |
| 88 | + ) |
80 | 89 |
|
81 | | - self.availability_zones: Type[Any] = ( |
| 90 | + self.api_test: Type['ApiService'] = ( |
| 91 | + objects.ApiTestService(self) # type: ignore |
| 92 | + ) |
| 93 | + self.availability_zones: Type['ApiService'] = ( |
82 | 94 | objects.AvailabilityZoneService(self) # type: ignore |
83 | 95 | ) |
84 | | - self.domains: Type[Any] = objects.DomainService(self) # type: ignore |
85 | | - self.invoices: Type[Any] = ( |
| 96 | + self.domains: Type['ApiService'] = ( |
| 97 | + objects.DomainService(self) # type: ignore |
| 98 | + ) |
| 99 | + self.invoices: Type['ApiService'] = ( |
86 | 100 | objects.InvoiceService(self) # type: ignore |
87 | 101 | ) |
88 | | - self.ssh_keys: Type[Any] = objects.SshKeyService(self) # type: ignore |
89 | | - self.vpss: Type[Any] = objects.VpsService(self) # type: ignore |
| 102 | + self.ssh_keys: Type['ApiService'] = ( |
| 103 | + objects.SshKeyService(self) # type: ignore |
| 104 | + ) |
| 105 | + self.vpss: Type['ApiService'] = ( |
| 106 | + objects.VpsService(self) # type: ignore |
| 107 | + ) |
90 | 108 |
|
91 | 109 | @property |
92 | 110 | def url(self) -> str: |
|
0 commit comments