Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[WIPTEST] Types fixes #10298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cfme/infrastructure/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from cfme.exceptions import displayed_not_implemented
from cfme.exceptions import ItemNotFound
from cfme.exceptions import MenuItemNotFound
from cfme.infrastructure.provider import InfraProvider
from cfme.modeling.base import BaseCollection
from cfme.modeling.base import BaseEntity
from cfme.optimize.utilization import DatastoreUtilizationTrendsView
Expand Down Expand Up @@ -216,7 +217,7 @@ class Datastore(Pretty, BaseEntity, Taggable, CustomButtonEventsMixin):
pretty_attrs = ['name', 'provider_key']
_param_name = ParamClassName('name')
name = attr.ib()
provider = attr.ib()
provider: InfraProvider = attr.ib()
type = attr.ib(default=None)

def __attrs_post_init__(self):
Expand Down Expand Up @@ -358,7 +359,7 @@ def wait_candu_data_available(self, timeout=900):


@attr.s
class DatastoreCollection(BaseCollection):
class DatastoreCollection(BaseCollection[Datastore]):
"""Collection class for :py:class:`cfme.infrastructure.datastore.Datastore`"""
ENTITY = Datastore

Expand Down Expand Up @@ -421,7 +422,6 @@ def run_smartstate_analysis(self, *datastores):
datastores = list(datastores)

checked_datastores = list()

view = navigate_to(self, 'All')

for datastore in datastores:
Expand Down Expand Up @@ -469,6 +469,7 @@ class DetailsFromProvider(CFMENavigateStep):
VIEW = DatastoreDetailsView

def prerequisite(self):
# TODO use DatastoresOfProvider
prov_view = navigate_to(self.obj.provider, 'Details')
prov_view.entities.summary('Relationships').click_at('Datastores')
return self.obj.create_view(DatastoresView)
Expand Down
21 changes: 13 additions & 8 deletions cfme/modeling/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from collections.abc import Callable
from typing import Generic
from typing import Type
from typing import TypeVar

import attr
from cached_property import cached_property
Expand Down Expand Up @@ -87,8 +90,11 @@ def __getattr__(self, name):
return self._collection_cache[name]


T = TypeVar('T')


@attr.s
class BaseCollection(NavigatableMixin):
class BaseCollection(NavigatableMixin, Generic[T]):
"""Class for helping create consistent Collections

The BaseCollection class is responsible for ensuring two things:
Expand All @@ -99,8 +105,7 @@ class BaseCollection(NavigatableMixin):
This class works in tandem with the entrypoint loader which ensures that the correct
argument names have been used.
"""

ENTITY = None
ENTITY: Type[T]

parent = attr.ib(repr=False)
filters = attr.ib(default=attr.Factory(dict))
Expand All @@ -120,13 +125,13 @@ def for_appliance(cls, appliance, *k, **kw):
def for_entity(cls, obj, *k, **kw):
return cls(obj, *k, **kw)

def instantiate(self, *args, **kwargs) -> T:
return self.ENTITY.from_collection(self, *args, **kwargs)

@classmethod
def for_entity_with_filter(cls, obj, filt, *k, **kw):
return cls.for_entity(obj, *k, **kw).filter(filt)

def instantiate(self, *args, **kwargs):
return self.ENTITY.from_collection(self, *args, **kwargs)

def filter(self, filter):
filters = self.filters.copy()
filters.update(filter)
Expand All @@ -146,7 +151,7 @@ class BaseEntity(NavigatableMixin):
argument names have been used.
"""

parent = attr.ib(repr=False) # This is the collection or not
parent: BaseCollection = attr.ib(repr=False) # This is the collection or not

# TODO This needs removing as we need proper __eq__ on objects, but it is part of a
# much larger discussion
Expand All @@ -157,7 +162,7 @@ def appliance(self):
return self.parent.appliance

@classmethod
def from_collection(cls, collection, *k, **kw):
def from_collection(cls, collection: BaseCollection, *k, **kw):
return cls(collection, *k, **kw)

@cached_property
Expand Down