Skip to content

Commit

Permalink
update type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Nov 23, 2023
1 parent 4c29a81 commit 0cf42fa
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions fastkml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import List
from typing import Optional
from typing import Union
from typing import cast

from fastkml import atom
from fastkml import config
Expand Down Expand Up @@ -117,7 +118,7 @@ class _Feature(TimeMixin, _BaseObject):
description: Optional[str]
# User-supplied content that appears in the description balloon.

_style_url: Optional[Union[Style, StyleMap]]
_style_url: Optional[StyleUrl]
# URL of a <Style> or <StyleMap> defined in a Document.
# If the style is in the same file, use a # reference.
# If the style is defined in an external file, use a full URL
Expand Down Expand Up @@ -172,15 +173,15 @@ def __init__(
description: Optional[str] = None,
view: Optional[Union[Camera, LookAt]] = None,
times: Optional[Union[TimeSpan, TimeStamp]] = None,
style_url: Optional[str] = None,
style_url: Optional[StyleUrl] = None,
styles: Optional[List[Style]] = None,
region: Optional[Region] = None,
extended_data: Optional[ExtendedData] = None,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces, id=id, target_id=target_id)
self.name = name
self.description = description
self.style_url = style_url
self._style_url = style_url
self._styles = []
self._view = view
self.visibility = visibility
Expand Down Expand Up @@ -229,7 +230,7 @@ def view(self, camera: Optional[Union[Camera, LookAt]]) -> None:
self._view = camera

@property
def link(self) -> atom.Link:
def link(self) -> Optional[atom.Link]:
return self._atom_link

@link.setter
Expand Down Expand Up @@ -338,10 +339,10 @@ def from_element(self, element: Element, strict: bool = False) -> None:
self.description = description.text
visibility = element.find(f"{self.ns}visibility")
if visibility is not None and visibility.text:
self.visibility = 1 if visibility.text in ["1", "true"] else 0
self.visibility = True if visibility.text in ["1", "true"] else False
isopen = element.find(f"{self.ns}open")
if isopen is not None:
self.isopen = 1 if isopen.text in ["1", "true"] else 0
self.isopen = True if isopen.text in ["1", "true"] else False
styles = element.findall(f"{self.ns}Style")
for style in styles:
s = Style.class_from_element(
Expand All @@ -350,7 +351,7 @@ def from_element(self, element: Element, strict: bool = False) -> None:
element=style,
strict=strict,
)
self.append_style(s)
self.append_style(cast(Style, s))
styles = element.findall(f"{self.ns}StyleMap")
for style in styles:
s = StyleMap.class_from_element(
Expand All @@ -359,22 +360,25 @@ def from_element(self, element: Element, strict: bool = False) -> None:
element=style,
strict=strict,
)
self.append_style(s)
self.append_style(cast(StyleMap, s))
style_url = element.find(f"{self.ns}styleUrl")
if style_url is not None:
self._style_url = StyleUrl.class_from_element(
ns=self.ns,
name_spaces=self.name_spaces,
element=style_url,
strict=strict,
self._style_url = cast(
StyleUrl,
StyleUrl.class_from_element(
ns=self.ns,
name_spaces=self.name_spaces,
element=style_url,
strict=strict,
),
)
snippet = element.find(f"{self.ns}Snippet")
if snippet is not None:
max_lines = snippet.get("maxLines")
if max_lines is not None:
self.snippet = Snippet(text=snippet.text, max_lines=int(max_lines))
else:
self.snippet = Snippet(text=snippet.text)
self.snippet = Snippet(text=snippet.text) # type: ignore[unreachable]
timespan = element.find(f"{self.ns}TimeSpan")
if timespan is not None:
self._timespan = TimeSpan.class_from_element(
Expand Down Expand Up @@ -464,7 +468,7 @@ def __init__(
description: Optional[str] = None,
view: Optional[Union[Camera, LookAt]] = None,
times: Optional[Union[TimeSpan, TimeStamp]] = None,
style_url: Optional[str] = None,
style_url: Optional[StyleUrl] = None,
styles: Optional[List[Style]] = None,
region: Optional[Region] = None,
extended_data: Optional[ExtendedData] = None,
Expand Down Expand Up @@ -500,7 +504,7 @@ def geometry(self) -> Optional[AnyGeometryType]:
return self._geometry.geometry
return None

def from_element(self, element: Element, strict=False) -> None:
def from_element(self, element: Element, strict: bool = False) -> None:
super().from_element(element)
point = element.find(f"{self.ns}Point")
if point is not None:
Expand Down Expand Up @@ -637,7 +641,7 @@ def __init__(
description: Optional[str] = None,
view: Optional[Union[Camera, LookAt]] = None,
times: Optional[Union[TimeSpan, TimeStamp]] = None,
style_url: Optional[str] = None,
style_url: Optional[StyleUrl] = None,
styles: Optional[List[Style]] = None,
region: Optional[Region] = None,
extended_data: Optional[ExtendedData] = None,
Expand Down Expand Up @@ -671,8 +675,12 @@ def __init__(
self.fly_to_view = fly_to_view
self.link = link

def etree_element(self):
element = super().etree_element()
def etree_element(
self,
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> Element:
element = super().etree_element(precision=precision, verbosity=verbosity)
if self.refresh_visibility is not None:
refresh_visibility = config.etree.SubElement( # type: ignore[attr-defined]
element,
Expand All @@ -690,7 +698,7 @@ def etree_element(self):
element.append(self.link.etree_element())
return element

def from_element(self, element, strict=False):
def from_element(self, element: Element, strict=False) -> None:
super(_Feature, self).from_element(element)

visibility = element.find(f"{self.ns}refreshVisibility")
Expand Down

0 comments on commit 0cf42fa

Please sign in to comment.