Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Oct 16, 2023
1 parent cb63d48 commit 856bb3a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
4 changes: 1 addition & 3 deletions fastkml/kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,9 +1681,7 @@ def __init__(

@property
def geometry(self) -> Optional[AnyGeometryType]:
if self._geometry is not None:
return self._geometry.geometry
return None
return self._geometry.geometry if self._geometry is not None else None

def from_element(self, element: Element, strict=False) -> None:
super().from_element(element)
Expand Down
10 changes: 3 additions & 7 deletions fastkml/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ def strtobool(val: str) -> int:
val = val.lower()
if val == "false":
return 0
if val == "true":
return 1
return int(float(val))
return 1 if val == "true" else int(float(val))

super().from_element(element)
fill = element.find(f"{self.ns}fill")
Expand Down Expand Up @@ -628,7 +626,7 @@ def from_element(self, element: Element) -> None:
key = pair.find(f"{self.ns}key")
style = pair.find(f"{self.ns}Style")
style_url = pair.find(f"{self.ns}styleUrl")
if key is None:
if key is None or key.text not in ["highlight", "normal"]:
raise ValueError
elif key.text == "highlight":
if style is not None:
Expand All @@ -640,7 +638,7 @@ def from_element(self, element: Element) -> None:
else:
raise ValueError
self.highlight = highlight
elif key.text == "normal":
else:
if style is not None:
normal = Style(self.ns)
normal.from_element(style)
Expand All @@ -650,8 +648,6 @@ def from_element(self, element: Element) -> None:
else:
raise ValueError
self.normal = normal
else:
raise ValueError

def etree_element(
self,
Expand Down
5 changes: 1 addition & 4 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ class Test(base._BaseObject):

def test_base_from_element_raises(self) -> None:
be = base._BaseObject()
element = cast(
types.Element,
config.etree.Element(config.KMLNS + "Base"), # type: ignore[attr-defined]
)
element = cast(types.Element, config.etree.Element(f"{config.KMLNS}Base"))

with pytest.raises(TypeError):
be.from_element(element=element)
Expand Down

0 comments on commit 856bb3a

Please sign in to comment.