mypy: Address issues with openstack.clustering
This one is cool. We use overload to allow the value of 'Resource.find' and 'Proxy._find' to vary depending on whether 'ignore_missing' is True or False. Change-Id: I386e10774dfb6ec9db80cbda9757446a2b5e4e57 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
b6cc1d817d
commit
4c1ced6ae2
|
@ -55,7 +55,6 @@ repos:
|
|||
| openstack/tests/fixtures.py
|
||||
| openstack/accelerator/.*
|
||||
| openstack/cloud/.*
|
||||
| openstack/clustering/.*
|
||||
| openstack/container_infrastructure_management/.*
|
||||
| openstack/database/.*
|
||||
| openstack/dns/.*
|
||||
|
|
|
@ -477,11 +477,43 @@ class Proxy(adapter.Adapter):
|
|||
value = resource.Resource._get_id(parent)
|
||||
return value
|
||||
|
||||
@ty.overload
|
||||
def _find(
|
||||
self,
|
||||
resource_type: ty.Type[ResourceType],
|
||||
name_or_id,
|
||||
ignore_missing=True,
|
||||
name_or_id: str,
|
||||
ignore_missing: ty.Literal[True] = True,
|
||||
**attrs,
|
||||
) -> ty.Optional[ResourceType]:
|
||||
...
|
||||
|
||||
@ty.overload
|
||||
def _find(
|
||||
self,
|
||||
resource_type: ty.Type[ResourceType],
|
||||
name_or_id: str,
|
||||
ignore_missing: ty.Literal[False],
|
||||
**attrs,
|
||||
) -> ResourceType:
|
||||
...
|
||||
|
||||
# excuse the duplication here: it's mypy's fault
|
||||
# https://github.com/python/mypy/issues/14764
|
||||
@ty.overload
|
||||
def _find(
|
||||
self,
|
||||
resource_type: ty.Type[ResourceType],
|
||||
name_or_id: str,
|
||||
ignore_missing: bool,
|
||||
**attrs,
|
||||
) -> ty.Optional[ResourceType]:
|
||||
...
|
||||
|
||||
def _find(
|
||||
self,
|
||||
resource_type: ty.Type[ResourceType],
|
||||
name_or_id: str,
|
||||
ignore_missing: bool = True,
|
||||
**attrs,
|
||||
) -> ty.Optional[ResourceType]:
|
||||
"""Find a resource
|
||||
|
|
|
@ -2248,16 +2248,63 @@ class Resource(dict):
|
|||
|
||||
return the_result
|
||||
|
||||
@ty.overload
|
||||
@classmethod
|
||||
def find(
|
||||
cls,
|
||||
session,
|
||||
name_or_id,
|
||||
ignore_missing=True,
|
||||
list_base_path=None,
|
||||
name_or_id: str,
|
||||
ignore_missing: ty.Literal[True] = True,
|
||||
list_base_path: ty.Optional[str] = None,
|
||||
*,
|
||||
microversion=None,
|
||||
all_projects=None,
|
||||
microversion: ty.Optional[str] = None,
|
||||
all_projects: ty.Optional[bool] = None,
|
||||
**params,
|
||||
) -> ty.Optional['Resource']:
|
||||
...
|
||||
|
||||
@ty.overload
|
||||
@classmethod
|
||||
def find(
|
||||
cls,
|
||||
session,
|
||||
name_or_id: str,
|
||||
ignore_missing: ty.Literal[False],
|
||||
list_base_path: ty.Optional[str] = None,
|
||||
*,
|
||||
microversion: ty.Optional[str] = None,
|
||||
all_projects: ty.Optional[bool] = None,
|
||||
**params,
|
||||
) -> 'Resource':
|
||||
...
|
||||
|
||||
# excuse the duplication here: it's mypy's fault
|
||||
# https://github.com/python/mypy/issues/14764
|
||||
@ty.overload
|
||||
@classmethod
|
||||
def find(
|
||||
cls,
|
||||
session,
|
||||
name_or_id: str,
|
||||
ignore_missing: bool,
|
||||
list_base_path: ty.Optional[str] = None,
|
||||
*,
|
||||
microversion: ty.Optional[str] = None,
|
||||
all_projects: ty.Optional[bool] = None,
|
||||
**params,
|
||||
):
|
||||
...
|
||||
|
||||
@classmethod
|
||||
def find(
|
||||
cls,
|
||||
session,
|
||||
name_or_id: str,
|
||||
ignore_missing: bool = True,
|
||||
list_base_path: ty.Optional[str] = None,
|
||||
*,
|
||||
microversion: ty.Optional[str] = None,
|
||||
all_projects: ty.Optional[bool] = None,
|
||||
**params,
|
||||
):
|
||||
"""Find a resource by its name or id.
|
||||
|
|
Loading…
Reference in New Issue