Skip to content

Conversation

@rosmur
Copy link

@rosmur rosmur commented Jun 29, 2025

Pyrefly (cutting edge type checker) reported several problems. Resolved all with this PR

Type Checking Results

> pyrefly check db.py
 INFO errors shown: 0, errors ignored: 0, modules: 1, transitive dependencies: 62, lines: 17,907, time: 0.08s, peak memory: physical 79.8 MiB

Unit Testing

> python3 -m unittest db_tests.py
......................................
----------------------------------------------------------------------
Ran 38 tests in 0.001s

OK

Copy link
Owner

@tekknolagi tekknolagi left a 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


Copy link
Owner

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

Copy link
Author

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/

Copy link
Owner

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:
Copy link
Owner

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

Copy link
Owner

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)

Comment on lines +78 to 84
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],
)
Copy link
Owner

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants