E226: pycodestyle incorrectly warns about missing whitespace around operators

未关闭
#658 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
tooling

调研方向

使用 example.py 片段和 pycodestyle --select E226 重现该报告。首先定位 pycodestyle 的 E226 实现,并检查它如何处理列表切片中的运算符。完成的标准是:普通的不带空格的算术表达式(例如 2+2)仍然会发出警告,而报告中切片内的 + 不会发出警告。

由索引模型根据 Issue 内容生成。

描述

Given the following example.py,

my_list = [1, 2, 3]
a = 2+2
b = my_list[1:1+1]

pycodestyle incorrectly warns about the missing whitespace for the + operator inside the list slice:

» pycodestyle --select E226 ./example.py
./example.py:2:6: E226 missing whitespace around arithmetic operator  # OK
./example.py:3:16: E226 missing whitespace around arithmetic operator  # incorrect

The first warning (line 2) is correct (line 2 should read a = 2 + 2); the second warning (line 3) is incorrect according to PEP-8:

Yes:

ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step]
ham[lower+offset : upper+offset]
ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
ham[lower + offset : upper + offset]

No:

ham[lower + offset:upper + offset]
ham[1: 9], ham[1 :9], ham[1:9 :3]
ham[lower : : upper]
ham[ : upper]

Edit: okay, I'm not so sure I've got it 100%. The style I think is PEP-8 doesn't really seem to get listed anywhere, but even if I add spaces around the : (which is listed), I still get lints.

主要语言
Python
星标
5.2k
派生
765
平均合并
1 天 20 小时
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PyCQA/pycodestyle 的其他 Issue

查看 PyCQA/pycodestyle 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。