docs: added docstrings to properties module

This commit is contained in:
Darren Eberly
2020-06-01 21:55:11 -04:00
parent 250ebc2d7d
commit 484e1ac69c

View File

@@ -1,11 +1,22 @@
"""Properties Module
This module casts raw properties from Tiled maps into a dictionary of
properly typed Properties.
"""
from pathlib import Path
from typing import Dict, List, NamedTuple, Optional, Union
from typing import Dict, List, Union
from typing_extensions import TypedDict
from .common_types import Color
Property = Union[float, Path, str, bool, Color]
Properties = Dict[str, Property]
RawProperty = Union[float, str, bool]
@@ -17,20 +28,26 @@ class RawProperties(TypedDict):
value: RawProperty
Properties = Dict[str, Property]
def cast(raw_properties: List[RawProperties]) -> Dict[str, Property]:
""" Cast raw properties into a dictionary of completed properly typed properties.
Args:
raw_properties: The list of raw properties to cast.
Returns:
Dict[str, Property]: The completed dictionary of casted properties.
"""
def cast(raw: List[RawProperties]) -> Dict[str, Property]:
final: Properties = {}
value: Property
for prop in raw:
if prop["type"] == "file":
value = Path(str(prop["value"]))
elif prop["type"] == "color":
value = Color(str(prop["value"]))
for property_ in raw_properties:
if property_["type"] == "file":
value = Path(str(property_["value"]))
elif property_["type"] == "color":
value = Color(str(property_["value"]))
else:
value = prop["value"]
final[str(prop["name"])] = value
value = property_["value"]
final[str(property_["name"])] = value
return final