Skip to content
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

fix: Fixed E731 errors in tests #737

Closed
wants to merge 1 commit into from
Closed

fix: Fixed E731 errors in tests #737

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Sep 21, 2023

Thanks for contributing!

Before submitting your pull request please have a look at the
following checklist:

  • ran the tests (pytest)
  • all style issues addressed (flake8)
  • your changes are covered by tests
  • your changes are documented, if needed

In addition, please take care to provide a proper description
on what your change does, fixes or achieves when submitting the
pull request.

@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (3696d53) 96.96% compared to head (d4b5d1a) 96.96%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #737   +/-   ##
=======================================
  Coverage   96.96%   96.96%           
=======================================
  Files          20       20           
  Lines        1547     1547           
=======================================
  Hits         1500     1500           
  Misses         47       47           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -102,7 +102,7 @@ def test_strip_comments_preserves_linebreak(self):
assert res == 'select *\n\nfrom foo'

def test_strip_ws(self):
f = lambda sql: sqlparse.format(sql, strip_whitespace=True)
def f(sql): return sqlparse.format(sql, strip_whitespace=True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I've got a different opinion on this. E731 states to prefer a function definition over assigning a lambda expression to a variable. But as also stated in E731 the primary reason is for debugging as the lambda expression shows up as <lambda> in a traceback.

But here the lambda is just a shorthand for the formatting code to make the tests shorter and more readable. Iff debugging is needed here, there's only one <lambda>. So it's pretty obvious.

On the other hand I find single line function definitions a bit harder to read and I would avoid them if possible.

So to me "Readability counts" is the argument here, especially as the one reason for using function definitions instead of assigning a lambda function to a variable doesn't count here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I get you!)
I will close this PR now,
and thank you for your feedback

@@ -140,8 +140,7 @@ def test_notransform_of_quoted_crlf(self):

class TestFormatReindentAligned:
@staticmethod
def formatter(sql):
return sqlparse.format(sql, reindent_aligned=True)
def formatter(sql): return sqlparse.format(sql, reindent_aligned=True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this to a single line expression? It's harder to read, IMO.

f = lambda sql: sqlparse.format(sql, output_format='python',
reindent=True)
def f(sql): return sqlparse.format(sql, output_format='python', reindent=True)
from pprint import pprint
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've left some debugging code in this change.

assert f(sql) == "sql = 'select * from foo;'"
f = lambda sql: sqlparse.format(sql, output_format='python',
reindent=True)
def f(sql): return sqlparse.format(sql, output_format='python', reindent=True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and some of the following changes break the 80-column rule.

@ghost ghost closed this Sep 26, 2023
@ghost ghost deleted the fix/e731 branch September 26, 2023 10:51
This pull request was closed.
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.

1 participant