[codeInspection] Fix python inspection descriptions

GitOrigin-RevId: 56876a5dd073a06c3fcc92f63ed1f5674830bc25
This commit is contained in:
Louis Vignier
2023-04-28 13:13:25 +00:00
committed by intellij-monorepo-bot
parent fc3e55da21
commit 1869ec9da6
67 changed files with 213 additions and 208 deletions
@@ -2,12 +2,12 @@
<body>
<p>Reports Cython variables being referenced before declaration.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
cdef int c_x
print(c_x, c_y) # Variable 'c_y' is used before its declaration
cdef int c_y = 0
</pre>
</code></pre>
</body>
</html>
@@ -3,21 +3,21 @@
<p>Reports violations of the
<a href="https://www.python.org/dev/peps/pep-0008/">PEP8</a> naming conventions.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class mammalia(object):
extremities = 4
def feeds(self):
print("milk")
</pre>
</code></pre>
<p>In this code fragment, IDE offers to rename <code>mammalia</code> to <code>Mammalia</code>.
When the quick-fix is applied, the code change to:</p>
<pre style="font-family: monospace">
<pre><code>
class Mammalia(object):
extremities = 4
def feeds(self):
print("milk")
</pre>
</code></pre>
</body>
</html>
@@ -2,11 +2,11 @@
<body>
<p>Reports shadowing built-in names, such as <code>len</code> or <code>list</code>.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def len(a, b, c):
d = a + b + c
return d
</pre>
</code></pre>
<p>In this code fragment, the <code>len</code> built-in name is used. The IDE offers to
apply the Rename refactoring as a fix.</p>
</body>
@@ -3,10 +3,10 @@
<p>Reports references in your code that cannot be resolved.</p>
<p>In a dynamically typed language, this is possible in a limited number of cases. </p>
<p>If a reference type is unknown, then its attributes are not highlighted as unresolved even if you know that they should be:</p>
<pre style="font-family: monospace">
<pre><code>
def print_string(s):
print(s.abc())
</pre>
</code></pre>
<p>In this code fragment <code>s</code> is always a string and <code>abc</code> should be highlighted as unresolved. However, <code>s</code>
type is inferred as <code>Any</code> and no warning is reported.</p>
<p>The IDE provides quick-fix actions to add missing references on-the-fly.</p>
@@ -2,7 +2,7 @@
<body>
<p>Reports undefined roles in reStructuredText files.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
.. role:: custom
.. role:: newcustom(emphasis)
@@ -12,6 +12,6 @@ An example of using :emphasis:`interpreted text`
Some text using undefined role :undef:`interpreted text`
</pre>
</code></pre>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports cases when not all abstract properties or methods are defined in
a subclass.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
from abc import abstractmethod, ABC
@@ -17,9 +17,9 @@ class Figure(ABC):
class Triangle(Figure):
def do_triangle(self):
pass
</pre>
</code></pre>
<p>When the quick-fix is applied, the IDE implements an abstract method for the <code>Triangle</code> class:</p>
<pre style="font-family: monospace">
<pre><code>
from abc import abstractmethod, ABC
@@ -36,6 +36,6 @@ class Triangle(Figure):
def do_triangle(self):
pass
</pre>
</code></pre>
</body>
</html>
@@ -4,12 +4,12 @@
passed to the function is equal to the default parameter value.</p>
<p>This inspection is disabled by default to avoid performance degradation.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def my_function(a: int = 2):
print(a)
my_function(2)
</pre>
</code></pre>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports discrepancies between declared parameters and actual arguments, as well as
incorrect arguments, for example, duplicate named arguments, and incorrect argument order.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Foo:
def __call__(self, p1: int, *, p2: str = "%"):
return p2 * p1
@@ -12,9 +12,9 @@ class Foo:
bar = Foo()
bar.__call__() # unfilled parameter
bar(5, "#") # unexpected argument
</pre>
</code></pre>
<p>The correct code fragment looks at follows:</p>
<pre style="font-family: monospace">
<pre><code>
class Foo:
def __call__(self, p1: int, *, p2: str = "%"):
return p2 * p1
@@ -23,6 +23,6 @@ class Foo:
bar = Foo()
bar.__call__(5)
bar(5, p2="#")
</pre>
</code></pre>
</body>
</html>
@@ -1,18 +1,19 @@
<html>
<body>
Reports the cases when you rewrite a loop variable with an inner loop:
<pre style="font-family: monospace">
Reports the cases when you rewrite a loop variable with an inner loop.
<p><b>Example:</b></p>
<pre><code>
for i in range(5):
for i in range(20, 25):
print("Inner", i)
print("Outer", i)
</pre>
</code></pre>
It also warns you if a variable declared in the <code>with</code> statement is redeclared inside of the statement body:
<pre style="font-family: monospace">
It also warns you if a variable declared in the <code>with</code> statement is redeclared inside the statement body:
<pre><code>
with open("file") as f:
f.read()
with open("file") as f:
</pre>
</code></pre>
</body>
</html>
@@ -3,22 +3,22 @@
<p>Reports coroutines that were called
without using the <code>await</code> syntax.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
async def bar():
pass
async def foo():
bar()
</pre>
</code></pre>
<p>After the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
async def bar():
pass
async def foo():
await bar()
</pre>
</code></pre>
</body>
</html>
@@ -3,18 +3,18 @@
Reports a problem when instance attribute
definition is outside <code>__init__</code> method.
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Book:
def __init__(self):
self.author = 'Mark Twain'
def release(self):
self.year = '1889'
</pre>
</code></pre>
<p>
When the quick-fix is applied, the code sample changes to:
</p>
<pre style="font-family: monospace">
<pre><code>
class Book:
def __init__(self):
self.year = '1889'
@@ -22,6 +22,6 @@ definition is outside <code>__init__</code> method.
def release(self):
pass
</pre>
</code></pre>
</body>
</html>
@@ -2,16 +2,16 @@
<body>
<p>Reports assignments that can be replaced with augmented assignments.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
a = 23
b = 3
a = a + b
</pre>
</code></pre>
<p>After the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
a = 23
b = 3
a += b
</pre>
</code></pre>
</body>
</html>
@@ -2,6 +2,8 @@
<body>
<p>Reports characters in byte literals that are outside ASCII range.</p>
<p><b>Example:</b></p>
<code>s = b'&#8470;5'</code>
<pre><code>
s = b'&#8470;5'
</code></pre>
</body>
</html>
@@ -2,12 +2,13 @@
<body>
<p>Reports a problem when you are trying
to call objects that are not callable, like, for example, properties:</p>
<pre style="font-family: monospace">
<p><b>Example:</b></p>
<pre><code>
class Record:
@property
def as_json(self):
json = Record().as_json()
</pre>
</code></pre>
</body>
</html>
@@ -3,15 +3,15 @@
<p>Reports cases in Python 2 when a class has no <code>__init__</code> method, neither its parent
classes.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Book():
pass
</pre>
</code></pre>
<p>The quick-fix adds the <code>__init__</code> method:</p>
<pre style="font-family: monospace">
<pre><code>
class Book():
def __init__(self):
pass
</pre>
</code></pre>
</body>
</html>
@@ -2,7 +2,7 @@
<body>
<p>Reports invalid usages of <a href="https://docs.python.org/3/library/typing.html#typing.ClassVar">ClassVar</a> annotations.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
from typing import ClassVar
@@ -17,6 +17,6 @@ class Cat:
Cat.color = "black" # OK
my_cat = Cat(5)
my_cat.color = "gray" # Error, setting class variable on instance
</pre>
</code></pre>
</body>
</html>
@@ -3,15 +3,15 @@
<p>Reports <a href="https://docs.python.org/2/reference/datamodel.html#new-style-and-classic-classes">
classic style classes</a> usage. This inspection applies only to Python 2.
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class A:
pass
</pre>
</code></pre>
<p>With quick-fixes provided by the IDE, this code fragment changes to:</p>
<pre style="font-family: monospace">
<pre><code>
class A(object):
def __init__(self):
pass
</pre>
</code></pre>
</body>
</html>
@@ -4,20 +4,20 @@
should always be done with <code>is</code> or <code>is not</code>, never
the equality operators.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
a = 2
if a == None:
print("Success")
</pre>
</code></pre>
<p>Once the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
a = 2
if a is None:
print("Success")
</pre>
</code></pre>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports invalid definitions and usages of classes created with
<code>dataclasses</code> or <code>attr</code> modules.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
import dataclasses
@@ -12,6 +12,6 @@ class FullName:
first: str
middle: str = ""
last: str
</pre>
</code></pre>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports usages of <code>@classmethod</code> or <code>@staticmethod</code> decorators
in methods outside a class.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class State(object):
@classmethod
@@ -14,11 +14,11 @@ class State(object):
@classmethod
def change_state(self):
pass
</pre>
</code></pre>
<p>The <code>change_state</code> method should not use the <code>@classmethod</code> decorator or it should be
moved to the <code>State</code> class declaration. </p>
<p>If you apply the <code>Remove decorator</code> action, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
class State(object):
@classmethod
@@ -28,6 +28,6 @@ class State(object):
def change_state(self):
pass
</pre>
</code></pre>
</body>
</html>
@@ -6,16 +6,16 @@
which means that modifying the
default value of the argument will affect all subsequent calls of that function.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def func(s, cache={}):
cache[s] = None
</pre>
</code></pre>
<p>When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
def func(s, cache=None):
if cache is None:
cache = {}
cache[s] = None
</pre>
</code></pre>
</body>
</html>
@@ -5,7 +5,7 @@
<p>Also, this inspection highlights usages of <code>abc.abstractstaticmethod</code>, <code>abc.abstractproperty</code>, and <code>abc.abstractclassmethod</code>
decorators.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Foo:
@property
def bar(self):
@@ -16,6 +16,6 @@ class Foo:
foo = Foo()
print(foo.bar)
</pre>
</code></pre>
</body>
</html>
@@ -4,13 +4,13 @@
by using a dictionary literal.</p>
<p>This approach brings performance improvements.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
dic = {}
dic['var'] = 1
</pre>
</code></pre>
<p>When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
dic = {'var': 1}
</pre>
</code></pre>
</body>
</html>
@@ -2,8 +2,8 @@
<body>
<p>Reports using the same value as the dictionary key twice.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
dic = {"a": [1, 2], "a": [3, 4]}
</pre>
</code></pre>
</body>
</html>
@@ -2,13 +2,13 @@
<body>
<p>Reports invalid usages of a class with <code>__slots__</code> definitions.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Foo:
__slots__ = ['foo', 'bar']
foo = Foo()
foo.baz = 'spam'
</pre>
</code></pre>
</body>
</html>
@@ -6,22 +6,22 @@
If you do not fix the order, some exceptions may not be caught by the most specific handler.
</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
try:
call()
except ValueError:
pass
except UnicodeError:
pass
</pre>
</code></pre>
<p>The IDE recommends moving the clause up. When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
try:
call()
except UnicodeError:
pass
except ValueError:
pass
</pre>
</code></pre>
</body>
</html>
@@ -4,22 +4,22 @@
raised but does not inherit from the
<a href="https://docs.python.org/3/library/exceptions.html">builtin Exception class</a>.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class A:
pass
def me_exception():
raise A()
</pre>
</code></pre>
<p>The proposed quick-fix changes the code to:</p>
<pre style="font-family: monospace">
<pre><code>
class A(Exception):
pass
def me_exception():
raise A()
</pre>
</code></pre>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports invalid usages of final classes,
methods and variables.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
from typing import final
@@ -16,6 +16,6 @@ class A:
class B(A):
def a_method(self):
pass
</pre>
</code></pre>
</body>
</html>
@@ -4,17 +4,17 @@
statements that are used not at
the beginning of a file.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
a = 1
from __future__ import print_function
print()
</pre>
</code></pre>
<p>When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
from __future__ import print_function
a = 1
print()
</pre>
</code></pre>
</body>
</html>
@@ -3,20 +3,20 @@
<p>Reports problems when a variable defined through the <code>global</code>
statement is not defined in the module scope.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def foo():
global bar
print(bar)
foo()
</pre>
</code></pre>
<p>As a fix, you can move the global variable declaration:</p>
<pre style="font-family: monospace">
<pre><code>
global bar
def foo():
print(bar)
</pre>
</code></pre>
</body>
</html>
@@ -2,7 +2,7 @@
<body>
<p>Reports mismatched parameters in a docstring. For example, <code>b</code> is highlighted, because there is no
such a parameter in the <code>add</code> function.</p>
<pre style="font-family: monospace">
<pre><code>
def add(a, c):
"""
@param a:
@@ -10,14 +10,14 @@
@return:
"""
pass
</pre>
</code></pre>
<p>The inspection does not warn you of missing parameters if none of them is mentioned in a docstring:</p>
<pre style="font-family: monospace">
<pre><code>
def mult(a, c):
"""
@return:
"""
pass
</pre>
</code></pre>
</body>
</html>
@@ -2,14 +2,14 @@
<body>
<p>Reports incompatible signatures of the <code>__new__</code> and <code>__init__</code> methods.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class MyClass(object):
def __new__(cls, arg1):
return super().__new__(cls)
def __init__(self):
pass
</pre>
</code></pre>
<p>If the <code>__new__</code> and <code>__init__</code> have different arguments, then the <code>MyClass</code>
cannot be instantiated.</p>
<p>As a fix, the IDE offers to apply the Change Signature refactoring.</p>
@@ -4,13 +4,13 @@
can be rewritten with a list literal.</p>
<p>This ensures better performance of your application.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
l = [1]
l.append(2)
</pre>
</code></pre>
<p>When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
l = [1, 2]
</pre>
</code></pre>
</body>
</html>
@@ -2,17 +2,17 @@
<body>
<p>Reports a missing encoding comment in Python 2.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Book(object):
def __init__(self):
pass
</pre>
</code></pre>
<p>When the quick-fix is applied, the missing comment is added:</p>
<pre style="font-family: monospace">
<pre><code>
# coding=utf-8
class Book(object):
def __init__(self):
pass
</pre>
</code></pre>
</body>
</html>
@@ -5,13 +5,13 @@
Because in most cases, there are no objectives in such reassignment, the
IDE indicates an error.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Account:
def calc(self, balance):
if balance == 0:
self = balance
return self
</pre>
</code></pre>
<p>As a fix, you might want to check and modify the algorithm to ensure that reassignment is needed. If everything is correct,
you can invoke intention actions for this code and opt to ignore the warning.</p>
</body></html>
@@ -3,26 +3,26 @@
<p>Reports any methods that do not require a class instance creation and can be
made static.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class MyClass(object):
def my_method(self, x):
print(x)
</pre>
</code></pre>
<p>If a <b>Make function from method</b> quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
def my_method(x):
print(x)
class MyClass(object):
pass
</pre>
</code></pre>
<p>If you select the <b>Make method static</b> quick-fix, the <code>@staticmethod</code> decorator is added:</p>
<pre style="font-family: monospace">
<pre><code>
class MyClass(object):
@staticmethod
def my_method(x):
print(x)
</pre>
</code></pre>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports inconsistencies in overriding method signatures.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Book:
def add_title(self):
pass
@@ -12,7 +12,7 @@ class Book:
class Novel(Book):
def add_title(self, text):
pass
</pre>
</code></pre>
<p>Parameters of the <code>add_title</code> method in the <code>Novel</code> class do not match the method
signature specified in the <code>Book</code> class. As a fix, the IDE offers to apply the Change Signature
@@ -3,27 +3,27 @@
<p>Reports methods that lack the first parameter that is usually
named <code>self</code>.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Movie:
def show():
pass
</pre>
</code></pre>
<p>When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
class Movie:
def show(self):
pass
</pre>
</code></pre>
<p>The inspection also reports naming issues in class methods.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Movie:
@classmethod
def show(abc):
pass
</pre>
</code></pre>
<p>Since the first parameter of a class method should be <code>cls</code>, the IDE provides a quick-fix
to rename it.</p>
</body>
@@ -2,7 +2,7 @@
<body>
<p>Reports cases when a call to the <code>super</code> constructor in a class is missed.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Fruit:
def __init__(self):
pass
@@ -11,11 +11,11 @@ class Fruit:
class Pear(Fruit):
def __init__(self):
pass
</pre>
</code></pre>
<p>The <code>Pear</code> class should have a <code>super</code> call in the <code>__init__</code>
method.</p>
<p>When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
class Fruit:
def __init__(self):
pass
@@ -24,6 +24,6 @@ class Fruit:
class Pear(Fruit):
def __init__(self):
super().__init__()
</pre>
</code></pre>
</body>
</html>
@@ -2,26 +2,26 @@
<body>
<p>Reports missing and empty docstrings.</p>
<p><b>Example of a missing docstring</b></p>
<pre style="font-family: monospace">
<pre><code>
def demo(a):
c = a ** 2
</pre>
</code></pre>
<p><b>Example of an empty docstring</b></p>
<pre style="font-family: monospace">
<pre><code>
def demo(a):
"""
"""
c = a ** 2
</pre>
</code></pre>
<p>When the quick-fix is applied, the code fragments change to:</p>
<pre style="font-family: monospace">
<pre><code>
def demo(a):
"""
:param a:
"""
c = a ** 2
</pre>
</code></pre>
<p>You need to provide some details about the parameter in the generated template.</p>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports invalid definition of a
<a href="https://docs.python.org/3/library/typing.html#typing.NamedTuple">typing.NamedTuple</a>.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
import typing
@@ -11,9 +11,9 @@ class FullName(typing.NamedTuple):
first: str
last: str = ""
middle: str
</pre>
</code></pre>
<p>As a fix, place the field with the default value after the fields without default values:</p>
<pre style="font-family: monospace">
<pre><code>
import typing
@@ -21,6 +21,6 @@ class FullName(typing.NamedTuple):
first: str
middle: str
last: str = ""
</pre>
</code></pre>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports problems with nesting decorators. The inspection highlights the cases when <code>classmethod</code> or <code>staticmethod</code>
is applied before another decorator.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def innocent(f):
return f
@@ -18,7 +18,7 @@ class A:
@staticmethod
def f1():
pass
</pre>
</code></pre>
<p>As a quick-fix, the IDE offers to remove the decorator.</p>
</body>
</html>
@@ -3,20 +3,20 @@
<p>Reports cases in Python 2 when a file contains non-ASCII characters and does not
have an encoding declaration at the top.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class A(object):
# &#8470;5
def __init__(self):
pass
</pre>
</code></pre>
<p>In this example, the IDE reports a non-ASCII symbol in a comment and a lack of encoding
declaration. Apply the proposed quick-fix to add a missing encoding declaration:</p>
<pre style="font-family: monospace">
<pre><code>
# coding=utf-8
class A(object)
# &#8470;5
def __init__(self):
pass
</pre>
</code></pre>
</body>
</html>
@@ -2,15 +2,14 @@
<body>
<p>Reports cases when an assignment is done on a function that does not return anything.</p>
This inspection is similar to <a href="https://docs.pylint.org/en/1.6.0/features.html#id6">pylint inspection E1111</a>.
<p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def just_print():
print("Hello!")
action = just_print()
</pre>
</code></pre>
<p>As a quick-fix, the IDE offers to remove the assignment.</p>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports cases when overloads in regular Python files are placed after the implementation or when their signatures are
not compatible with the implementation.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
from typing import overload
@@ -19,6 +19,6 @@ def foo(p1): # Overload signature is not compatible with the implementation
def foo(p1, p2, p3):
print(p1, p2, p3)
</pre>
</code></pre>
</body>
</html>
@@ -7,7 +7,7 @@ Reports cases when properties are accessed inappropriately:
<li>Non-deletable properties are deleted</li>
</ul>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class MyClass:
@property
def read_only(self): return None
@@ -21,6 +21,6 @@ a = MyClass()
a.read_only = 10 # property cannot be set
del a.read_only # property cannot be deleted
print(a.write_only) # property cannot be read
</pre>
</code></pre>
</body>
</html>
@@ -2,7 +2,7 @@
<body>
<p>Reports problems with the arguments of <code>property()</code> and functions
annotated with <code>@property</code>.</p>
<pre style="font-family: monospace">
<pre><code>
class C:
@property
def abc(self): # Getter should return or yield something
@@ -19,7 +19,7 @@ class C:
@abc.deleter
def abc(self, v1): # Delete signature should be (self)
pass
</pre>
</code></pre>
<p>A quick-fix offers to update parameters.</p>
</body>
</html>
@@ -2,7 +2,8 @@
<body>
<p>Reports cases when a protected member is accessed outside the class,
a descendant of the class where it is defined, or a module.</p>
<pre style="font-family: monospace">
<p><b>Example:</b></p>
<pre><code>
class Foo:
def _protected_method(self):
pass
@@ -15,6 +16,6 @@ class Bar(Foo):
foo = Foo()
foo._protected_method() # Access to a protected method
</pre>
</code></pre>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports invalid definitions and usages of protocols introduced in
<a href="https://www.python.org/dev/peps/pep-0544/">PEP-544</a>.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
from typing import Protocol
@@ -20,6 +20,6 @@ class MyClass(MyProtocol):
class MyAnotherProtocol(MyClass, Protocol): # All bases of a protocol must be protocols
pass
</pre>
</code></pre>
</body>
</html>
@@ -2,12 +2,12 @@
<body>
<p>Reports unconditional redeclarations of names without being used in between.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def x(): pass
x = 2
</pre>
</code></pre>
<p>It applies to function and class declarations, and top-level assignments. </p>
<p>When the warning is shown, you can try a recommended action, for example, you might be prompted to
rename the variable.</p>
@@ -5,14 +5,14 @@
<code>__init__</code> methods of classes.
</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Sum:
def __init__(self, a, b):
self.a = a
self.b = b
self.sum = a + b
return self.sum
</pre>
</code></pre>
<p>A constructor should not return any value. The <code>__init__</code> method should
only initialize the values of instance members for news objects.</p>
<p>As a quick-fix, the IDE offers to remove the <code>return</code> statement.</p>
@@ -3,16 +3,16 @@
<p>Reports calls to the <code>set</code> function that can be replaced with
the <code>set</code> literal.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def do_mult(a, b):
c = a * b
return set([c, a, b])
</pre>
</code></pre>
<p>When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
def do_mult(a, b):
c = a * b
return {c, a, b}
</pre>
</code></pre>
</body>
</html>
@@ -2,11 +2,11 @@
<body>
<p>Reports shadowing names defined in outer scopes.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def outer(p):
def inner(p):
pass
</pre>
</code></pre>
<p>As a quick-fix, the IDE offers to remove a parameter or rename it.</p>
</body>
</html>
@@ -2,16 +2,16 @@
<body>
<p>Reports equality comparison with a boolean literal.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def func(s):
if s.isdigit() == True:
return int(s)
</pre>
</code></pre>
<p>With the quick-fix applied, the code fragment will be simplified to:</p>
<pre style="font-family: monospace">
<pre><code>
def func(s):
if s.isdigit():
return int(s)
</pre>
</code></pre>
</body>
</html>
@@ -2,16 +2,16 @@
<body>
<p>Reports docstrings that do not adhere to the triple double-quoted string format.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def calc(self, balance=0):
'param: balance'
self.balance = balance
</pre>
</code></pre>
<p>When the quick-fix is applied, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
def calc(self, balance=0):
"""param: balance"""
self.balance = balance
</pre>
</code></pre>
</body>
</html>
@@ -2,14 +2,14 @@
<body>
<p>Reports statements that have no effect.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Car:
def __init__(self, speed=0):
self.speed = speed
self.time # has no effect
2 + 3 # has no effect
</pre>
</code></pre>
<p>In this example, you can either add a field <code>time</code> to the <code>Car</code> class or
introduce variables for the problematic statements.</p>
</body>
@@ -2,17 +2,17 @@
<body>
<p>Reports errors in string formatting operations.</p>
<p><b>Example 1:</b></p>
<pre style="font-family: monospace">
<pre><code>
"Hello {1}".format("people")
</pre>
</code></pre>
<p><b>Example 2:</b></p>
<pre style="font-family: monospace">
<pre><code>
def bar():
return 1
"%s %s" % bar()
</pre>
</code></pre>
<p>As a fix, you need to rewrite string formatting fragments to
adhere to the <a href="https://docs.python.org/3/library/string.html#format-string-syntax">formatting syntax</a>.</p>
</body>
@@ -7,7 +7,7 @@
<li><code>B</code> a subclass of <code>A</code></li>
</ul>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
class Figure:
def color(self):
pass
@@ -21,7 +21,7 @@ class Rectangle(Figure):
class Square(Figure):
def color(self):
return super(Rectangle, self).color() # Square is not an instance or subclass of Rectangle
</pre>
</code></pre>
<p>As a fix, you can make the <code>Square</code> an instance of the <code>Rectangle</code> class.</p>
</body>
</html>
@@ -2,17 +2,17 @@
<body>
<p>Reports trailing semicolons in statements.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def my_func(a):
c = a ** 2;
return c
</pre>
</code></pre>
<p>IDE provides a quick-fix that removes a trailing semicolon. When you
apply it, the code changes to:</p>
<pre style="font-family: monospace">
<pre><code>
def my_func(a):
c = a ** 2
return c
</pre>
</code></pre>
</body>
</html>
@@ -3,10 +3,10 @@
<p>Reports cases when the number of expressions on the right-hand side
and targets on the left-hand side are not the same.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
t = ('red', 'blue', 'green', 'white')
(c1, c2, c3) = t
</pre>
</code></pre>
<p>As a quick-fix, you can modify the highlighted code fragment to restore the tuple
balance.</p>
</body>
@@ -1,10 +1,11 @@
<html>
<body>
<p>Reports assignments to a tuple item.</p>
<pre style="font-family: monospace">
<p><b>Example:</b></p>
<pre><code>
t = ('red', 'blue', 'green', 'white')
t[3] = 'black'
</pre>
</code></pre>
<p>A quick-fix offers to replace the tuple with a list.</p>
</body>
</html>
@@ -4,22 +4,22 @@
<p>Types of function parameters can be specified in
docstrings or in Python 3 function annotations.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
def foo() -> int:
return "abc" # Expected int, got str
a: str
a = foo() # Expected str, got int
</pre>
</code></pre>
<p>With the quick-fix, you can modify the problematic types:</p>
<pre style="font-family: monospace">
<pre><code>
def foo() -> str:
return "abc"
a: str
a = foo()
</pre>
</code></pre>
</body>
</html>
@@ -2,7 +2,7 @@
<body>
<p>Reports invalid usages of type hints.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
from typing import TypeVar
T0 = TypeVar('T1') # Argument of 'TypeVar' must be 'T0'
@@ -16,7 +16,7 @@ def b(p: int) -> int: # Type specified both in a comment and annotation
def c(p1, p2): # Type signature has too many arguments
# type: (int) -> int
pass
</pre>
</code></pre>
<p>Available quick-fixes offer various actions. You can rename, remove, or move problematic elements. You can also manually modify type declarations to ensure no warning is shown.</p>
</body>
</html>
@@ -3,7 +3,7 @@
<p>Reports invalid definition and usage of
<a href="https://www.python.org/dev/peps/pep-0589/">TypedDict</a>.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
from typing import TypedDict
@@ -20,6 +20,6 @@ m = Movie(name="name", year=1000, rate=9)
print(m["director"]) # There is no the 'director' key in 'Movie'
del m["name"] # The 'name' key cannot be deleted
m["year"] = "1001" # Expected 'int', got 'str'
</pre>
</code></pre>
</body>
</html>
@@ -2,18 +2,18 @@
<body>
<p>Reports local variables referenced before assignment.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
x = 0
if x > 10:
b = 3
print(b)
</pre>
</code></pre>
<p>The IDE reports a problem for <code>print(b)</code>. A possible fix is:</p>
<pre style="font-family: monospace">
<pre><code>
x = 0
if x > 10:
b = 3
print(b)
</pre>
</code></pre>
</body>
</html>
@@ -3,10 +3,10 @@
<p>Reports backslashes in places where line continuation is implicit inside <code>()</code>,
<code>[]</code>, and <code>{}</code>.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
a = ('first', \
'second', 'third')
</pre>
</code></pre>
<p>When the quick-fix is applied, the redundant backslash is deleted.</p>
</body>
</html>
@@ -2,12 +2,12 @@
<body>
<p>Reports code fragments that cannot be normally reached.</p>
<p><b>Example:</b></p>
<pre style="font-family: monospace">
<pre><code>
if True:
print('Yes')
else:
print('No')
</pre>
</code></pre>
<p>As a fix, you might want to check and modify the algorithm to ensure it implements
the expected logic.</p>
</body></html>