-
Notifications
You must be signed in to change notification settings - Fork 17
Implement zmanim calculations #2
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
Conversation
|
Just a minor note on typehints. You're using |
def elevation(self, elevation):
if elevation is None:
elevation = 0
if elevation < 0:
raise ValueError("elevation cannot be negative")
self.__elevation = elevationYou can simplify that first condition by taking advantage of def elevation(self, elevation):
if elevation < 0:
raise ValueError("elevation cannot be negative")
self.__elevation = elevation or 0 |
|
@yeedle Re: #2 (comment) |
|
@yeedle Re: #2 (comment) |
|
re type checking: I was referring to the typehints/type annotations, but for |
|
re |
|
With regards to the double leading underscores that are used: From PEP-8 In general, the convention for private methods would be a single leading underscore. Unless this is truly a case where there's a specific need to avoid name clashes with subclasses. |
zmanim/astronomical_calendar.py
Outdated
| noon_hour = (self.temporal_hour(sunrise, sunset) / self.HOUR_MILLIS) * 6.0 | ||
| return sunrise + timedelta(noon_hour / 24.0) | ||
|
|
||
| def __date_time_from_time_of_day(self, time_of_day: float, mode: str) -> datetime: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns an Optional[datetime], based on line 80
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, since it appears that time_of_day accepts None, the arg type should be Optional[float] as well.
zmanim/astronomical_calendar.py
Outdated
| def utc_sea_level_sunset(self, zenith: float) -> float: | ||
| return self.astronomical_calculator.utc_sunset(self.__adjusted_date(), self.geo_location, zenith, adjust_for_elevation=False) | ||
|
|
||
| def temporal_hour(self, sunrise: datetime = __sentinel, sunset: datetime = __sentinel) -> float: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns an Optional[float], based on line 65
zmanim/astronomical_calendar.py
Outdated
| noon_hour = (self.temporal_hour(sunrise, sunset) / self.HOUR_MILLIS) * 6.0 | ||
| return sunrise + timedelta(noon_hour / 24.0) | ||
|
|
||
| def __date_time_from_time_of_day(self, time_of_day: float, mode: str) -> datetime: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, since it appears that time_of_day accepts None, the arg type should be Optional[float] as well.
zmanim/astronomical_calendar.py
Outdated
|
|
||
| __sentinel=object() | ||
|
|
||
| def __init__(self, geo_location: GeoLocation = None, date: date = None, calculator: AstronomicalCalculations = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the arguments are being assigned None default values, the arg type for those is technically Optional[<type>].
This could be left as is, since mypy is smart enough to deduce the type is Optional here, but it's good to know that according to PEP 484, Type checkers should move towards requiring the optional type to be made explicit.
https://www.python.org/dev/peps/pep-0484/#union-types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be getting nitpicky on the types -- mypy can be configured to be more or less strict, so really just depends.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think being careful about types is being nit-picky. Modules with good typehints are tremendously valueable, especially when you use them with a good IDE like PyCharm, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using PyCharm and it indicates that it sees the arg type as Optional, return types as well. I'll update shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To enforce the explicit optional, you can run mypy with the --no-implicit-optional flag.
…in favor of float
|
Imports should be ordered by builtins, third party then local https://www.python.org/dev/peps/pep-0008/#imports |
|
@leviadler re: #2 (comment) thanks, nifty feature! |
No description provided.