Skip to content

Commit

Permalink
Use Generic type T in return types
Browse files Browse the repository at this point in the history
Modify the return type of the Metadata factory
methods (from_*) to use the Generic type T. This helps IDEs
understand the return type and give proper hints.

The static method from_bytes() has to become a class method
to get the needed Generic info.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
  • Loading branch information
sechkova committed Jul 29, 2021
1 parent 6aa5727 commit ba6c672
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, signed: T, signatures: "OrderedDict[str, Signature]"):
self.signatures = signatures

@classmethod
def from_dict(cls, metadata: Dict[str, Any]) -> "Metadata":
def from_dict(cls, metadata: Dict[str, Any]) -> "Metadata[T]":
"""Creates Metadata object from its dict representation.
Arguments:
Expand Down Expand Up @@ -133,7 +133,7 @@ def from_file(
filename: str,
deserializer: Optional[MetadataDeserializer] = None,
storage_backend: Optional[StorageBackendInterface] = None,
) -> "Metadata":
) -> "Metadata[T]":
"""Loads TUF metadata from file storage.
Arguments:
Expand All @@ -160,11 +160,12 @@ def from_file(
with storage_backend.get(filename) as file_obj:
return cls.from_bytes(file_obj.read(), deserializer)

@staticmethod
@classmethod
def from_bytes(
cls,
data: bytes,
deserializer: Optional[MetadataDeserializer] = None,
) -> "Metadata":
) -> "Metadata[T]":
"""Loads TUF metadata from raw data.
Arguments:
Expand Down

0 comments on commit ba6c672

Please sign in to comment.