Skip to content

Commit

Permalink
refactor: add Clients type hints (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Jul 21, 2023
1 parent c89b5bd commit 66f9163
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 17 deletions.
9 changes: 8 additions & 1 deletion hcloud/actions/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from __future__ import annotations

import time
from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..core.client import BoundModelBase, ClientEntityBase
from ..core.domain import Meta
from .domain import Action, ActionFailedException, ActionTimeoutException

if TYPE_CHECKING:
from .._client import Client


class BoundAction(BoundModelBase):
_client: ActionsClient

model = Action

def wait_until_finished(self, max_retries=100):
Expand Down Expand Up @@ -37,6 +42,8 @@ class ActionsPageResult(NamedTuple):


class ActionsClient(ClientEntityBase):
_client: Client

def get_by_id(self, id):
# type: (int) -> BoundAction
"""Get a specific action by its ID.
Expand Down
9 changes: 8 additions & 1 deletion hcloud/certificates/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..actions.client import ActionsPageResult, BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
Expand All @@ -12,8 +12,13 @@
ManagedCertificateStatus,
)

if TYPE_CHECKING:
from .._client import Client


class BoundCertificate(BoundModelBase):
_client: CertificatesClient

model = Certificate

def __init__(self, client, data, complete=True):
Expand Down Expand Up @@ -91,6 +96,8 @@ class CertificatesPageResult(NamedTuple):


class CertificatesClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> BoundCertificate
"""Get a specific certificate by its ID.
Expand Down
9 changes: 8 additions & 1 deletion hcloud/datacenters/client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from ..locations.client import BoundLocation
from ..server_types.client import BoundServerType
from .domain import Datacenter, DatacenterServerTypes

if TYPE_CHECKING:
from .._client import Client


class BoundDatacenter(BoundModelBase):
_client: DatacentersClient

model = Datacenter

def __init__(self, client, data):
Expand Down Expand Up @@ -52,6 +57,8 @@ class DatacentersPageResult(NamedTuple):


class DatacentersClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> BoundDatacenter
"""Get a specific datacenter by its ID.
Expand Down
9 changes: 8 additions & 1 deletion hcloud/firewalls/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..actions.client import ActionsPageResult, BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
Expand All @@ -13,8 +13,13 @@
FirewallRule,
)

if TYPE_CHECKING:
from .._client import Client


class BoundFirewall(BoundModelBase):
_client: FirewallsClient

model = Firewall

def __init__(self, client, data, complete=True):
Expand Down Expand Up @@ -142,6 +147,8 @@ class FirewallsPageResult(NamedTuple):


class FirewallsClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_actions_list(
self,
firewall, # type: Firewall
Expand Down
9 changes: 8 additions & 1 deletion hcloud/floating_ips/client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..actions.client import ActionsPageResult, BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from ..locations.client import BoundLocation
from .domain import CreateFloatingIPResponse, FloatingIP

if TYPE_CHECKING:
from .._client import Client


class BoundFloatingIP(BoundModelBase):
_client: FloatingIPsClient

model = FloatingIP

def __init__(self, client, data, complete=True):
Expand Down Expand Up @@ -127,6 +132,8 @@ class FloatingIPsPageResult(NamedTuple):


class FloatingIPsClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_actions_list(
self,
floating_ip, # type: FloatingIP
Expand Down
9 changes: 8 additions & 1 deletion hcloud/images/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..actions.client import ActionsPageResult, BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from .domain import Image

if TYPE_CHECKING:
from .._client import Client


class BoundImage(BoundModelBase):
_client: ImagesClient

model = Image

def __init__(self, client, data):
Expand Down Expand Up @@ -97,6 +102,8 @@ class ImagesPageResult(NamedTuple):


class ImagesClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_actions_list(
self,
image, # type: Image
Expand Down
9 changes: 8 additions & 1 deletion hcloud/isos/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple
from warnings import warn

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from .domain import Iso

if TYPE_CHECKING:
from .._client import Client


class BoundIso(BoundModelBase):
_client: IsosClient

model = Iso


Expand All @@ -18,6 +23,8 @@ class IsosPageResult(NamedTuple):


class IsosClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> BoundIso
"""Get a specific ISO by its id
Expand Down
9 changes: 8 additions & 1 deletion hcloud/load_balancer_types/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from .domain import LoadBalancerType

if TYPE_CHECKING:
from .._client import Client


class BoundLoadBalancerType(BoundModelBase):
_client: LoadBalancerTypesClient

model = LoadBalancerType


Expand All @@ -17,6 +22,8 @@ class LoadBalancerTypesPageResult(NamedTuple):


class LoadBalancerTypesClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> load_balancer_types.client.BoundLoadBalancerType
"""Returns a specific Load Balancer Type.
Expand Down
9 changes: 8 additions & 1 deletion hcloud/load_balancers/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..actions.client import ActionsPageResult, BoundAction
from ..certificates.client import BoundCertificate
Expand All @@ -27,8 +27,13 @@
PublicNetwork,
)

if TYPE_CHECKING:
from .._client import Client


class BoundLoadBalancer(BoundModelBase):
_client: LoadBalancersClient

model = LoadBalancer

def __init__(self, client, data, complete=True):
Expand Down Expand Up @@ -318,6 +323,8 @@ class LoadBalancersPageResult(NamedTuple):


class LoadBalancersClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> BoundLoadBalancer
"""Get a specific Load Balancer
Expand Down
9 changes: 8 additions & 1 deletion hcloud/locations/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from .domain import Location

if TYPE_CHECKING:
from .._client import Client


class BoundLocation(BoundModelBase):
_client: LocationsClient

model = Location


Expand All @@ -17,6 +22,8 @@ class LocationsPageResult(NamedTuple):


class LocationsClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> locations.client.BoundLocation
"""Get a specific location by its ID.
Expand Down
9 changes: 8 additions & 1 deletion hcloud/networks/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..actions.client import ActionsPageResult, BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from .domain import Network, NetworkRoute, NetworkSubnet

if TYPE_CHECKING:
from .._client import Client


class BoundNetwork(BoundModelBase):
_client: NetworksClient

model = Network

def __init__(self, client, data, complete=True):
Expand Down Expand Up @@ -161,6 +166,8 @@ class NetworksPageResult(NamedTuple):


class NetworksClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> BoundNetwork
"""Get a specific network
Expand Down
9 changes: 8 additions & 1 deletion hcloud/placement_groups/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from .domain import CreatePlacementGroupResponse, PlacementGroup

if TYPE_CHECKING:
from .._client import Client


class BoundPlacementGroup(BoundModelBase):
_client: PlacementGroupsClient

model = PlacementGroup

def update(self, labels=None, name=None):
Expand Down Expand Up @@ -38,6 +43,8 @@ class PlacementGroupsPageResult(NamedTuple):


class PlacementGroupsClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> BoundPlacementGroup
"""Returns a specific Placement Group object
Expand Down
9 changes: 8 additions & 1 deletion hcloud/primary_ips/client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from __future__ import annotations

from typing import NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import Meta
from .domain import CreatePrimaryIPResponse, PrimaryIP

if TYPE_CHECKING:
from .._client import Client


class BoundPrimaryIP(BoundModelBase):
_client: PrimaryIPsClient

model = PrimaryIP

def __init__(self, client, data, complete=True):
Expand Down Expand Up @@ -93,6 +98,8 @@ class PrimaryIPsPageResult(NamedTuple):


class PrimaryIPsClient(ClientEntityBase, GetEntityByNameMixin):
_client: Client

def get_by_id(self, id):
# type: (int) -> BoundPrimaryIP
"""Returns a specific Primary IP object.
Expand Down
Loading

0 comments on commit 66f9163

Please sign in to comment.