Repository navigation
Fix: 支持带时区的 expire_time 过期判断 - #4237
Merged
Merged
Conversation
_check_matcher compared naive datetime.now() with expire_time, raising TypeError for timezone-aware datetimes and leaving the matcher alive. Take now() in expire_time's own tzinfo instead. Fixes #4236 Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Contributor
|
🚀 Deployed to https://deploy-preview-4237--nonebot2.netlify.app |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4237 +/- ##
==========================================
+ Coverage 93.84% 93.85% +0.01%
==========================================
Files 49 49
Lines 4532 4540 +8
==========================================
+ Hits 4253 4261 +8
Misses 279 279
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
yanyongyu
previously approved these changes
Nov 4, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
yanyongyu
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #4236
_check_matchercompared a naivedatetime.now()againstMatcher.expire_time. Whenexpire_timeis a timezone-aware datetime (allowed by thedatetime | timedeltaannotation, e.g.datetime.now(timezone.utc) + timedelta(minutes=5)), the comparison raisesTypeError: can't compare offset-naive and offset-aware datetimesoutside the permission/ruletryblocks. The matcher is then never destroyed and keeps failing on every event.This takes "now" in the expire time's own timezone:
datetime.now(Matcher.expire_time.tzinfo). For naiveexpire_time(including thetimedeltapath, which produces a naive datetime)tzinfoisNone, so behaviour is unchanged.Added
test_aware_datetime_expire, mirroringtest_datetime_expirewith an already expired UTC-awareexpire_time, and checked that the matcher gets destroyed.ruff format --checkandruff checkpass on the changed files. I have not run the pytest suite locally; relying on CI for it.