pylint

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

邮差的信 提交于 2019-12-03 02:06:19
问题 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

Automated docstring and comments spell check

Deadly 提交于 2019-12-03 01:20:35
Consider the following sample code: # -*- coding: utf-8 -*- """Test module.""" def test(): """Tets function""" return 10 pylint gives it 10 of 10, flake8 doesn't find any warnings: $ pylint test.py ... Global evaluation ----------------- Your code has been rated at 10.00/10 ... $ flake8 test.py $ But, as you may see, there is a typo in the test function's docstring. And, your editor would probably highlight it automagically, for example, here's how Pycharm does it: Thanks to the https://stackoverflow.com/questions/2151300/whats-the-best-way-to-spell-check-python-source-code topic, now I know

Pylint badge in gitlab

别说谁变了你拦得住时间么 提交于 2019-12-03 00:19:31
Gitlab has functionality to generade badges about build status and coverage percentage. Is it possible to create custom badge to display Pylint results? Or just display this results in README.md? I already have CI job for Pylint JGC I have written a python badge generation package that produces badges very visually similar to the main badge services. It is highly flexible, you can import and use in your python code, or run from the command line. I use this in GitLab CI to display pylint and coverage scores. There are other ways to do this using shields.io (see other answer from kubouch ), but

pylint warning on 'except Exception:'

痞子三分冷 提交于 2019-12-03 00:11:55
For a block like this: try: #some stuff except Exception: pass pylint raises warning W0703 'Catch "Exception"'. Why? Greg It's considered good practice to not normally catch the root Exception object, instead of catching more specific ones - for example IOException. Consider if an out of memory exception occurred - simply using "pass" isn't going to leave your programme in a good state. Pretty much the only time you should catch Exception is at the top level of your programme, where you can (try to) log it, display an error, and exit as gracefully as you can. Jonathan Hartley It's good

Pylint to show only warnings and errors

大城市里の小女人 提交于 2019-12-02 19:06:24
I would like to use pylint to check my code but I am only interested in error and warning levels. Is there a way to do that in command line or in pylintrc? I am not interested in filtering given issues (like listing all messages in MESSAGE CONTROL), I just want pylint to ignore all convention and refactor messages. Note: I don't think that's a duplicate of Using Pylint to display error and warnings Use the -d / --disable option to turn off the "C" and "R" message classes (convention and refactor): -d <msg ids>, --disable=<msg ids> Disable the message, report, category or checker with the given

Why is the empty dictionary a dangerous default value in Python? [duplicate]

走远了吗. 提交于 2019-12-02 18:40:29
This question already has an answer here: “Least Astonishment” and the Mutable Default Argument 31 answers Python methods: default parameter values are evaluated ONCE 3 answers I put empty braces as the default value for an optional argument to a Python function, and pylint (using Sublime package) told me it was dangerous. Can someone explain why this is the case? And is a better alternative to use None instead? It's dangerous only if your function will modify the argument. If you modify a default argument, it will persist until the next call, so your "empty" dict will start to contain values

visual studio code disable auto wrap long line

妖精的绣舞 提交于 2019-12-02 17:24:32
I use vs code to write python with pylint. When I press ctrl + S (save), the editor wrap a long line into multiple short lines. How to disable the action or configure wrap column count to 120 (default is 80)? I have tried "python.linting.pylintArgs": ["--max-line-length=120"] and "editor.wordWrapColumn": 120 , but didn't work. Check your Python formatting provider. "python.formatting.provider": "autopep8" I guess in your case it is not PyLint who keeps wrapping the long lines, but autopep8 .Try setting --max-line-length for autopep8 instead. "python.formatting.autopep8Args": [ "--max-line

How to deal with Pylint's “too-many-instance-attributes” message?

一世执手 提交于 2019-12-02 16:58:58
I have just tried to lint some code with Pylint, and the last remaining error is R0902: too-many-instance-attributes (8/7) I understand the rationale behind limiting the number of instance attributes, but seven seems a bit low. I also realise that the linter should not have the last word. However, I would like to know what I should be doing instead of: def __init__(self, output_file=None, output_dir=None): """ Set the frobnicator up, along with default geometries """ self.margin = 30 self.pos = [0, 0] self.sep = [5, 5] self.cell = [20, 20] self.frobbr = library.Frobbr() page = self.frobbr.get

Pylint invalid constant name

不问归期 提交于 2019-12-02 16:55:15
I'm receiving a Pylint error regarding my constant: MIN_SOIL_PARTICLE_DENS (invalid name). Any ideas why this constant is wrong? Here's my full function: def bulk_density(clay, sand, organic_matter): MIN_SOIL_PARTICLE_DENS = 2.65 x1 = (0.078 + 0.278 * sand + 0.034 * clay + 0.022 * organic_matter - 0.018 * sand * organic_matter - 0.027 * clay * organic_matter - 0.584 * sand * clay) x2 = -0.107 + 1.636 * x1 field_capacity = vol_water_content_33_j_kg(clay, sand, organic_matter)#m3/m3 sat_water_content = 0.043 + field_capacity + x2 - 0.097 * sand return (1 - sat_water_content) * MIN_SOIL_PARTICLE

Pylint can't find SQLAlchemy query member

吃可爱长大的小学妹 提交于 2019-12-02 16:09:33
I have a Flask (v0.10.1) application using Flask-SQLAlchemy (v2.0) and I'm trying to configure Pylint to check it. Running with Python 3.4.2. First error was: Instance of 'SQLAlchemy' has no 'Table' member (no-member) And I fixed this one ignoring the check for member attributes on SQLAlchemy: ignored-classes=SQLAlchemy But I'm having a problem with the query member on entities: Class 'UserToken' has no 'query' member (no-member) Is there any way to fix this issue without having to ignore no-member errors on every query call? Flask bootstrap: from flask import Flask from flask_sqlalchemy