Skip to content

[CI] [RLlib] flake8 raises E731 after code is formatted with Black #21315

@bveeramani

Description

@bveeramani

Ray Component

RLlib

What happened + What you expected to happen

I formatted the RLlib code with Black and then ran flake8, but then I got the warning E731 do not assign a lambda expression, use a def.

rllib/evaluation/worker_set.py:452:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/worker_set.py:454:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/worker_set.py:463:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/worker_set.py:465:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/worker_set.py:469:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/worker_set.py:476:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/worker_set.py:478:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/worker_set.py:485:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/sampler.py:457:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/sampler.py:458:13: E731 do not assign a lambda expression, use a def
rllib/evaluation/sampler.py:461:13: E731 do not assign a lambda expression, use a def

sampler.py and worker_set.py assign lambda expressions to variables. For example,

queue_putter = (lambda x: None)
extra_batches_putter = (lambda x: None)

Black removes extraneous parentheses surrounding lambda expressions. So, after formatting, the code snippet above looks like:

queue_putter = lambda x: None
extra_batches_putter = lambda x: None

It seems like, for some reason, flake8 doesn't raise E731 if a lambda expression is wrapped in parentheses.

To allow us to migrate to Black (#21311) without causing our builds to fail, we'll need to preemptively disable E731 in sampler.py and worker_set.py.

Versions / Dependencies

  • Python: 3.8.12
  • OS: macOS 11.5.2
  • Black: 21.12b0
  • flake8: 3.9.1 (flake8-bugbear: 21.9.2, flake8-comprehensions: 3.7.0, flake8_quotes: 2.0.0, mccabe: 0.6.1, pycodestyle: 2.7.0, pyflakes: 2.3.1)
  • Ray commit: 14ed7cfaaa8f890204619c149d4d50b5857c3cd6

Reproduction script

black rllib
flake8 rllib | grep E731

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions