Skip to content

Commit

Permalink
refactor: add from __future__ import annotations imports (#249)
Browse files Browse the repository at this point in the history
* chore: make isort import future annotations

* chore: add from __future__ import annotations imports
  • Loading branch information
jooola committed Jul 20, 2023
1 parent 91b7285 commit c920c34
Show file tree
Hide file tree
Showing 103 changed files with 212 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import sys
from datetime import datetime
Expand Down
2 changes: 2 additions & 0 deletions examples/create_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from hcloud import Client
from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType
Expand Down
2 changes: 2 additions & 0 deletions examples/list_servers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from hcloud import Client

client = Client(
Expand Down
2 changes: 2 additions & 0 deletions examples/usage_oop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from hcloud import Client
from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType
Expand Down
2 changes: 2 additions & 0 deletions examples/usage_procedurale.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from hcloud import Client
from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType
Expand Down
2 changes: 2 additions & 0 deletions hcloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from __future__ import annotations

from ._client import Client # noqa
from ._exceptions import APIException, HCloudException # noqa
2 changes: 2 additions & 0 deletions hcloud/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from __future__ import annotations

VERSION = "1.26.0" # x-release-please-version
9 changes: 5 additions & 4 deletions hcloud/_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import time
from typing import Optional, Union

import requests

Expand Down Expand Up @@ -35,8 +36,8 @@ def __init__(
self,
token: str,
api_endpoint: str = "https://api.hetzner.cloud/v1",
application_name: Optional[str] = None,
application_version: Optional[str] = None,
application_name: str | None = None,
application_version: str | None = None,
poll_interval: int = 1,
):
"""Create an new Client instance
Expand Down Expand Up @@ -186,7 +187,7 @@ def request(
url: str,
tries: int = 1,
**kwargs,
) -> Union[bytes, dict]:
) -> bytes | dict:
"""Perform a request to the Hetzner Cloud API, wrapper around requests.request
:param method: HTTP Method to perform the Request
Expand Down
3 changes: 3 additions & 0 deletions hcloud/_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


class HCloudException(Exception):
"""There was an error while using the hcloud library"""

Expand Down
2 changes: 2 additions & 0 deletions hcloud/actions/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import time

from ..core.client import BoundModelBase, ClientEntityBase
Expand Down
2 changes: 2 additions & 0 deletions hcloud/actions/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from .._exceptions import HCloudException
Expand Down
2 changes: 2 additions & 0 deletions hcloud/certificates/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import add_meta_to_result
Expand Down
2 changes: 2 additions & 0 deletions hcloud/certificates/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain, DomainIdentityMixin
Expand Down
4 changes: 3 additions & 1 deletion hcloud/core/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from .domain import add_meta_to_result


Expand Down Expand Up @@ -34,7 +36,7 @@ def _get_all(
list_function, # type: function
results_list_attribute_name, # type: str
*args,
**kwargs
**kwargs,
):
# type (...) -> List[BoundModelBase]

Expand Down
2 changes: 2 additions & 0 deletions hcloud/core/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from collections import namedtuple


Expand Down
2 changes: 2 additions & 0 deletions hcloud/datacenters/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..locations.client import BoundLocation
from ..server_types.client import BoundServerType
Expand Down
2 changes: 2 additions & 0 deletions hcloud/datacenters/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..core.domain import BaseDomain, DomainIdentityMixin


Expand Down
2 changes: 2 additions & 0 deletions hcloud/deprecation/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain
Expand Down
2 changes: 2 additions & 0 deletions hcloud/firewalls/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import add_meta_to_result
Expand Down
2 changes: 2 additions & 0 deletions hcloud/firewalls/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain
Expand Down
2 changes: 2 additions & 0 deletions hcloud/floating_ips/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import add_meta_to_result
Expand Down
2 changes: 2 additions & 0 deletions hcloud/floating_ips/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain
Expand Down
2 changes: 2 additions & 0 deletions hcloud/hcloud.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import warnings

warnings.warn(
Expand Down
7 changes: 4 additions & 3 deletions hcloud/helpers/labels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
from typing import Dict


class LabelValidator:
Expand All @@ -11,7 +12,7 @@ class LabelValidator:
)

@staticmethod
def validate(labels: Dict[str, str]) -> bool:
def validate(labels: dict[str, str]) -> bool:
"""Validates Labels. If you want to know which key/value pair of the dict is not correctly formatted
use :func:`~hcloud.helpers.labels.validate_verbose`.
Expand All @@ -25,7 +26,7 @@ def validate(labels: Dict[str, str]) -> bool:
return True

@staticmethod
def validate_verbose(labels: Dict[str, str]) -> (bool, str):
def validate_verbose(labels: dict[str, str]) -> tuple(bool, str):
"""Validates Labels and returns the corresponding error message if something is wrong. Returns True, <empty string>
if everything is fine.
Expand Down
2 changes: 2 additions & 0 deletions hcloud/images/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import add_meta_to_result
Expand Down
2 changes: 2 additions & 0 deletions hcloud/images/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain, DomainIdentityMixin
Expand Down
2 changes: 2 additions & 0 deletions hcloud/isos/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from warnings import warn

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
Expand Down
2 changes: 2 additions & 0 deletions hcloud/isos/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain, DomainIdentityMixin
Expand Down
2 changes: 2 additions & 0 deletions hcloud/load_balancer_types/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

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

Expand Down
2 changes: 2 additions & 0 deletions hcloud/load_balancer_types/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..core.domain import BaseDomain, DomainIdentityMixin


Expand Down
2 changes: 2 additions & 0 deletions hcloud/load_balancers/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..certificates.client import BoundCertificate
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
Expand Down
2 changes: 2 additions & 0 deletions hcloud/load_balancers/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain
Expand Down
2 changes: 2 additions & 0 deletions hcloud/locations/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

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

Expand Down
2 changes: 2 additions & 0 deletions hcloud/locations/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..core.domain import BaseDomain, DomainIdentityMixin


Expand Down
2 changes: 2 additions & 0 deletions hcloud/networks/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import add_meta_to_result
Expand Down
2 changes: 2 additions & 0 deletions hcloud/networks/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain
Expand Down
2 changes: 2 additions & 0 deletions hcloud/placement_groups/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from .domain import CreatePlacementGroupResponse, PlacementGroup
Expand Down
2 changes: 2 additions & 0 deletions hcloud/placement_groups/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain
Expand Down
2 changes: 2 additions & 0 deletions hcloud/primary_ips/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from .domain import CreatePrimaryIPResponse, PrimaryIP
Expand Down
2 changes: 2 additions & 0 deletions hcloud/primary_ips/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain
Expand Down
2 changes: 2 additions & 0 deletions hcloud/server_types/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from .domain import ServerType

Expand Down
2 changes: 2 additions & 0 deletions hcloud/server_types/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..core.domain import BaseDomain, DomainIdentityMixin
from ..deprecation.domain import DeprecationInfo

Expand Down
2 changes: 2 additions & 0 deletions hcloud/servers/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import add_meta_to_result
Expand Down
2 changes: 2 additions & 0 deletions hcloud/servers/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain
Expand Down
2 changes: 2 additions & 0 deletions hcloud/ssh_keys/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from .domain import SSHKey

Expand Down
2 changes: 2 additions & 0 deletions hcloud/ssh_keys/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain, DomainIdentityMixin
Expand Down
2 changes: 2 additions & 0 deletions hcloud/volumes/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from ..actions.client import BoundAction
from ..core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from ..core.domain import add_meta_to_result
Expand Down
2 changes: 2 additions & 0 deletions hcloud/volumes/domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dateutil.parser import isoparse

from ..core.domain import BaseDomain, DomainIdentityMixin
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tool.isort]
profile = "black"
combine_as_imports = true
add_imports = ["from __future__ import annotations"]

[tool.coverage.run]
source = ["hcloud"]
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from setuptools import find_packages, setup

with open("README.rst") as readme_file:
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/actions/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions tests/unit/actions/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest import mock

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/actions/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime
from datetime import timezone

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/certificates/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions tests/unit/certificates/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest import mock

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/certificates/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime
from datetime import timezone

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest import mock

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/core/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest import mock

import pytest
Expand Down
Loading

0 comments on commit c920c34

Please sign in to comment.