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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix E731 #766

Merged
merged 3 commits into from
Nov 16, 2022
Merged

Fix E731 #766

merged 3 commits into from
Nov 16, 2022

Conversation

harupy
Copy link
Contributor

@harupy harupy commented Nov 16, 2022

E731 should be only emitted when the assignment target is a Name.

a = lambda: None  # bad, should be converted to `def a(): return None`.
a.b = lambda: None  # ok
a["b"] = lambda  # ok
# Flake8

> flake8 --select E731 resources/test/fixtures/E731.py
resources/test/fixtures/E731.py:2:1: E731 do not assign a lambda expression, use a def
resources/test/fixtures/E731.py:4:1: E731 do not assign a lambda expression, use a def
resources/test/fixtures/E731.py:7:5: E731 do not assign a lambda expression, use a def

# Current

> cargo run -- --select E731 resources/test/fixtures/E731.py
resources/test/fixtures/E731.py:2:1: E731 Do not assign a lambda expression, use a def
resources/test/fixtures/E731.py:4:1: E731 Do not assign a lambda expression, use a def
resources/test/fixtures/E731.py:7:5: E731 Do not assign a lambda expression, use a def
resources/test/fixtures/E731.py:12:1: E731 Do not assign a lambda expression, use a def  馃憟
resources/test/fixtures/E731.py:16:1: E731 Do not assign a lambda expression, use a def  馃憟

# With fix

> cargo run -- --select E731 resources/test/fixtures/E731.py
resources/test/fixtures/E731.py:2:1: E731 Do not assign a lambda expression, use a def
resources/test/fixtures/E731.py:4:1: E731 Do not assign a lambda expression, use a def
resources/test/fixtures/E731.py:7:5: E731 Do not assign a lambda expression, use a def

@charliermarsh charliermarsh merged commit 910ee52 into astral-sh:main Nov 16, 2022
@harupy harupy deleted the fix-E731 branch November 16, 2022 15:01
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.

None yet

2 participants