repr for expressions#2020
Conversation
evanh
left a comment
There was a problem hiding this comment.
Per our discussion on Slack, I don't think this is more readable than what we have before (except that the indenting is nicer). {'__name__': 'Column', 'alias': None, 'column_name': 'c2', 'table_name': 't1'} is more readable than Column(alias='alias', table_name='table', column_name='column') and it's certainly not less verbose.
| function_2, | ||
| ] | ||
| assert list(function_2) == expected | ||
| print(function_2) |
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| @dataclass(frozen=True, repr=False) |
There was a problem hiding this comment.
Why do you not have a repr on these anymore?
There was a problem hiding this comment.
dataclasses have a default repr, you need to explicitly say you're using your own so that it uses your implementation
evanh
left a comment
There was a problem hiding this comment.
This looks pretty good to me, well done. Just one comment on the tests.
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "test_expr,expected_str", |
There was a problem hiding this comment.
You're missing a test for aliases.
There was a problem hiding this comment.
Thanks, this looks good.
Just one concern on subscriptable references, I think it is missing an accept call on the key.
The rest are only questions or nits.
Do you plan to provide a more concise implementation for the str method or are we going to use the same ?
I was planning on using the same one (at least for now). We can decide if we want anything different later |
Did you have something in mind? Maybe the repr but no newlines or indentation? |
Not really. I wondered what your plan was. I am ok with using the same representation. |
Codecov Report
@@ Coverage Diff @@
## master #2020 +/- ##
==========================================
+ Coverage 90.94% 91.02% +0.07%
==========================================
Files 499 499
Lines 21499 21550 +51
==========================================
+ Hits 19553 19615 +62
+ Misses 1946 1935 -11
Continue to review full report at Codecov.
|
Problem
AST printed is unreadable which makes test debugging difficult
Solution
Create a visitor class that traverses an expression and creates a string somewhat resembling the query. Use that to implement the repr method of the Expression base class
Results
Formatted queries look something like this:
Test Plan
All types of visited nodes are tested, I am assuming that is sufficient, happy to add more if folks would like it