-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Convenience Functionality for BusinessOpeningHours #4861
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
base: master
Are you sure you want to change the base?
Conversation
-check if the business is open at a given time -get the opening hours for a given day
Convenience Functionality for BusinessOpeningHours -check if the business is open at a given time -get the opening hours for a given day
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.
Hey. Thanks for your PR!
I gave it first quick look, but without actually reviewing the new logic. For starters, I focused on a few formalities and setup problems since you're apprantly strugging with this #4194 (comment). I hope that my comments help you.
Please also make sure to check the output of the pre-commit ci run in the "status checks" tab on the PR.
Please let me know if you need additional help with getting the tests running & pre-commit to pass - or when that's done and I should review properly :) Looking forward to it!
src/telegram/_utils/datetime.py
Outdated
try: | ||
return zoneinfo.ZoneInfo(tz) | ||
except zoneinfo.ZoneInfoNotFoundError as err: | ||
raise TelegramError( |
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.
raise TelegramError( | |
raise oneinfo.ZoneInfoNotFoundError( |
src/telegram/_utils/enum.py
Outdated
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.
please revert. This is unrelated to your changes and in fact the pre-commit ci run complains about it
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
edit 4861.HEoGVs2mYXWzqMahi6SEhV.toml
Hello. Im having general problems to understand work flow here in git PR ) Please guide me) |
Hi I am going to give this a shot.
I do not quite get the question here, which requested changed did you not apply successfully? Yes the git actions will run on every commit. Doesn't really matter, the important part is that they don't fail on the last one.
The pre commit CI is imo pretty self explanatory, you apparently in the second PR also already fixed some issues there, so I am going to assume you understand that. You can also change the branch in this PR to your new one in your repo. We can ignore the Bot API test, and fix the chango/security analysis later. The important part to ensure you code is working correctly is the pre commit and the unit test. If you open any unit test run, and wait for it to load, you should have a huge wall of text. Scroll up to leave the flaky tests behind, until you see tests/test_business_classes.py:715: AssertionError. These are now the unit tests which failed, and they explain you where it failed and why (what it expected, what it got). You need to scroll up further to see them all, but you will get quickly an idea what the output format is. So either you need to fix the tests, or your code. Do that for all the tests, and see where that gets you. If you have more questions, make sure you read through the contrib guidelines and otherwise ask. Just here, or in our development group. |
On my pc i have this (python-telegram-bot) PS C:\Users\Aweryc\PycharmProjects\python-telegram-bot> pre-commit run -a Now go to CI steps) |
Convenience functionalty boh
# Conflicts: # changes/unreleased/4861.HEoGVs2mYXWzqMahi6SEhV.toml # src/telegram/_utils/datetime.py
# Conflicts: # changes/unreleased/4861.HEoGVs2mYXWzqMahi6SEhV.toml # src/telegram/_utils/datetime.py
Hello. I made a changes and now some unit tests are passed for different python versions, some ain't.
What should I do? |
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.
Heyho :) Thanks for the updates and sorry for the late reply. I've gone through your code logic now and left several comments, but haven't reviewed the tests yet. As for the failing tests, I opened #4879. Once that's merged, we'll apply it to your branch as well :)
if dt.tzinfo is None: | ||
dt_utc = dt | ||
else: | ||
dt_utc = dt.astimezone(verify_timezone(ZoneInfo(self.time_zone_name))) |
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.
if dt.tzinfo is None: | |
dt_utc = dt | |
else: | |
dt_utc = dt.astimezone(verify_timezone(ZoneInfo(self.time_zone_name))) | |
aware_datetime = datetime.replace(tzinfo=verify_timezone(self.time_zone_name)) if datetime.tzinfo is None else datetime |
the name dt_utc
is a bit misleading as the involved timezones are probably not UTC :)
def verify_timezone( | ||
tz: Union[dtm.tzinfo, zoneinfo.ZoneInfo], | ||
) -> Optional[Union[zoneinfo.ZoneInfo, dtm.tzinfo]]: | ||
""" | ||
Verifies that the given timezone is a valid timezone. | ||
""" |
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.
def verify_timezone( | |
tz: Union[dtm.tzinfo, zoneinfo.ZoneInfo], | |
) -> Optional[Union[zoneinfo.ZoneInfo, dtm.tzinfo]]: | |
""" | |
Verifies that the given timezone is a valid timezone. | |
""" | |
def get_zoneinfo( | |
tz: str, | |
) -> zoneinfo.ZoneInfo: | |
"""Wrapper around the `ZoneInfo` constructor with slightly more helpful error messages | |
""" |
The goal of this helper is to improve the error message that's raised by ZoneInfo(some_timezone_name)
if the tzdata
package is not available and the timezone can not be provided by the system. validating that an object is indeed a ZoneInfo
object doesn't give any advantage to us :)
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.
Change a doc is ok a got it.
And you want to change type hints and returning value?
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.
yes :)
if isinstance(tz, (dtm.tzinfo, zoneinfo.ZoneInfo)): | ||
return tz |
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.
if isinstance(tz, (dtm.tzinfo, zoneinfo.ZoneInfo)): | |
return tz |
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.
You suggest just delete this two lines?
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.
yes
except (TypeError, ValueError) as e: | ||
raise zoneinfo.ZoneInfoNotFoundError( | ||
f"No time zone found with key {tz}. " | ||
f"Make sure to use a valid time zone name and " | ||
f"correct install tzdata (https://pypi.org/project/tzdata/)" | ||
) from e |
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.
except (TypeError, ValueError) as e: | |
raise zoneinfo.ZoneInfoNotFoundError( | |
f"No time zone found with key {tz}. " | |
f"Make sure to use a valid time zone name and " | |
f"correct install tzdata (https://pypi.org/project/tzdata/)" | |
) from e |
from the python docs:
key must be in the form of a relative, normalized POSIX path, with no up-level references. The constructor will raise ValueError if a non-conforming key is passed.
This means that in case the user passes something that is not a timezone name, python will complain. A ValueError does however not really mean that no timezone could be found. Also the error message is already helpful in this case:
ValueError: ZoneInfo keys may not be absolute paths, got: :://urope/Berliuidtaerndiutanrn
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.
got: :://urope/Berliuidtaerndiutanrn
Sorry, cant read this) Is this example of wrong user input?
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.
yes :)
PS: #4879 is merged. You can merge the master branch into yours :) |
Convenience Functionality for BusinessOpeningHours
-check if the business is open at a given time
-get the opening hours for a given day