-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…9605) * Fix a false positive with ``singledispatchmethod-function`` when a method is decorated with both ``functools.singledispatchmethod`` and ``staticmethod``. Closes #9531 (cherry picked from commit 6df4e1d) Co-authored-by: Mark Byrne <[email protected]>
- Loading branch information
1 parent
cf102ff
commit 461831f
Showing
16 changed files
with
196 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
from functools import singledispatch | ||
|
||
|
||
class Board: | ||
@singledispatch | ||
@staticmethod | ||
def convert_position(position): | ||
pass | ||
@singledispatch | ||
def convert_position(position): | ||
print(position) | ||
|
||
@convert_position.register | ||
@staticmethod | ||
def _(position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register | ||
@staticmethod | ||
def _(position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" | ||
@convert_position.register | ||
def _(position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
|
||
@convert_position.register | ||
def _(position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
from functools import singledispatchmethod | ||
|
||
|
||
class Board: | ||
@singledispatchmethod # [singledispatchmethod-function] | ||
@staticmethod | ||
def convert_position(position): | ||
pass | ||
@singledispatchmethod # [singledispatchmethod-function] | ||
def convert_position(position): | ||
print(position) | ||
|
||
@convert_position.register # [singledispatchmethod-function] | ||
@staticmethod | ||
def _(position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register # [singledispatchmethod-function] | ||
@staticmethod | ||
def _(position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" | ||
@convert_position.register # [singledispatchmethod-function] | ||
def _(position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
|
||
@convert_position.register # [singledispatchmethod-function] | ||
def _(position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fix a false positive with ``singledispatchmethod-function`` when a method is decorated with both ``functools.singledispatchmethod`` and ``staticmethod``. | ||
|
||
Closes #9531 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/functional/s/singledispatch/singledispatch_method.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""Tests for singledispatch-method""" | ||
# pylint: disable=missing-class-docstring, missing-function-docstring,too-few-public-methods | ||
|
||
|
||
from functools import singledispatch | ||
|
||
|
||
class Board1: | ||
@singledispatch # [singledispatch-method] | ||
def convert_position(self, position): | ||
pass | ||
|
||
@convert_position.register # [singledispatch-method] | ||
def _(self, position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register # [singledispatch-method] | ||
def _(self, position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" | ||
|
||
|
||
class Board2: | ||
@singledispatch # [singledispatch-method] | ||
@classmethod | ||
def convert_position(cls, position): | ||
pass | ||
|
||
@convert_position.register # [singledispatch-method] | ||
@classmethod | ||
def _(cls, position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register # [singledispatch-method] | ||
@classmethod | ||
def _(cls, position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" | ||
|
||
|
||
|
||
class Board3: | ||
@singledispatch # [singledispatch-method] | ||
@staticmethod | ||
def convert_position(position): | ||
pass | ||
|
||
@convert_position.register # [singledispatch-method] | ||
@staticmethod | ||
def _(position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register # [singledispatch-method] | ||
@staticmethod | ||
def _(position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" | ||
|
||
|
||
# Do not emit `singledispatch-method`: | ||
@singledispatch | ||
def convert_position(position): | ||
print(position) | ||
|
||
@convert_position.register | ||
def _(position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register | ||
def _(position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" |
12 changes: 9 additions & 3 deletions
12
tests/functional/s/singledispatch/singledispatch_method.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
singledispatch-method:26:5:26:19:Board.convert_position:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:HIGH | ||
singledispatch-method:31:5:31:30:Board._:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:INFERENCE | ||
singledispatch-method:37:5:37:30:Board._:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:INFERENCE | ||
singledispatch-method:9:5:9:19:Board1.convert_position:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:HIGH | ||
singledispatch-method:13:5:13:30:Board1._:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:INFERENCE | ||
singledispatch-method:18:5:18:30:Board1._:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:INFERENCE | ||
singledispatch-method:24:5:24:19:Board2.convert_position:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:HIGH | ||
singledispatch-method:29:5:29:30:Board2._:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:INFERENCE | ||
singledispatch-method:35:5:35:30:Board2._:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:INFERENCE | ||
singledispatch-method:43:5:43:19:Board3.convert_position:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:HIGH | ||
singledispatch-method:48:5:48:30:Board3._:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:INFERENCE | ||
singledispatch-method:54:5:54:30:Board3._:singledispatch decorator should not be used with methods, use singledispatchmethod instead.:INFERENCE |
23 changes: 0 additions & 23 deletions
23
tests/functional/s/singledispatch/singledispatch_method_py37.py
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
tests/functional/s/singledispatch/singledispatch_method_py37.rc
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
tests/functional/s/singledispatch/singledispatch_method_py37.txt
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
tests/functional/s/singledispatch/singledispatch_method_py38.py
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
tests/functional/s/singledispatch/singledispatch_method_py38.txt
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
tests/functional/s/singledispatch/singledispatchmethod_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Tests for singledispatchmethod-function""" | ||
# pylint: disable=missing-class-docstring, missing-function-docstring,too-few-public-methods | ||
|
||
|
||
from functools import singledispatchmethod | ||
|
||
|
||
# Emit `singledispatchmethod-function` when functions are decorated with `singledispatchmethod` | ||
@singledispatchmethod # [singledispatchmethod-function] | ||
def convert_position2(position): | ||
print(position) | ||
|
||
@convert_position2.register # [singledispatchmethod-function] | ||
def _(position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position2.register # [singledispatchmethod-function] | ||
def _(position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" | ||
|
||
|
||
class Board1: | ||
@singledispatchmethod | ||
def convert_position(self, position): | ||
pass | ||
|
||
@convert_position.register | ||
def _(self, position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register | ||
def _(self, position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" | ||
|
||
|
||
class Board2: | ||
@singledispatchmethod | ||
@staticmethod | ||
def convert_position(position): | ||
pass | ||
|
||
@convert_position.register | ||
@staticmethod | ||
def _(position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register | ||
@staticmethod | ||
def _(position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" | ||
|
||
|
||
class Board3: | ||
@singledispatchmethod | ||
@classmethod | ||
def convert_position(cls, position): | ||
pass | ||
|
||
@convert_position.register | ||
@classmethod | ||
def _(cls, position: str) -> tuple: | ||
position_a, position_b = position.split(",") | ||
return (int(position_a), int(position_b)) | ||
|
||
@convert_position.register | ||
@classmethod | ||
def _(cls, position: tuple) -> str: | ||
return f"{position[0]},{position[1]}" |
3 changes: 3 additions & 0 deletions
3
tests/functional/s/singledispatch/singledispatchmethod_function.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
singledispatchmethod-function:9:1:9:21:convert_position2:singledispatchmethod decorator should not be used with functions, use singledispatch instead.:HIGH | ||
singledispatchmethod-function:13:1:13:27:_:singledispatchmethod decorator should not be used with functions, use singledispatch instead.:INFERENCE | ||
singledispatchmethod-function:18:1:18:27:_:singledispatchmethod decorator should not be used with functions, use singledispatch instead.:INFERENCE |
Oops, something went wrong.