Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to pylint v3 #46

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
os: ["macos-11", ubuntu-20.04, "windows-latest"]
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- name: Setup python
Expand Down
5 changes: 1 addition & 4 deletions perflint/comprehension_checker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from astroid import nodes
from pylint.checkers import BaseChecker
from pylint.checkers import utils as checker_utils
from pylint.interfaces import IAstroidChecker
from astroid.helpers import safe_infer


Expand All @@ -10,8 +9,6 @@ class ComprehensionChecker(BaseChecker):
Check for comprehension usage
"""

__implements__ = IAstroidChecker

name = "comprehension-checker"
priority = -1
msgs = {
Expand All @@ -35,7 +32,7 @@ class ComprehensionChecker(BaseChecker):
def visit_for(self, node: nodes.For):
pass

@checker_utils.check_messages(
@checker_utils.only_required_for_messages(
"use-list-comprehension", "use-dict-comprehension", "use-list-copy"
)
def leave_for(self, node: nodes.For):
Expand Down
25 changes: 10 additions & 15 deletions perflint/for_loop_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from astroid.helpers import safe_infer
from pylint.checkers import BaseChecker
from pylint.checkers import utils as checker_utils
from pylint.interfaces import IAstroidChecker

iterable_types = (
nodes.Tuple,
Expand Down Expand Up @@ -52,8 +51,6 @@ class ForLoopChecker(BaseChecker):
Check for poor for-loop usage.
"""

__implements__ = IAstroidChecker

name = "for-loop-checker"
priority = -1
msgs = {
Expand All @@ -69,7 +66,7 @@ class ForLoopChecker(BaseChecker):
),
}

@checker_utils.check_messages(
@checker_utils.only_required_for_messages(
"unnecessary-list-cast", "incorrect-dictionary-iterator"
)
def visit_for(self, node: nodes.For) -> None:
Expand Down Expand Up @@ -130,8 +127,6 @@ class LoopInvariantChecker(BaseChecker):
Check for poor for-loop usage.
"""

__implements__ = IAstroidChecker

name = "loop-invariant-checker"
priority = -1
msgs = {
Expand Down Expand Up @@ -170,7 +165,7 @@ def __init__(self, linter=None):
self._loop_consts: List[List[nodes.Const]] = []
self._ignore: List[nodes.NodeNG] = []

@checker_utils.check_messages("loop-invariant-statement")
@checker_utils.only_required_for_messages("loop-invariant-statement")
def visit_for(self, node: nodes.For) -> None:
"""Visit for loop bodies."""
self._loop_level += 1
Expand All @@ -184,7 +179,7 @@ def visit_for(self, node: nodes.For) -> None:
self._loop_consts.append([])
self._ignore.append(node.iter)

@checker_utils.check_messages("loop-invariant-statement")
@checker_utils.only_required_for_messages("loop-invariant-statement")
def visit_while(self, node: nodes.While) -> None:
"""Visit while loop bodies."""
self._loop_level += 1
Expand Down Expand Up @@ -214,11 +209,11 @@ def visit_dict(self, node: nodes.Dict) -> None:
):
self._ignore.append(node)

@checker_utils.check_messages("loop-invariant-statement")
@checker_utils.only_required_for_messages("loop-invariant-statement")
def leave_for(self, node: nodes.For) -> None:
self._leave_loop(node)

@checker_utils.check_messages("loop-invariant-statement")
@checker_utils.only_required_for_messages("loop-invariant-statement")
def leave_while(self, node: nodes.While) -> None:
self._leave_loop(node)

Expand Down Expand Up @@ -303,7 +298,7 @@ def visit_augassign(self, node: nodes.AugAssign) -> None:
if isinstance(node.target, nodes.AssignName):
self._loop_assignments[-1].add(node.target.name)

@checker_utils.check_messages("loop-global-usage")
@checker_utils.only_required_for_messages("loop-global-usage")
def visit_name(self, node: nodes.Name) -> None:
"""Look for global names"""
if self._loop_names:
Expand Down Expand Up @@ -338,12 +333,12 @@ def visit_call(self, node: nodes.Call) -> None:
if isinstance(node.func.expr, nodes.Name):
self._loop_assignments[-1].add(node.func.expr.name)

@checker_utils.check_messages("loop-try-except-usage")
def visit_tryexcept(self, node: nodes.TryExcept) -> None:
@checker_utils.only_required_for_messages("loop-try-except-usage")
def visit_tryexcept(self, node: nodes.Try) -> None:
if self._loop_level > 0:
self.add_message("loop-try-except-usage", node=node)

@checker_utils.check_messages("memoryview-over-bytes")
@checker_utils.only_required_for_messages("memoryview-over-bytes")
def visit_subscript(self, node: nodes.Subscript) -> None:
if self._loop_level == 0:
return
Expand All @@ -360,7 +355,7 @@ def visit_subscript(self, node: nodes.Subscript) -> None:
):
self.add_message("memoryview-over-bytes", node=node)

@checker_utils.check_messages("dotted-import-in-loop")
@checker_utils.only_required_for_messages("dotted-import-in-loop")
def visit_attribute(self, node: nodes.Attribute) -> None:
if self._loop_level == 0:
return
Expand Down
7 changes: 2 additions & 5 deletions perflint/list_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
from astroid import nodes
from pylint.checkers import BaseChecker
from pylint.checkers import utils as checker_utils
from pylint.interfaces import IAstroidChecker


class ListChecker(BaseChecker):
"""
Check for inefficient list usage
"""

__implements__ = IAstroidChecker

name = 'list-checker'
priority = -1
msgs = {
Expand Down Expand Up @@ -42,14 +39,14 @@ def _raise_for_scope(self):
for _assignment in _lists.values():
self.add_message("use-tuple-over-list", node=_assignment.parent.value)

@checker_utils.check_messages("use-tuple-over-list")
@checker_utils.only_required_for_messages("use-tuple-over-list")
def leave_module(self, node: nodes.Module):
self._raise_for_scope()

def visit_functiondef(self, node: nodes.FunctionDef):
self._lists_to_watch.append({})

@checker_utils.check_messages("use-tuple-over-list")
@checker_utils.only_required_for_messages("use-tuple-over-list")
def leave_functiondef(self, node: nodes.FunctionDef):
self._raise_for_scope()

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ authors = [{name = "Anthony Shaw"}]
readme = "README.md"
classifiers = ["License :: OSI Approved :: MIT License"]
dynamic = ["version", "description"]
dependencies = ["pylint >= 2.12.0, < 3.0"]
dependencies = ["pylint >=3.0.0,<4.0.0"]
requires-python = ">=3.8"

[project.urls]
Home = "https://github.com/tonybaloney/perflint"
Expand Down
Loading