pylint

How to indicate multiple unused values in Python?

被刻印的时光 ゝ 提交于 2019-12-23 08:47:07
问题 Normally in Python, one should use an _ to indicate an argument is unused. def example_basic(unused): pass becomes def example_basic(_): pass Then if there are multiple unused arguments, multiple _ s can't be used since they will conflict, so a *_ is used: def example_multiple(unused1, unused2): pass becomes def example_multiple(*_): pass Finally, what should be done if there are multiple non-adjacent arguments that go unused? def example_non_adjacent(unused1, used, unused2): return used

How to avoid Pylint warnings for constructor of inherited class in Python 3?

∥☆過路亽.° 提交于 2019-12-23 08:30:30
问题 In Python 3, I have the following code: class A: def __init__(self): pass class B(A): def __init__(self): super().__init__() This yields the Pylint warning: Old-style class defined. (old-style-class) Use of super on an old style class (super-on-old-class) In my understanding, in Python 3 there does not exist an old-style class anymore and this code is OK. Even if I explicitly use new-style classes with this code class A(object): def __init__(self): pass class B(A): def __init__(self): super()

Mixing datetime.strptime() arguments

依然范特西╮ 提交于 2019-12-23 08:18:06
问题 It is quite a common mistake to mix up the datetime.strptime() format string and date string arguments using: datetime.strptime("%B %d, %Y", "January 8, 2014") instead of the other way around: datetime.strptime("January 8, 2014", "%B %d, %Y") Of course, it would fail during the runtime: >>> datetime.strptime("%B %d, %Y", "January 8, 2014") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/

Pylint W0212 protected-access

蓝咒 提交于 2019-12-23 06:49:23
问题 In Python, prefixing with one underscore indicates that a member should not be accessed outside of its class. This seems to be on a per-class basis like Java and C++. However, pylint seems to enforce this convention on a per-object basis. Is there a way to allow per-class access without resorting to #pylint: disable=protected-access ? class A: def __init__(self): self._b = 5 def __eq__(self, other): return self._b == other._b Result: pylint a.py a.py:6: W0212(protected-access) Access to a

Pylint says 'string' module is deprecated. What's the new way to get range of lowercase characters?

浪子不回头ぞ 提交于 2019-12-23 06:49:12
问题 I was just pylinting some code and noticed a colleague had imported the old Python 'string' module, not to use any functions from it but simply to have access to the constant ' string.lowercase '. I removed the deprecated import and substituted 'abcdef...' for string.lowercase, but I was wondering: is there a better way I should be doing this? 回答1: string itself is not deprecated, just those methods like string.join that are better accessed through a string object. You can still import string

Visual Studio Code, pylint complaining about “Unable to import XXX”

北城以北 提交于 2019-12-22 13:55:20
问题 I am using Visual Studio Code to work on a large python project with many modules. My settings.json looks like this: { "python.linting.pylintEnabled": true, "python.linting.enabled": true, "python.autoComplete.extraPaths": [ "C:/Users/.../repos/platform", ], "python.linting.pylintPath": "pylint" } After that inside the code. I am getting a ton of error on all import modules which are inside the platform-folder. I have python3 installed with python extensions and pylint installed as well. I

How would I start integrating pyflakes with Hudson

随声附和 提交于 2019-12-22 04:12:30
问题 We use Hudson for continuous integration with the Violations Plugin which parses our output from pylint. However, pylint is a bit too strict, and hard to configure. What we'd rather use is pyflakes which would give us the right level of "You're doing it wrong." 回答1: You can adapt pyflakes and pep8 output to work with the Violations pylint plugin. pyflakes path/to/src | awk -F\: '{printf "%s:%s: [E]%s\n", $1, $2, $3}' > violations.pyflakes.txt pep8 path/to/src | awk -F\: '{printf "%s:%s: [%s]

Alternatives to imp.find_module?

[亡魂溺海] 提交于 2019-12-21 16:54:35
问题 Background I've grown tired of the issue with pylint not being able to import files when you use namespace packages and divide your code-base into separate folders. As such I started digging into the astNG source-code which has been identified as the source of the trouble (see bugreport 8796 on astng). At the heart of the issue seems to be the use of pythons own imp.find_module in the process of finding imports. What happens is that the import's first (sub)package - a in import a.b.c - is fed

How to handle the pylint message: ID:W0612 Unused Variable

时光总嘲笑我的痴心妄想 提交于 2019-12-21 06:50:41
问题 I'm updating some code to PEP 8 standard using pylint. Part of the code is throwing the W0612 unused variable error but it's because it's using a module that returns (x,y) for example when only x is needed in this particular case, this is what's done. (var_1, var_2) = func() def func(): a="a" b="b" return (a,b) var_1 is then returned but var_2 is never used and therefore throws the error. How should I handle this? I'm thinking this var = func()[0] What is the best way to handle it? 回答1: I

“Unused import warning” and pylint

随声附和 提交于 2019-12-21 06:49:03
问题 So I'm working on a project in Python and trying to keep it up to standards with pylint and just generally . So, I have a source file, (We'll just call it a.py) #a.py import loggingsetup def foo(): log.info("This is a log message") But, I want to control what the logging looks like, so in loggingsetup I have something like: #loggingsetup.py import logging logging.root.setLevel(logging.DEBUG) consoleOut = logging.StreamHandler() consoleOut.setLevel(logging.INFO) consoleOut.setFormatter(logging