Skip to content

Commit c24f62a

Browse files
committed
Merge branch 'main' of https://github.com/PyCQA/pylint into false_positive_type_checking
2 parents 2fc8fda + 8d13dbe commit c24f62a

File tree

18 files changed

+188
-10
lines changed

18 files changed

+188
-10
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
1+
This error was raised when we encountered an unexpected value type in a toml
2+
configuration between pylint 2.12 and pylint 2.14 (before the argparse refactor).

doc/data/messages/b/bad-configuration-section/good.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/data/messages/p/parse-error/good.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
def fifty_percent_off(whole):
2+
return (float(whole)) * 50 / 100
3+
4+
5+
def calculate_sum_and_display_price_of_fruits(*fruits): # [too-complex]
6+
# McCabe rating is 13 here (by default 10)
7+
shopping_list = []
8+
9+
if "apple" in fruits:
10+
v = fifty_percent_off(1.1)
11+
shopping_list.append(v)
12+
if "pear" in fruits:
13+
shopping_list.append(0.8)
14+
if "banana" in fruits:
15+
shopping_list.append(1.2)
16+
if "mango" in fruits:
17+
shopping_list.append(3.5)
18+
if "peach" in fruits:
19+
shopping_list.append(0.5)
20+
if "melon" in fruits:
21+
shopping_list.append(4.9)
22+
if "orange" in fruits:
23+
shopping_list.append(2.0)
24+
if "strawberry" in fruits:
25+
shopping_list.append(2.5)
26+
if "mandarin" in fruits:
27+
shopping_list.append(2.3)
28+
if "plum" in fruits:
29+
shopping_list.append(0.5)
30+
if "watermelon" in fruits:
31+
v = fifty_percent_off(6.4)
32+
shopping_list.append(v)
33+
34+
combine = zip(fruits, shopping_list)
35+
36+
for i in combine:
37+
print(f"{i[0]} ${i[1]:.2f}")
38+
39+
total = sum(shopping_list)
40+
print(f"Total price is ${total:.2f}")
41+
42+
43+
fruits_to_buy = ["apple", "orange", "watermelon"]
44+
calculate_sum_and_display_price_of_fruits(*fruits_to_buy)

doc/data/messages/t/too-complex/details.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1-
# This is a placeholder for correct code for this message.
1+
FRUIT_PRICES = {
2+
"apple": 1.1,
3+
"pear": 0.8,
4+
"banana": 1.2,
5+
"mango": 3.5,
6+
"peach": 0.5,
7+
"melon": 4.9,
8+
"orange": 2.0,
9+
"strawberry": 2.5,
10+
"mandarin": 2.3,
11+
"plum": 0.5,
12+
"watermelon": 6.4,
13+
}
14+
DISCOUNTED_FRUITS = ["apple", "watermelon"]
15+
16+
17+
def fifty_percent_off(whole):
18+
return (float(whole)) * 50 / 100
19+
20+
21+
def get_price(fruit):
22+
full_price = FRUIT_PRICES.get(fruit)
23+
if fruit in DISCOUNTED_FRUITS:
24+
return fifty_percent_off(full_price)
25+
else:
26+
return full_price
27+
28+
29+
def display_fruit_and_price(fruits):
30+
for fruit in fruits:
31+
print(f"{fruit} ${get_price(fruit) :.2f}")
32+
33+
34+
def get_total(fruits):
35+
return sum(get_price(f) for f in fruits)
36+
37+
38+
fruits_to_buy = ["apple", "orange", "watermelon"]
39+
display_fruit_and_price(fruits_to_buy)
40+
print(f"Total price is ${get_total(fruits_to_buy):.2f}")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[main]
2+
3+
load-plugins=pylint.extensions.mccabe
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f"python {3.5} is past end of life" # [using-f-string-in-unsupported-version]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
1+
f-strings were introduced in Python version 3.6; to use them, please use a more recent version of Python.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# This is a placeholder for correct code for this message.
1+
"python {} is past end of life".format(3.5)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[main]
2+
py-version=3.5

doc/exts/pylint_messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ def _write_redirect_old_page(
414414
)
415415
content = f""".. _{old_name[0]}:
416416
417-
{get_rst_title("/".join(old_name), "=")}
418-
"{old_name[0]} has been renamed. The new message can be found at:
417+
{get_rst_title(" / ".join(old_name), "=")}
418+
'{old_name[0]}' has been renamed. The new message can be found at:
419419
420420
.. toctree::
421421
:maxdepth: 2

doc/whatsnew/2/2.16/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ Last but not least @clavedeluna and @nickdrozd became triagers, welcome to the t
3232

3333
.. towncrier release notes start
3434
35+
What's new in Pylint 2.16.1?
36+
----------------------------
37+
Release date: 2023-02-02
38+
39+
40+
Other Bug Fixes
41+
---------------
42+
43+
- Fix a crash happening for python interpreter < 3.9 following a failed typing
44+
update.
45+
46+
Closes #8161 (`#8161 <https://github.com/PyCQA/pylint/issues/8161>`_)
47+
48+
3549
What's new in Pylint 2.16.0?
3650
----------------------------
3751
Release date: 2023-02-01

tests/functional/ext/typing/redundant_typehint_argument.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
""""Checks for redundant Union typehints in assignments"""
2-
# pylint: disable=deprecated-typing-alias,consider-alternative-union-syntax,consider-using-alias
2+
# pylint: disable=deprecated-typing-alias,consider-alternative-union-syntax,consider-using-alias,invalid-name,unused-argument,missing-function-docstring
33

44
from __future__ import annotations
55
from typing import Union, Optional, Sequence
@@ -19,3 +19,16 @@
1919
ANSWER_10: dict | list[int] | float | str | int | bool = 10
2020
# +1: [redundant-typehint-argument]
2121
ANSWER_11: list[int] | dict[int] | dict[list[int]] | list[str] | list[str] = ['string']
22+
23+
# Multiple warnings for the same repeated type
24+
# +1: [redundant-typehint-argument, redundant-typehint-argument, redundant-typehint-argument]
25+
x: int | int | int | int
26+
27+
# No warning for redundant types in compound type (yet !)
28+
z: dict[int | int, str | str]
29+
30+
# +1: [redundant-typehint-argument]
31+
zz: dict[int | int, str | str] | dict[int | int, str | str]
32+
33+
# No warnings for redundant types in function signature (yet !)
34+
def f(p: int | int) -> str | str: ...

tests/functional/ext/typing/redundant_typehint_argument.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ redundant-typehint-argument:16:0:16:82::Type `list[str]` is used more than once
77
redundant-typehint-argument:17:0:17:23::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
88
redundant-typehint-argument:18:0:18:43::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
99
redundant-typehint-argument:21:0:21:87::Type `list[str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
10+
redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
11+
redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
12+
redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
13+
redundant-typehint-argument:31:0:31:59::Type `dict[int | int, str | str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
""""Checks for redundant Union typehints in assignments"""
2+
# pylint: disable=deprecated-typing-alias,consider-alternative-union-syntax,consider-using-alias,invalid-name,unused-argument,missing-function-docstring
3+
4+
from __future__ import annotations
5+
from typing import Union, Optional, Sequence
6+
7+
# +1: [redundant-typehint-argument, redundant-typehint-argument]
8+
ANSWER_0: Union[int, int, str, bool, float, str] = 0
9+
ANSWER_1: Optional[int] = 1
10+
ANSWER_2: Sequence[int] = [2]
11+
ANSWER_3: Union[list[int], str, int, bool, list[int]] = 3 # [redundant-typehint-argument]
12+
ANSWER_4: Optional[None] = None # [redundant-typehint-argument]
13+
ANSWER_5: Optional[list[int]] = None
14+
ANSWER_6: Union[None, None] = None # [redundant-typehint-argument]
15+
# +1: [redundant-typehint-argument]
16+
ANSWER_7: Union[list[int], dict[int], dict[list[int]], list[str], list[str]] = [7]
17+
ANSWER_8: int | int = 8 # [redundant-typehint-argument]
18+
ANSWER_9: str | int | None | int | bool = 9 # [redundant-typehint-argument]
19+
ANSWER_10: dict | list[int] | float | str | int | bool = 10
20+
# +1: [redundant-typehint-argument]
21+
ANSWER_11: list[int] | dict[int] | dict[list[int]] | list[str] | list[str] = ['string']
22+
23+
# Multiple warnings for the same repeated type
24+
# +1: [redundant-typehint-argument, redundant-typehint-argument, redundant-typehint-argument]
25+
x: int | int | int | int
26+
27+
# No warning for type alias (yet !)
28+
Q = int | int
29+
QQ = Q | Q
30+
31+
q: Q | Q # [redundant-typehint-argument]
32+
33+
# No warning for redundant types in compound type (yet !)
34+
z: dict[int | int, str | str]
35+
36+
# +1: [redundant-typehint-argument]
37+
zz: dict[int | int, str | str] | dict[int | int, str | str]
38+
39+
# No warnings for redundant types in function signature (yet !)
40+
def f(p: int | int) -> str | str: ...
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[main]
2+
py-version=3.10
3+
load-plugins=pylint.extensions.typing
4+
5+
[testoptions]
6+
min_pyver=3.10
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
redundant-typehint-argument:8:0:8:52::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
2+
redundant-typehint-argument:8:0:8:52::Type `str` is used more than once in union type annotation. Remove redundant typehints.:HIGH
3+
redundant-typehint-argument:11:0:11:57::Type `list[int]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
4+
redundant-typehint-argument:12:10:12:24::Type `None` is used more than once in union type annotation. Remove redundant typehints.:HIGH
5+
redundant-typehint-argument:14:0:14:34::Type `None` is used more than once in union type annotation. Remove redundant typehints.:HIGH
6+
redundant-typehint-argument:16:0:16:82::Type `list[str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
7+
redundant-typehint-argument:17:0:17:23::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
8+
redundant-typehint-argument:18:0:18:43::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
9+
redundant-typehint-argument:21:0:21:87::Type `list[str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
10+
redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
11+
redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
12+
redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
13+
redundant-typehint-argument:31:0:31:8::Type `Q` is used more than once in union type annotation. Remove redundant typehints.:HIGH
14+
redundant-typehint-argument:37:0:37:59::Type `dict[int | int, str | str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH

0 commit comments

Comments
 (0)