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

Conversation

sourcery-ai[bot]
Copy link
Contributor

@sourcery-ai sourcery-ai bot commented Nov 11, 2023

Pull Request #266 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the 260-refactor-timestamp-and-timespan branch, then run:

git fetch origin sourcery/260-refactor-timestamp-and-timespan
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from cleder November 11, 2023 20:14

WatermelonAI Summary

AI Summary deactivated by sourcery-ai[bot]

GitHub PRs

No results found in Jira Tickets :(

No results found in Confluence Docs :(

No results found in Slack Threads :(

No results found in Notion Pages :(

No results found in Linear Tickets :(

No results found in Asana Tasks :(

fastkml is an open repo and Watermelon will serve it for free.
🍉🫶
Have you starred Watermelon?

@sourcery-ai sourcery-ai bot force-pushed the sourcery/260-refactor-timestamp-and-timespan branch from 5cba575 to 5a911ff Compare November 11, 2023 20:15
Copy link

what-the-diff bot commented Nov 11, 2023

PR Summary

  • Enhanced property retrieval in fastkml/kml.py
    This update ensures properties like style_url, author, snippet, address, phone_number and geometry will return actual data only when it exists. Otherwise, it will now just return None, handling the cases where the expected data is not available much better.

  • Streamlined get_style_by_url method in fastkml/kml.py
    The searching process for styles by their IDs has been made efficient using a generator expression which either returns the found style or yields None.

  • Optimized parsing and element creation in fastkml/times.py
    With the use of the walrus operator, parsing date strings and creating subelements based on exists of self.begin and self.end values are now more efficient, ensuring unnecessary computations are eliminated.

WatermelonAI Summary

AI Summary deactivated by sourcery-ai[bot]

GitHub PRs

No results found in Jira Tickets :(

No results found in Confluence Docs :(

No results found in Slack Threads :(

No results found in Notion Pages :(

No results found in Linear Tickets :(

No results found in Asana Tasks :(

fastkml is an open repo and Watermelon will serve it for free.
🍉🫶

Copy link

codecov bot commented Nov 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (046dd3f) 92.83% compared to head (1e44f7c) 92.88%.

Additional details and impacted files
@@                           Coverage Diff                           @@
##           260-refactor-timestamp-and-timespan     #267      +/-   ##
=======================================================================
+ Coverage                                92.83%   92.88%   +0.05%     
=======================================================================
  Files                                       34       34              
  Lines                                     4812     4795      -17     
=======================================================================
- Hits                                      4467     4454      -13     
+ Misses                                     345      341       -4     
Files Coverage Δ
fastkml/kml.py 77.09% <100.00%> (+0.07%) ⬆️
fastkml/times.py 98.05% <100.00%> (-0.06%) ⬇️
tests/base_test.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ghost
Copy link

ghost commented Nov 11, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@sourcery-ai sourcery-ai bot force-pushed the sourcery/260-refactor-timestamp-and-timespan branch from 5a911ff to 1e44f7c Compare November 11, 2023 20:22
@@ -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.

WatermelonAI Summary

AI Summary deactivated by sourcery-ai[bot]

GitHub PRs

No results found in Jira Tickets :(

No results found in Confluence Docs :(

No results found in Slack Threads :(

No results found in Notion Pages :(

No results found in Linear Tickets :(

No results found in Asana Tasks :(

fastkml is an open repo and Watermelon will serve it for free.
🍉🫶

if isinstance(self._style_url, StyleUrl):
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:

Comment on lines -261 to +259
if self._atom_author:
return self._atom_author.name
return None
return self._atom_author.name if self._atom_author 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.author refactored with the following changes:

Comment on lines -299 to +295
text = self._snippet.get("text")
if text:
if text := self._snippet.get("text"):
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:

Comment on lines -338 to +333
if self._address:
return self._address
return None
return self._address if self._address 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.address refactored with the following changes:

Comment on lines -353 to +346
if self._phone_number:
return self._phone_number
return None
return self._phone_number if self._phone_number 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.phone_number refactored with the following changes:

Comment on lines -1650 to +1641
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)
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)

Comment on lines -1720 to +1708
if self._geometry is not None:
return self._geometry.geometry
return None
return self._geometry.geometry if self._geometry is not None 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 Placemark.geometry refactored with the following changes:

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:

Comment on lines -229 to +235
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):
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:

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]

Base automatically changed from 260-refactor-timestamp-and-timespan to develop November 11, 2023 20:25
@sourcery-ai sourcery-ai bot closed this Nov 11, 2023
@sourcery-ai sourcery-ai bot deleted the sourcery/260-refactor-timestamp-and-timespan branch November 11, 2023 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants