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

Add or update type hints #82

Merged
merged 38 commits into from Mar 30, 2022
Merged

Add or update type hints #82

merged 38 commits into from Mar 30, 2022

Conversation

lymanepp
Copy link
Collaborator

mypy passes, but some of the type hints might needs to be adjusted.

Copy link
Owner

@MatthewFlamm MatthewFlamm left a comment

Choose a reason for hiding this comment

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

Looking good!

Please pull in changes from master branch so the typing CI runs here. Now that #79 is merged.

pynws/raw_data.py Outdated Show resolved Hide resolved
pynws/raw_data.py Outdated Show resolved Hide resolved
pynws/simple_nws.py Show resolved Hide resolved
pynws/simple_nws.py Outdated Show resolved Hide resolved
pynws/simple_nws.py Outdated Show resolved Hide resolved
@MatthewFlamm
Copy link
Owner

The use of return Types isn't consistent in this PR, but I'm not sure how important it is to indicate a None return. You can implement if you like

lymanepp and others added 2 commits March 27, 2022 08:46
Co-authored-by: MatthewFlamm <39341281+MatthewFlamm@users.noreply.github.com>
@lymanepp
Copy link
Collaborator Author

The use of return Types isn't consistent in this PR, but I'm not sure how important it is to indicate a None return. You can implement if you like

This is just a starting point. Please feel free to commit fixes directly to this PR.

@lymanepp
Copy link
Collaborator Author

Many methods have been annotated. There are some remaining, but I'm done with this for now. Feel free to continue or merge as-is if you approve.

pynws/nws.py Show resolved Hide resolved
pynws/nws.py Show resolved Hide resolved
@lymanepp lymanepp mentioned this pull request Mar 28, 2022
pynws/forecast.py Outdated Show resolved Hide resolved
Copy link
Owner

@MatthewFlamm MatthewFlamm left a comment

Choose a reason for hiding this comment

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

Hopefully the last round of comments.

pynws/nws.py Show resolved Hide resolved
@@ -87,48 +111,60 @@ async def get_detailed_forecast(self: Nws) -> DetailedForecast:
"""
if self.wfo is None:
await self.get_points()
if self.wfo is None or self.x is None or self.y is None:
Copy link
Owner

Choose a reason for hiding this comment

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

Either this should move into get_points, or it should be inside the prior if statement, which is expanded to check for self.x and self.y, or both.

Copy link
Collaborator Author

@lymanepp lymanepp Mar 30, 2022

Choose a reason for hiding this comment

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

Without those checks, mypy has the following complaints.

pynws\nws.py:117: error: Argument 1 to "raw_detailed_forecast" has incompatible type "Optional[str]"; expected "str"
pynws\nws.py:117: error: Argument 2 to "raw_detailed_forecast" has incompatible type "Optional[int]"; expected "int"
pynws\nws.py:117: error: Argument 3 to "raw_detailed_forecast" has incompatible type "Optional[int]"; expected "int"

I could use cast to remove the Optional in the arguments to raw_detailed_forecast instead if you prefer. That would look like this:

        if self.wfo is None:
            await self.get_points()
        raw_forecast = await raw_detailed_forecast(
            cast(str, self.wfo),
            cast(int, self.x),
            cast(int, self.y),
            self.session,
            self.userid,
        )
        return DetailedForecast(raw_forecast["properties"])

One more thing, get_points silently fails when retrieving from API fails.

        data = await raw_points(*self.latlon, self.session, self.userid)

        properties = data.get("properties")
        if properties:
            self.wfo = properties.get("cwa")
            self.x = properties.get("gridX")
            self.y = properties.get("gridY")
            self.forecast_zone = properties.get("forecastZone").split("/")[-1]
            self.county_zone = properties.get("county").split("/")[-1]
            self.fire_weather_zone = properties.get("fireWeatherZone").split("/")[-1]
        return properties

"""Return daily forecast from grid."""
if self.wfo is None:
await self.get_points()
if self.wfo is None or self.x is None or self.y is None:
Copy link
Owner

Choose a reason for hiding this comment

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

same as above

"""Return hourly forecast from grid."""
if self.wfo is None:
await self.get_points()
if self.wfo is None or self.x is None or self.y is None:
Copy link
Owner

Choose a reason for hiding this comment

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

same as above

"""Returns alerts dict for forecast zone."""
if self.forecast_zone is None:
await self.get_points()
if self.forecast_zone is None:
Copy link
Owner

Choose a reason for hiding this comment

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

should the zone checks also move inside self.get_points?

pynws/simple_nws.py Show resolved Hide resolved
@MatthewFlamm
Copy link
Owner

My only outstanding comments are the ones about checking self.x and similar outside the get_points method.

@MatthewFlamm MatthewFlamm merged commit fcc705b into MatthewFlamm:master Mar 30, 2022
@lymanepp lymanepp deleted the typing branch March 30, 2022 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants