Skip to content

Commit

Permalink
Fix typing in tagging py (#1371)
Browse files Browse the repository at this point in the history
Signed-off-by: Bala.FA <bala@minio.io>
  • Loading branch information
balamurugana committed Dec 11, 2023
1 parent 99f8c41 commit d624459
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions minio/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

from __future__ import absolute_import, annotations

from typing import Type, TypeVar
from typing import Type, TypeVar, cast
from xml.etree import ElementTree as ET

from .commonconfig import Tags
from .xml import Element, SubElement, find

K = TypeVar("K", bound="Tagging")
A = TypeVar("A", bound="Tagging")


class Tagging:
Expand All @@ -39,18 +39,16 @@ def tags(self) -> Tags | None:
return self._tags

@classmethod
def fromxml(cls: Type[K], element: ET.Element) -> K:
def fromxml(cls: Type[A], element: ET.Element) -> A:
"""Create new object with values from XML element."""
tag_set = find(element, "TagSet")
if tag_set is None:
raise ValueError("missing XML tag 'TagSet'")
element = cast(ET.Element, find(element, "TagSet", True))
tags = (
None if find(tag_set, "Tag") is None
else Tags.fromxml(tag_set)
None if find(element, "Tag") is None
else Tags.fromxml(element)
)
return cls(tags)

def toxml(self, element: ET.Element) -> ET.Element:
def toxml(self, element: ET.Element | None) -> ET.Element:
"""Convert to XML."""
element = Element("Tagging")
if self._tags:
Expand Down

0 comments on commit d624459

Please sign in to comment.