-
Notifications
You must be signed in to change notification settings - Fork 2
⚙️ FEATURE-#40: Use Optional[bool] for Query flags to remove ambiguity #60
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| from datetime import date | ||
| from typing import Optional, Union | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field | ||
| from pydantic import BaseModel, ConfigDict, Field, model_validator | ||
|
|
||
|
|
||
| def _ascii(value: str) -> str: | ||
|
|
@@ -194,7 +194,7 @@ class Query(BaseModel): | |
| deleted: Optional[bool] = None | ||
| draft: Optional[bool] = None | ||
|
|
||
| unseen: bool = False | ||
| unseen: Optional[bool] = None | ||
|
|
||
| def _date_clauses(self) -> list[str]: | ||
| fields = ( | ||
|
|
@@ -229,6 +229,12 @@ def _size_clauses(self) -> list[str]: | |
| f"({name} {value})" for name, value in fields if value is not None | ||
| ] | ||
|
|
||
| @model_validator(mode="after") | ||
| def _check_seen_unseen(self) -> Query: | ||
| if self.seen is True and self.unseen is True: | ||
| raise ValueError("Cannot set both seen=True and unseen=True.") | ||
| return self | ||
|
|
||
| def _flag_clauses(self) -> list[str]: | ||
| fields = ( | ||
| (self.seen, "SEEN"), | ||
|
|
@@ -241,9 +247,7 @@ def _flag_clauses(self) -> list[str]: | |
| for flag, name in fields: | ||
| if flag is True: | ||
| parts.append(f"({name})") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Problem — The Fix — Add a Pydantic @model_validator(mode='after')
def _check_seen_unseen(self) -> 'Query':
if self.seen is not None and self.unseen is not None:
raise ValueError(
'Cannot set both seen and unseen. Use seen=True or unseen=True, not both.'
)
return self |
||
| elif flag is False: | ||
| parts.append(f"(UN{name})") | ||
| if self.unseen: | ||
| if self.unseen is True: | ||
| parts.append("(UNSEEN)") | ||
| return parts | ||
|
|
||
|
|
||
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.
[Blocking]
Problem — This is a silent breaking change for existing consumers. Previously,
Query(unseen=False)was the default and meant "no unseen filter" — the_flag_clausesmethod only checkedif self.unseen:which was falsy forFalse. After this PR,Query(unseen=False)now emits(SEEN), actively filtering for seen-only messages.Failure scenario —
Since the library is at version
1.0.0.dev1, there may not be many external callers yet, but this still changes documented behavior without a deprecation path.Fix — Document this as a breaking change in the PR description and changelog. Consider if the default change from
FalsetoNoneis sufficient, or ifunseen=Falseshould remain a no-op for backward compatibility.