自动修复 ‘invalid-envvar-default’ (W1508) pylint 问题

huangapple go评论52阅读模式
英文:

Automatically fix 'invalid-envvar-default' (W1508) pylint issue

问题

没有办法自动修复'invalid-envar-default' pylint问题吗?

我尝试的所有工具(autopep8、autoflake和black)都不能自动修复此问题。

解决方案似乎对所有情况都很简单,确保第二个参数是一个字符串(可以用str()包装它):

从:
os.getenv('SECRET_KEY', 1) # [invalid-envvar-default]

到:os.getenv('SECRET_KEY', '1')

英文:

Is there any way to automatically fix 'invalid-envar-default' pylint issue?

None of the tools that I tried (autopep8, autoflake and black) do not automatically fix this issue.

The solution seems to be pretty straightforward for all cases, ensuring the second parameter is a string (it could be just wrap it with str():

Going from:
os.getenv('SECRET_KEY', 1) # [invalid-envvar-default]

to: os.getenv('SECRET_KEY', '1')

答案1

得分: 1

pylint目前没有自动修复功能。ruff旨在实现这一功能,但目前只有少数几个lint可用(并且不包括'invalid-envar-default')。很可能此类检查将从pylint中删除或在ruff中未实现,因为它与类型检查器应该通用地应用于单个函数的单个参数非常接近。这似乎是类型检查器不可用时的遗留物。(来源:我是pylint的维护者,正在考虑彻底删除此检查)。

因此,目前修复此问题的最佳方式是手动操作。

英文:

pylint does not have autofix at the moment. ruff aim to do that, but has few lints available at the moment (and not 'invalid-envar-default'). It's likely that this kind of check will be dropped from pylint or not implemented in ruff because it's really really close to what a type checker should do generically applied on a single parameter of a single function. It feel like a remnant of time when type checker where not available. (source: I'm a pylint maintainer and I'm thinking about removing this check outright).

So to sump up, the optimal way to fix this right now is manually.

huangapple
  • 本文由 发表于 2023年2月7日 00:36:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364106.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定