Skip to content

Conversation

@cclauss
Copy link
Contributor

@cclauss cclauss commented Jul 27, 2024

Let's consider this after #102 is merged so we can ensure that the pytests continue to pass with these changes.

Which ruff rules E can be automatically fixed?

% ruff check --statistics | grep "\[\*\]"

  58	E401	[*] multiple-imports-on-one-line
  51	F841	[*] unused-variable
  25	E711	[*] none-comparison
   8	E731	[*] lambda-assignment
   5	E703	[*] useless-semicolon
   2	E712	[*] true-false-comparison
   2	E713	[*] not-in-test

% ruff check --select=E --fix --unsafe-fixes

Found 276 errors (100 fixed, 176 remaining).

% ruff rule E731 # https://docs.astral.sh/ruff/rules/lambda-assignment

lambda-assignment (E731)

Derived from the pycodestyle linter.

Fix is sometimes available.

What it does

Checks for lambda expressions which are assigned to a variable.

Why is this bad?

Per PEP 8, you should "Always use a def statement instead of an assignment
statement that binds a lambda expression directly to an identifier."

Using a def statement leads to better tracebacks, and the assignment
itself negates the primary benefit of using a lambda expression (i.e.,
that it can be embedded inside another expression).

Example

f = lambda x: 2 * x

Use instead:

def f(x):
    return 2 * x

@arigo
Copy link
Contributor

arigo commented Jul 27, 2024

I know I didn't follow the letter of PEP 8 when writing CFFI. It's far too late now. I'm not reviewing changes to 42 files just for stylistic purposes, sorry. Additionally, CFFI is mostly in maintenance mode only.

@arigo arigo closed this Jul 27, 2024
@cclauss cclauss deleted the ruff-check-select-E-fix branch July 27, 2024 21:07
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