-
Couldn't load subscription status.
- Fork 2
Add Type Annotations #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
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks for the patch! I left my comments. After they're addressed, the type checking commit is good to go.
I would rather not include #1 (and its associated commit).
|
|
||
| from typing import Any, Callable, Dict, Iterable, Optional, Set, Tuple | ||
|
|
||
|
|
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.
Let's do Row = Dict[str, Any] and RowPredicate = Callable[[Row], bool] to make types easier to read
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.
Sorry which line are you referencing/
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.
Adding new type aliases so we can use those throughout the new type annotations. This will make nearly every annotation much shorter
| result = db.OFFSET(result, offset) | ||
| if limit: | ||
| result = db.LIMIT(result, limit) | ||
| if distinct: |
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 should go in a separate commit and needs separate tests. Additionally, in the SQL order of execution, I think it goes between select and order by
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.
(test is slightly less important but it should go in a separate commit than type checking for sure)
| set_values: Dict[str, Any], | ||
| pred: Callable[[Dict[str, Any]], bool] = lambda _: True, | ||
| ) -> Table: | ||
| return Table( | ||
| table.name, [{**row, **set} if pred(row) else row for row in table.rows] | ||
| table.name, | ||
| [{**row, **set_values} if pred(row) else row for row in table.rows], | ||
| ) |
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.
s/set_values/row_updates/g maybe
…future__` to enable postponed evaluation of type hints (PEP 563). (modern type hints for forward references) This allows updating the return type hint in the `Table.filter` method from the string literal `"Table"` to the direct type `Table`, resulting in cleaner and more modern code.
Pyrefly (cutting edge type checker) reported several problems. Resolved all with this PR
Type Checking Results
Unit Testing