typing: Annotate openstack.format
Change-Id: I38184277951e0f8decd16d98d9f3f24a7d878b63 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -10,17 +10,21 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
class Formatter:
|
||||
_T = ty.TypeVar('_T')
|
||||
|
||||
|
||||
class Formatter(ty.Generic[_T]):
|
||||
@classmethod
|
||||
def deserialize(cls, value):
|
||||
def deserialize(cls, value: ty.Any) -> _T:
|
||||
"""Return a formatted object representing the value"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class BoolStr(Formatter):
|
||||
class BoolStr(Formatter[bool]):
|
||||
@classmethod
|
||||
def deserialize(cls, value):
|
||||
def deserialize(cls, value: ty.Any) -> bool:
|
||||
"""Convert a boolean string to a boolean"""
|
||||
expr = str(value).lower()
|
||||
if "true" == expr:
|
||||
|
||||
@@ -15,9 +15,9 @@ from urllib import parse
|
||||
from openstack import format
|
||||
|
||||
|
||||
class HREFToUUID(format.Formatter):
|
||||
class HREFToUUID(format.Formatter[str]):
|
||||
@classmethod
|
||||
def deserialize(cls, value):
|
||||
def deserialize(cls, value: str) -> str:
|
||||
"""Convert a HREF to the UUID portion"""
|
||||
parts = parse.urlsplit(value)
|
||||
|
||||
|
||||
@@ -28,6 +28,16 @@ exclude = '''
|
||||
)
|
||||
'''
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = ["openstack.format"]
|
||||
warn_return_any = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_any_generics = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_defs = true
|
||||
no_implicit_reexport = true
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = ["openstack.tests.unit.*"]
|
||||
ignore_errors = true
|
||||
|
||||
Reference in New Issue
Block a user