Skip to content

Commit

Permalink
Merge pull request #49 from bcl/master-pylint-3
Browse files Browse the repository at this point in the history
A couple updates for pylint 3.0
  • Loading branch information
vojtechtrefny authored Oct 2, 2023
2 parents ababfae + 093c9a1 commit cc4deea
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
10 changes: 4 additions & 6 deletions pocketlint/checkers/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
import astroid

from pylint.checkers import BaseChecker
from pylint.checkers.utils import check_messages, safe_infer
from pylint.interfaces import IAstroidChecker
from pylint.checkers.utils import only_required_for_messages, safe_infer

import os


class EnvironChecker(BaseChecker):
__implements__ = (IAstroidChecker,)
name = "environ"
msgs = {"W9940" : ("Found potentially unsafe modification of environment",
"environment-modify",
Expand All @@ -51,7 +49,7 @@ def _is_environ(self, node):

return False

@check_messages("environment-modify")
@only_required_for_messages("environment-modify")
def visit_assign(self, node):
if not isinstance(node, astroid.Assign):
return
Expand All @@ -64,7 +62,7 @@ def visit_assign(self, node):
if self._is_environ(target.value):
self.add_message("environment-modify", node=node)

@check_messages("environment-modify")
@only_required_for_messages("environment-modify")
def visit_call(self, node):
# Check both for uses of os.putenv and os.setenv and modifying calls
# to the os.environ object, such as os.environ.update
Expand All @@ -90,7 +88,7 @@ def visit_call(self, node):
function_node.name in ("clear", "pop", "popitem", "setdefault", "update"):
self.add_message("environment-modify", node=node)

@check_messages("environment-modify")
@only_required_for_messages("environment-modify")
def visit_delete(self, node):
if not isinstance(node, astroid.Delete):
return
Expand Down
16 changes: 5 additions & 11 deletions pocketlint/checkers/intl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
from pylint.checkers import BaseChecker
from pylint.checkers.strings import StringFormatChecker
from pylint.checkers.logging import LoggingChecker
from pylint.checkers.utils import check_messages
from pylint.interfaces import IAstroidChecker
from pylint.checkers.utils import only_required_for_messages

from copy import copy

Expand Down Expand Up @@ -57,7 +56,6 @@ def _get_message_strings(node):


class IntlChecker(BaseChecker):
__implements__ = (IAstroidChecker, )
name = "internationalization"
msgs = {"W9901": ("Found % in a call to a _() method",
"found-percent-in-_",
Expand All @@ -67,7 +65,7 @@ class IntlChecker(BaseChecker):
"Calling _ at the module or class level results in translations to the wrong language")
}

@check_messages("found-percent-in-_")
@only_required_for_messages("found-percent-in-_")
def visit_binop(self, node):
if node.op != "%":
return
Expand All @@ -80,7 +78,7 @@ def visit_binop(self, node):

curr = curr.parent

@check_messages("found-_-in-module-class")
@only_required_for_messages("found-_-in-module-class")
def visit_call(self, node):
# The first test skips internal functions like getattr.
if isinstance(node.func, astroid.Name) and node.func.name == "_":
Expand All @@ -90,16 +88,14 @@ def visit_call(self, node):

# Extend LoggingChecker to check translated logging strings
class IntlLoggingChecker(LoggingChecker):
__implements__ = (IAstroidChecker,)

name = 'intl-logging'
msgs = {'W9903': ("Fake message for translated E/W120* checks",
"translated-log",
"This message is not emitted itself, but can be used to control the display of \
logging format messages extended for translated strings")
}

@check_messages('translated-log')
@only_required_for_messages('translated-log')
def visit_call(self, node):
if len(node.args) >= 1 and isinstance(node.args[0], astroid.Call) and \
getattr(node.args[0].func, "name", "") in translationMethods:
Expand All @@ -123,16 +119,14 @@ def __init__(self, *args, **kwargs):

# Extend StringFormatChecker to check translated format strings
class IntlStringFormatChecker(StringFormatChecker):
__implements__ = (IAstroidChecker,)

name = 'intl-string'
msgs = {'W9904': ("Fake message for translated E/W130* checks",
"translated-format",
"This message is not emitted itself, but can be used to control the display of \
string format messages extended for translated strings")
}

@check_messages('translated-format')
@only_required_for_messages('translated-format')
def visit_binop(self, node):
if node.op != '%':
return
Expand Down
6 changes: 2 additions & 4 deletions pocketlint/checkers/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import astroid

from pylint.checkers import BaseChecker
from pylint.checkers.utils import check_messages
from pylint.interfaces import IAstroidChecker
from pylint.checkers.utils import only_required_for_messages

import xml.etree.ElementTree as ET

Expand All @@ -37,7 +36,6 @@


class MarkupChecker(BaseChecker):
__implements__ = (IAstroidChecker,)
name = "pango-markup"
msgs = {"W9920" : ("Found invalid pango markup",
"invalid-markup",
Expand Down Expand Up @@ -73,7 +71,7 @@ def _validate_pango_markup_string(self, node, string):
def __init__(self, linter=None):
BaseChecker.__init__(self, linter)

@check_messages("invalid-markup", "invalid-markup-element", "unescaped-markup", "unnecessary-markup")
@only_required_for_messages("invalid-markup", "invalid-markup-element", "unescaped-markup", "unnecessary-markup")
def visit_const(self, node):
if not isinstance(node.value, (str, bytes)):
return
Expand Down
8 changes: 2 additions & 6 deletions pocketlint/checkers/pointless-override.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import astroid

from pylint.checkers import BaseChecker
from pylint.checkers.utils import check_messages
from pylint.interfaces import IAstroidChecker
from pylint.checkers.utils import only_required_for_messages


class PointlessData(object, metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -241,9 +240,6 @@ class D(B,C):
The analysis is both incomplete and unsound because it expects that
assignments will always be made by means of the same syntax.
"""

__implements__ = (IAstroidChecker,)

name = "pointless class attribute override checker"
msgs = {
"W9951":
Expand All @@ -260,7 +256,7 @@ class D(B,C):
)
}

@check_messages("W9951", "W9952")
@only_required_for_messages("W9951", "W9952")
def visit_class(self, node):
for checker in (PointlessAssignment, PointlessFunctionDefinition):
for (name, value) in checker.get_data(node):
Expand Down
6 changes: 2 additions & 4 deletions pocketlint/checkers/preconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@
import astroid

from pylint.checkers import BaseChecker
from pylint.checkers.utils import check_messages
from pylint.interfaces import IAstroidChecker
from pylint.checkers.utils import only_required_for_messages


class PreconfChecker(BaseChecker):
__implements__ = (IAstroidChecker, )
name = "Yum preconf"
msgs = {"W9910": ("Accessing yum.preconf outside of _resetYum",
"bad-preconf-access",
"Accessing yum.preconf outside of _resetYum will cause tracebacks"),
}

@check_messages("bad-preconf-access")
@only_required_for_messages("bad-preconf-access")
def visit_getattr(self, node):
if node.attrname == "preconf":
if not isinstance(node.scope(), astroid.FunctionDef) or not node.scope().name == "_resetYum":
Expand Down

0 comments on commit cc4deea

Please sign in to comment.