codeant-ai-for-open-source[bot] commented on code in PR #42054:
URL: https://github.com/apache/superset/pull/42054#discussion_r3593064068
##########
superset/utils/date_parser.py:
##########
@@ -95,9 +105,12 @@ def normalize_time_delta(human_readable: str) -> dict[str,
int]:
if not matched:
raise TimeDeltaAmbiguousError(human_readable)
- key = matched[2] + "s"
+ key = matched[2].lower() + "s"
Review Comment:
**Suggestion:** Add an explicit type annotation for the newly introduced
local variable so its intended string type is clear. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This newly added local variable is assigned a string value but has no type
annotation, which matches the custom rule requiring type hints on newly added
or modified Python code where annotation is feasible.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7b6cc692bc4348e7be1e2cd494900eac&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=7b6cc692bc4348e7be1e2cd494900eac&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/utils/date_parser.py
**Line:** 108:108
**Comment:**
*Custom Rule: Add an explicit type annotation for the newly introduced
local variable so its intended string type is clear.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42054&comment_hash=ced4cb7d31830d099ef9eed8f302c8735081f567c239ae2cd676ebeea3dc525b&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42054&comment_hash=ced4cb7d31830d099ef9eed8f302c8735081f567c239ae2cd676ebeea3dc525b&reaction=dislike'>๐</a>
##########
tests/unit_tests/utils/date_parser_tests.py:
##########
@@ -561,6 +564,70 @@ def test_get_past_or_future() -> None:
assert get_past_or_future("3 month", dttm) == datetime(2020, 5, 29)
+def test_get_past_or_future_quarters() -> None:
+ # parsedatetime has no notion of quarters (it would leave the source time
+ # unchanged); quarter phrases are rewritten to months before parsing
+ dttm = datetime(2024, 5, 15, 10, 30, 45)
Review Comment:
**Suggestion:** Add an explicit type annotation for this local datetime
variable to comply with the type-hints requirement. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is a newly added local variable with an obvious datetime type and no
annotation. That matches the rule requiring type hints on relevant variables
that can be annotated.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=203e4f3100a3414baa831219162cdcac&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=203e4f3100a3414baa831219162cdcac&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/utils/date_parser_tests.py
**Line:** 570:570
**Comment:**
*Custom Rule: Add an explicit type annotation for this local datetime
variable to comply with the type-hints requirement.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42054&comment_hash=b3fb9aea76fbe522056f7f450a51b8df6dddd21acb05c5bebb3751fb6dbe8059&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42054&comment_hash=b3fb9aea76fbe522056f7f450a51b8df6dddd21acb05c5bebb3751fb6dbe8059&reaction=dislike'>๐</a>
##########
tests/unit_tests/utils/date_parser_tests.py:
##########
@@ -561,6 +564,70 @@ def test_get_past_or_future() -> None:
assert get_past_or_future("3 month", dttm) == datetime(2020, 5, 29)
+def test_get_past_or_future_quarters() -> None:
+ # parsedatetime has no notion of quarters (it would leave the source time
+ # unchanged); quarter phrases are rewritten to months before parsing
+ dttm = datetime(2024, 5, 15, 10, 30, 45)
+ assert get_past_or_future("1 quarter ago", dttm) == datetime(
+ 2024, 2, 15, 10, 30, 45
+ )
+ assert get_past_or_future("2 quarters ago", dttm) == datetime(
+ 2023, 11, 15, 10, 30, 45
+ )
+ assert get_past_or_future("1 quarter later", dttm) == datetime(
+ 2024, 8, 15, 10, 30, 45
+ )
+ assert get_past_or_future("1 QUARTER ago", dttm) == datetime(
+ 2024, 2, 15, 10, 30, 45
+ )
+ # absurdly long digit runs are not rewritten (bounded to keep matching
+ # linear and the month count small); they parse like any other
+ # unintelligible phrase, i.e. the source time comes back unchanged
+ assert get_past_or_future("0" * 100_000 + " quarters ago", dttm) == dttm
+
+
+def test_parse_human_timedelta_unparseable_is_zero() -> None:
+ # the parser leaves unparseable phrases as the source time, so their
+ # delta is zero; a zero delta alone cannot distinguish them from
+ # legitimate zero-shift phrases (see is_parseable_human_timedelta)
+ dttm = datetime(2024, 5, 15)
Review Comment:
**Suggestion:** Add an explicit type annotation for this local datetime
variable to satisfy the mandatory typing rule for relevant variables.
[custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is another newly introduced local variable with a clearly inferable
datetime type and no type hint, so it violates the Python type-hints rule.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=021474adb8ba4aa692a23668ac732177&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=021474adb8ba4aa692a23668ac732177&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/utils/date_parser_tests.py
**Line:** 593:593
**Comment:**
*Custom Rule: Add an explicit type annotation for this local datetime
variable to satisfy the mandatory typing rule for relevant variables.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42054&comment_hash=9bc8a8dd2e4a74a3e50500ae7a73a9f61d49ba6b632c0f4b53184689c2eb91a0&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42054&comment_hash=9bc8a8dd2e4a74a3e50500ae7a73a9f61d49ba6b632c0f4b53184689c2eb91a0&reaction=dislike'>๐</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]