pylint

Python - Should I put my helper functions inside or outside the class? [closed]

≡放荡痞女 提交于 2019-12-02 16:08:21
In Python, if some methods of a class need a helper function, but the helper function itself doesn't use anything in the class, should I put the helper function inside or outside the class? I tried putting it inside but PyLint was complaining that this function could have been put outside. @Karl: The class is a software upgrader and the helper function creates a new folder if the folder doesn't exist yet. The class is in a module having pretty much only the code for the class as of now. Other classes may be added later on. When deciding where to put helper functions the question I ask is, "Is

Pylint showing invalid variable name in output

£可爱£侵袭症+ 提交于 2019-12-02 16:06:48
I made a simple python script to post data on a website. #Imports url_to_short = sys.argv[1] post_url = 'https://www.googleapis.com/urlshortener/v1/url' headers = {'Content-Type': 'application/json'} data = {'longUrl': url_to_short} post_data = json.dumps(data) req = urllib2.Request(post_url, post_data, headers) resp = urllib2.urlopen(req) if resp.getcode() == 200: content = json.loads(resp.read()) #Other stuff Now I thought lets check my script for coding standards with pylint tool. My pylint output is as follows: ************* Module post C: 1,0: Missing docstring C: 6,0: Invalid name "url

Why is the use of len(SEQUENCE) in condition values considered incorrect by Pylint?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 15:40:47
Considering this code snippet: from os import walk files = [] for (dirpath, _, filenames) in walk(mydir): # more code that modifies files if len(files) == 0: # <-- C1801 return None I was alarmed by Pylint with this message regarding the line with the if statement: [pylint] C1801:Do not use len(SEQUENCE) as condition value The rule C1801, at first glance, did not sound very reasonable to me, and the definition on the reference guide does not explain why this is a problem. In fact, it downright calls it an incorrect use . len-as-condition (C1801) : Do not use len(SEQUENCE) as condition value

What makes pylint think my class is abstract?

我的未来我决定 提交于 2019-12-01 17:49:50
As I understand it, Python (2.5.2) does not have real support for abstract classes. Why is pylint complaining about this class being an "Abstract class not reference?" Will it do this for any class that has NotImplementedError thrown? I have each class in its own file so if this is the case I guess I have no choice but to suppress this message but I am hoping there is maybe another way around it. """Package Repository interface.""" class PackageRepository(object): """Package Repository interface.""" def __init__(self): self.hello = "world" def get_package(self, package_id): """ Get a package

What makes pylint think my class is abstract?

删除回忆录丶 提交于 2019-12-01 17:44:50
问题 As I understand it, Python (2.5.2) does not have real support for abstract classes. Why is pylint complaining about this class being an "Abstract class not reference?" Will it do this for any class that has NotImplementedError thrown? I have each class in its own file so if this is the case I guess I have no choice but to suppress this message but I am hoping there is maybe another way around it. """Package Repository interface.""" class PackageRepository(object): """Package Repository

Pylint ignore specific names [duplicate]

孤街醉人 提交于 2019-12-01 17:34:24
问题 This question already has answers here : How to disable pylint 'Undefined variable' error for a specific variable in a file? (6 answers) Closed 6 years ago . I have a problem with pylint, i.e. sometimes it repeats the same message for some variable/class/module etc. and I can't find a workaround for that. What I want is to say pylint "don't check [message XXX|any message] for variable YYY in [this module|module "ZZZ"]" with some option or rcfile directive. 回答1: What you are asking for is not

Why should __all__ only contain string objects?

半世苍凉 提交于 2019-12-01 11:41:53
Today I came across the following pylint error: invalid-all-object (E0604): Invalid object %r in __all__, must contain only strings Used when an invalid (non-string) object occurs in __all__. And I'm quite curious to why is it considered incorrect to expose objects directly? Because it's supposed to be a list of names , not values: If the list of identifiers is replaced by a star ( '*' ), all public names defined in the module are bound in the local namespace for the scope where the import statement occurs. The public names defined by a module are determined by checking the module’s namespace

Permanent Config File in Pylint

有些话、适合烂在心里 提交于 2019-12-01 11:07:43
问题 I've setup a custom configuration file for Pylint (name, conveniently, config). There has to be a way that I don't have to include --rcfile=config on every run. How can I set the config file permanently? 回答1: set the path to that file in the PYLINTRC environment variable, or rename the file $HOME/.pylintrc or /etc/pylintrc (the latter is probably only supported on *nix) 回答2: When you do not specify the --rcfile option, Pylint searches for a configuration file in the following order and uses

Capture variable from for-loop for using later in QPushButton [duplicate]

南笙酒味 提交于 2019-12-01 10:40:58
This question already has an answer here: Using lambda expression to connect slots in pyqt 3 answers Disclaimer : I've read other questions like this already (eg. this one ) but didn't find a working solution for me yet (or I just don't understand them :)) When I create a lambda inside a for loop accessing data from the scope of the block I get a pylint warning ( cell-var-from-loop ) because of the way Python captures work. E.g: for key, value in data.items(): button = QtGui.QPushButton('show data') button.clicked.connect(lambda: show_data(value)) table_widget.setCellWidget(1, 1, button) There

Capture variable from for-loop for using later in QPushButton [duplicate]

喜你入骨 提交于 2019-12-01 07:32:58
问题 This question already has answers here : Using lambda expression to connect slots in pyqt (3 answers) Closed 2 years ago . Disclaimer : I've read other questions like this already (eg. this one) but didn't find a working solution for me yet (or I just don't understand them :)) When I create a lambda inside a for loop accessing data from the scope of the block I get a pylint warning ( cell-var-from-loop ) because of the way Python captures work. E.g: for key, value in data.items(): button =