From ddea42795d66a07a5e95865a908e09e014dc90f3 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Wed, 25 Sep 2024 17:34:35 -0400 Subject: [PATCH] Resolve circular imports and restore top-level imports --- linode_api4/objects/linode.py | 29 ++++++++++++----------------- linode_api4/objects/networking.py | 5 ++++- linode_api4/objects/nodebalancer.py | 10 +++------- linode_api4/objects/volume.py | 4 +++- linode_api4/objects/vpc.py | 6 +----- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/linode_api4/objects/linode.py b/linode_api4/objects/linode.py index 775def88a..12c75d85c 100644 --- a/linode_api4/objects/linode.py +++ b/linode_api4/objects/linode.py @@ -11,18 +11,19 @@ from linode_api4 import util from linode_api4.common import load_and_validate_keys from linode_api4.errors import UnexpectedResponseError -from linode_api4.objects import ( - Base, - DerivedBase, - Image, - JSONObject, - Property, - Region, -) -from linode_api4.objects.base import MappedObject +from linode_api4.objects.base import Base, MappedObject, Property +from linode_api4.objects.dbase import DerivedBase from linode_api4.objects.filtering import FilterableAttribute -from linode_api4.objects.networking import IPAddress, IPv6Range, VPCIPAddress -from linode_api4.objects.serializable import StrEnum +from linode_api4.objects.image import Image +from linode_api4.objects.networking import ( + Firewall, + IPAddress, + IPv6Range, + VPCIPAddress, +) +from linode_api4.objects.nodebalancer import NodeBalancer +from linode_api4.objects.region import Region +from linode_api4.objects.serializable import JSONObject, StrEnum from linode_api4.objects.vpc import VPC, VPCSubnet from linode_api4.paginated_list import PaginatedList @@ -1618,9 +1619,6 @@ def firewalls(self): :returns: A List of Firewalls of the Linode Instance. :rtype: List[Firewall] """ - from linode_api4.objects import ( # pylint: disable=import-outside-toplevel - Firewall, - ) result = self._client.get( "{}/firewalls".format(Instance.api_endpoint), model=self @@ -1640,9 +1638,6 @@ def nodebalancers(self): :returns: A List of Nodebalancers of the Linode Instance. :rtype: List[Nodebalancer] """ - from linode_api4.objects import ( # pylint: disable=import-outside-toplevel - NodeBalancer, - ) result = self._client.get( "{}/nodebalancers".format(Instance.api_endpoint), model=self diff --git a/linode_api4/objects/networking.py b/linode_api4/objects/networking.py index 9e19b2d92..c4fff1ac3 100644 --- a/linode_api4/objects/networking.py +++ b/linode_api4/objects/networking.py @@ -3,7 +3,10 @@ from linode_api4.common import Price, RegionPrice from linode_api4.errors import UnexpectedResponseError -from linode_api4.objects import Base, DerivedBase, JSONObject, Property, Region +from linode_api4.objects.base import Base, Property +from linode_api4.objects.dbase import DerivedBase +from linode_api4.objects.region import Region +from linode_api4.objects.serializable import JSONObject class IPv6Pool(Base): diff --git a/linode_api4/objects/nodebalancer.py b/linode_api4/objects/nodebalancer.py index 36d038bcb..d038b6998 100644 --- a/linode_api4/objects/nodebalancer.py +++ b/linode_api4/objects/nodebalancer.py @@ -3,14 +3,10 @@ from linode_api4.common import Price, RegionPrice from linode_api4.errors import UnexpectedResponseError -from linode_api4.objects import ( - Base, - DerivedBase, - MappedObject, - Property, - Region, -) +from linode_api4.objects.base import Base, MappedObject, Property +from linode_api4.objects.dbase import DerivedBase from linode_api4.objects.networking import Firewall, IPAddress +from linode_api4.objects.region import Region class NodeBalancerType(Base): diff --git a/linode_api4/objects/volume.py b/linode_api4/objects/volume.py index a79e3174c..6c8514f9f 100644 --- a/linode_api4/objects/volume.py +++ b/linode_api4/objects/volume.py @@ -1,6 +1,8 @@ from linode_api4.common import Price, RegionPrice from linode_api4.errors import UnexpectedResponseError -from linode_api4.objects import Base, Instance, Property, Region +from linode_api4.objects.base import Base, Property +from linode_api4.objects.linode import Instance, Region +from linode_api4.objects.region import Region class VolumeType(Base): diff --git a/linode_api4/objects/vpc.py b/linode_api4/objects/vpc.py index e4fe36c78..3c9a4aaba 100644 --- a/linode_api4/objects/vpc.py +++ b/linode_api4/objects/vpc.py @@ -3,6 +3,7 @@ from linode_api4.errors import UnexpectedResponseError from linode_api4.objects import Base, DerivedBase, Property, Region +from linode_api4.objects.networking import VPCIPAddress from linode_api4.objects.serializable import JSONObject from linode_api4.paginated_list import PaginatedList @@ -110,11 +111,6 @@ def ips(self) -> PaginatedList: :rtype: PaginatedList of VPCIPAddress """ - # need to avoid circular import - from linode_api4.objects import ( # pylint: disable=import-outside-toplevel - VPCIPAddress, - ) - return self._client._get_and_filter( VPCIPAddress, endpoint="/vpcs/{}/ips".format(self.id) )