Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/PyCQA/pylint into overridde…
Browse files Browse the repository at this point in the history
…n-final-method-documentation
  • Loading branch information
mbyrnepr2 committed Apr 2, 2022
2 parents eb625d1 + ca3bc0e commit 45a7db4
Show file tree
Hide file tree
Showing 64 changed files with 671 additions and 191 deletions.
17 changes: 17 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Release date: TBA
Put new features here and also in 'doc/whatsnew/2.14.rst'


* Exclude dunder calls on super() from raising ``unnecessary-dunder-call``.

Closes #6074

* Add new check ``unnecessary-dunder-call`` for unnecessary dunder method calls.

Closes #5936
Expand All @@ -36,6 +40,12 @@ Release date: TBA

* Fix bug where specifically enabling just ``await-outside-async`` was not possible.

* The ``set_config_directly`` decorator has been removed.

* Added new message called ``duplicate-value`` which identifies duplicate values inside sets.

Closes #5880

..
Insert your changelog randomly, it will reduce merge conflicts
(Ie. not necessarily at the end)
Expand All @@ -49,6 +59,13 @@ Release date: TBA
* functions & classes which contain both a docstring and an ellipsis.
* A body which contains an ellipsis ``nodes.Expr`` node & at least one other statement.

* Fix crash for ``redefined-slots-in-subclass`` when the type of the slot is not a const or a string.

Closes #6100

* Only raise ``not-callable`` when all the inferred values of a property are not callable.

Closes #5931


What's New in Pylint 2.13.4?
Expand Down
22 changes: 12 additions & 10 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,18 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = "python_docs_theme"
html_theme = "furo"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"collapsiblesidebar": True,
"issues_url": "https://github.com/pycqa/pylint/issues/new",
"root_name": "PyCQA",
"root_url": "https://meta.pycqa.org/en/latest/",
}
# TO-DO: Disable thme options too see how Furo themes look in default config
# html_theme_options = {
# "collapsiblesidebar": True,
# "issues_url": "https://github.com/pycqa/pylint/issues/new",
# "root_name": "PyCQA",
# "root_url": "https://meta.pycqa.org/en/latest/",
# }

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
Expand Down Expand Up @@ -146,9 +147,10 @@
smartquotes = False

# Custom sidebar templates, maps document names to template names.
html_sidebars = {
"**": ["localtoc.html", "globaltoc.html", "relations.html", "sourcelink.html"]
}
# Use Default Furo Sidebar
# html_sidebars = {
# "**": ["localtoc.html", "globaltoc.html", "relations.html", "sourcelink.html"]
# }

# Additional templates that should be rendered to pages, maps page names to
# template names.
Expand Down
23 changes: 23 additions & 0 deletions doc/data/messages/a/arguments-differ/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Drink:
def mix(self, fluid_one, fluid_two):
return fluid_one + fluid_two


class Cocktail(Drink):
def mix(self, fluid_one, fluid_two, alcoholic_fluid_one): # [arguments-differ]
return fluid_one + fluid_two + alcoholic_fluid_one


class Car:
tank = 0

def fill_tank(self, gas):
self.tank += gas


class Airplane(Car):
kerosine_tank = 0

def fill_tank(self, gas, kerosine): # [arguments-differ]
self.tank += gas
self.kerosine_tank += kerosine
8 changes: 8 additions & 0 deletions doc/data/messages/a/arguments-differ/details.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
``argument-differ`` denotes an issue with the Liskov Substitution Principle.
This means that the code in question violates an important design principle which does not have
one single solution. We recommend to search online for the best solution in your case.

To give some examples of potential solutions:
- Add the argument to the parent class
- Remove the inheritance completely
- Add default arguments to the child class
24 changes: 24 additions & 0 deletions doc/data/messages/a/arguments-differ/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Drink:
def mix(self, fluid_one, fluid_two):
return fluid_one + fluid_two


class Cocktail(Drink):
def mix(self, fluid_one, fluid_two, alcoholic_fluid_one="Beer")
return fluid_one + fluid_two + alcoholic_fluid_one


class Car:
tank = 0

def fill_tank(self, gas):
self.tank += gas


class Airplane:
tank = 0
kerosine_tank = 0

def fill_tank(self, gas, kerosine):
self.tank += gas
self.kerosine_tank += kerosine
1 change: 1 addition & 0 deletions doc/data/messages/a/arguments-differ/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `Liskov Substitution Principle <https://en.wikipedia.org/wiki/Liskov_substitution_principle>`_
13 changes: 13 additions & 0 deletions doc/data/messages/a/arguments-out-of-order/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def function_3_args(first_argument, second_argument, third_argument):
"""Three arguments function"""
return first_argument, second_argument, third_argument


def args_out_of_order():
first_argument = 1
second_argument = 2
third_argument = 3

function_3_args( # [arguments-out-of-order]
first_argument, third_argument, second_argument
)
11 changes: 11 additions & 0 deletions doc/data/messages/a/arguments-out-of-order/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def function_3_args(first_argument, second_argument, third_argument):
"""Three arguments function"""
return first_argument, second_argument, third_argument


def args_out_of_order():
first_argument = 1
second_argument = 2
third_argument = 3

function_3_args(first_argument, second_argument, third_argument)
13 changes: 13 additions & 0 deletions doc/data/messages/a/arguments-renamed/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Fruit:
def brew(self, ingredient_name: str):
print(f"Brewing a {type(self)} with {ingredient_name}")

class Apple(Fruit):
...

class Orange(Fruit):
def brew(self, flavor: str): # [arguments-renamed]
print(f"Brewing an orange with {flavor}")

for fruit, ingredient_name in [[Orange(), "thyme"], [Apple(), "cinnamon"]]:
fruit.brew(ingredient_name=ingredient_name)
13 changes: 13 additions & 0 deletions doc/data/messages/a/arguments-renamed/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Fruit:
def brew(self, ingredient_name: str):
print(f"Brewing a {type(self)} with {ingredient_name}")

class Apple(Fruit):
...

class Orange(Fruit):
def brew(self, ingredient_name: str):
print(f"Brewing an orange with {ingredient_name}")

for fruit, ingredient_name in [[Orange(), "thyme"], [Apple(), "cinnamon"]]:
fruit.brew(ingredient_name=ingredient_name)
4 changes: 4 additions & 0 deletions doc/data/messages/b/broad-except/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
try:
1 / 0
except Exception: # [broad-except]
pass
4 changes: 4 additions & 0 deletions doc/data/messages/b/broad-except/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
try:
1 / 0
except ZeroDivisionError:
pass
8 changes: 8 additions & 0 deletions doc/data/messages/c/catching-non-exception/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class FooError:
pass


try:
1 / 0
except FooError: # [catching-non-exception]
pass
8 changes: 8 additions & 0 deletions doc/data/messages/c/catching-non-exception/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class FooError(Exception):
pass


try:
1 / 0
except FooError:
pass
1 change: 1 addition & 0 deletions doc/data/messages/d/duplicate-value/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
incorrect_set = {'value1', 23, 5, 'value1'} # [duplicate-value]
1 change: 1 addition & 0 deletions doc/data/messages/d/duplicate-value/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
correct_set = {'value1', 23, 5}
1 change: 1 addition & 0 deletions doc/data/messages/m/missing-format-argument-key/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("My name is {first} {last}".format(first="John")) # [missing-format-argument-key]
1 change: 1 addition & 0 deletions doc/data/messages/m/missing-format-argument-key/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("My name is {first} {last}".format(first="John", last="Wick"))
2 changes: 2 additions & 0 deletions doc/data/messages/m/missing-format-argument-key/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* `PEP 3101 <https://peps.python.org/pep-3101/>`_
* `Custom String Formmating <https://docs.python.org/3/library/string.html#custom-string-formatting>`_
7 changes: 7 additions & 0 deletions doc/data/messages/s/super-with-arguments/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Fruit:
pass


class Orange(Fruit):
def __init__(self):
super(Orange, self).__init__() # [super-with-arguments]
7 changes: 7 additions & 0 deletions doc/data/messages/s/super-with-arguments/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Fruit:
pass


class Orange(Fruit):
def __init__(self):
super().__init__()
1 change: 1 addition & 0 deletions doc/data/messages/t/too-few-format-args/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Today is {0}, so tomorrow will be {1}".format("Monday")) # [too-few-format-args]
1 change: 1 addition & 0 deletions doc/data/messages/t/too-few-format-args/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Today is {0}, so tomorrow will be {1}".format("Monday", "Tuesday"))
1 change: 1 addition & 0 deletions doc/data/messages/t/too-few-format-args/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`String Formmating <https://docs.python.org/3/library/string.html#formatstrings>`_
16 changes: 16 additions & 0 deletions doc/data/messages/t/too-many-arguments/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def three_d_chess_move( # [too-many-arguments]
x_white,
y_white,
z_white,
piece_white,
x_black,
y_black,
z_black,
piece_black,
x_blue,
y_blue,
z_blue,
piece_blue,
current_player,
):
pass
18 changes: 18 additions & 0 deletions doc/data/messages/t/too-many-arguments/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from dataclasses import dataclass


@dataclass
class ThreeDChessPiece:
x: int
y: int
z: int
type: str


def three_d_chess_move(
white: ThreeDChessPiece,
black: ThreeDChessPiece,
blue: ThreeDChessPiece,
current_player,
):
pass
1 change: 1 addition & 0 deletions doc/data/messages/t/too-many-format-args/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Today is {0}, so tomorrow will be {1}".format("Monday", "Tuesday", "Wednesday")) # [too-many-format-args]
1 change: 1 addition & 0 deletions doc/data/messages/t/too-many-format-args/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Today is {0}, so tomorrow will be {1}".format("Monday", "Tuesday"))
1 change: 1 addition & 0 deletions doc/data/messages/t/too-many-format-args/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`String Formmating <https://docs.python.org/3/library/string.html#formatstrings>`_
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Sphinx==4.5.0
python-docs-theme==2022.1
furo==2022.3.4
-e .
10 changes: 10 additions & 0 deletions doc/whatsnew/2.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ New checkers

Closes #4525

* Added new message called ``duplicate-value`` which identifies duplicate values inside sets.

Closes #5880

Removed checkers
================

Expand All @@ -38,8 +42,14 @@ Extensions
Other Changes
=============

* Only raise ``not-callable`` when all the inferred values of a property are not callable.

Closes #5931

* The concept of checker priority has been removed.

* The ``set_config_directly`` decorator has been removed.

* Fix false negative for ``no-member`` when attempting to assign an instance
attribute to itself without any prior assignment.

Expand Down
22 changes: 21 additions & 1 deletion pylint/checkers/base/basic_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pylint import interfaces
from pylint import utils as lint_utils
from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker
from pylint.interfaces import HIGH, IAstroidChecker
from pylint.reporters.ureports import nodes as reporter_nodes
from pylint.utils import LinterStats
from pylint.utils.utils import get_global_option
Expand Down Expand Up @@ -246,6 +246,11 @@ class BasicChecker(_BasicChecker):
"Used when an assert statement has a string literal as its first argument, which will "
"cause the assert to always pass.",
),
"W0130": (
"Duplicate value %r in set",
"duplicate-value",
"This message is emitted when a set contains the same value two or more times.",
),
}

reports = (("RP0101", "Statistics by type", report_by_type_stats),)
Expand Down Expand Up @@ -637,6 +642,21 @@ def visit_dict(self, node: nodes.Dict) -> None:
self.add_message("duplicate-key", node=node, args=key)
keys.add(key)

@utils.check_messages("duplicate-value")
def visit_set(self, node: nodes.Set) -> None:
"""Check duplicate value in set."""
values = set()
for v in node.elts:
if isinstance(v, nodes.Const):
value = v.value
else:
continue
if value in values:
self.add_message(
"duplicate-value", node=node, args=value, confidence=HIGH
)
values.add(value)

def visit_tryfinally(self, node: nodes.TryFinally) -> None:
"""Update try...finally flag."""
self._tryfinallys.append(node)
Expand Down
5 changes: 5 additions & 0 deletions pylint/checkers/base/docstring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class DocStringChecker(_BasicChecker):
),
)

def __init__(
self, linter=None, *, future_option_parsing: Literal[None, True] = None
):
_BasicChecker.__init__(self, linter, future_option_parsing=True)

def open(self):
self.linter.stats.reset_undocumented()

Expand Down
Loading

0 comments on commit 45a7db4

Please sign in to comment.