Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TimeStamp and TimeSpan class to use class_from_element method (Sourcery refactored) #267

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions fastkml/kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ def style_url(self) -> Optional[str]:
Returns the url only, not a full StyleUrl object.
if you need the full StyleUrl object use _style_url.
"""
if isinstance(self._style_url, StyleUrl):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present.

return self._style_url.url
return None
return self._style_url.url if isinstance(self._style_url, StyleUrl) else None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _Feature.style_url refactored with the following changes:


@style_url.setter
def style_url(self, styleurl: Union[str, StyleUrl, None]) -> None:
Expand Down Expand Up @@ -258,9 +256,7 @@ def link(self, url) -> None:

@property
def author(self) -> None:
if self._atom_author:
return self._atom_author.name
return None
return self._atom_author.name if self._atom_author else None
Comment on lines -261 to +259
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _Feature.author refactored with the following changes:


@author.setter
def author(self, name) -> None:
Expand Down Expand Up @@ -296,8 +292,7 @@ def snippet(self) -> Optional[Dict[str, Any]]:
if not self._snippet:
return None
if isinstance(self._snippet, dict):
text = self._snippet.get("text")
if text:
if text := self._snippet.get("text"):
Comment on lines -299 to +295
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _Feature.snippet refactored with the following changes:

assert isinstance(text, str)
max_lines = self._snippet.get("maxLines", None)
if max_lines is None:
Expand Down Expand Up @@ -335,9 +330,7 @@ def snippet(self, snip=None) -> None:

@property
def address(self) -> None:
if self._address:
return self._address
return None
return self._address if self._address else None
Comment on lines -338 to +333
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _Feature.address refactored with the following changes:


@address.setter
def address(self, address) -> None:
Expand All @@ -350,9 +343,7 @@ def address(self, address) -> None:

@property
def phone_number(self) -> None:
if self._phone_number:
return self._phone_number
return None
return self._phone_number if self._phone_number else None
Comment on lines -353 to +346
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _Feature.phone_number refactored with the following changes:


@phone_number.setter
def phone_number(self, phone_number) -> None:
Expand Down Expand Up @@ -1647,10 +1638,7 @@ def etree_element(

def get_style_by_url(self, style_url: str) -> Union[Style, StyleMap]:
id = urlparse.urlparse(style_url).fragment
for style in self.styles():
if style.id == id:
return style
return None
return next((style for style in self.styles() if style.id == id), None)
Comment on lines -1650 to +1641
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Document.get_style_by_url refactored with the following changes:

  • Use the built-in function next instead of a for-loop (use-next)



class Folder(_Container):
Expand Down Expand Up @@ -1717,9 +1705,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
Comment on lines -1720 to +1708
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Placemark.geometry refactored with the following changes:


def from_element(self, element: Element, strict=False) -> None:
super().from_element(element)
Expand Down
9 changes: 3 additions & 6 deletions fastkml/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def parse(cls, datestr: str) -> Optional["KmlDateTime"]:
"""Parse a KML DateTime string into a KmlDateTime object."""
resolution = None
dt = None
year_month_day_match = year_month_day.match(datestr)
if year_month_day_match:
if year_month_day_match := year_month_day.match(datestr):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function KmlDateTime.parse refactored with the following changes:

year = int(year_month_day_match.group("year"))
month = int(year_month_day_match.group("month") or 1)
day = int(year_month_day_match.group("day") or 1)
Expand Down Expand Up @@ -226,16 +225,14 @@ def etree_element(
) -> Element:
element = super().etree_element(precision=precision, verbosity=verbosity)
if self.begin is not None:
text = str(self.begin)
if text:
if text := str(self.begin):
begin = config.etree.SubElement( # type: ignore[attr-defined]
element,
f"{self.ns}begin",
)
begin.text = text
if self.end is not None:
text = str(self.end)
if text:
if text := str(self.end):
Comment on lines -229 to +235
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TimeSpan.etree_element refactored with the following changes:

end = config.etree.SubElement( # type: ignore[attr-defined]
element,
f"{self.ns}end",
Expand Down
5 changes: 1 addition & 4 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,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"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestStdLibrary.test_base_from_element_raises refactored with the following changes:

This removes the following comments ( why? ):

# type: ignore[attr-defined]


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