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

Update pylint to 3.1.0 #6191

Merged
merged 16 commits into from
Apr 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import subprocess

import six
import lib.datatransformer as transformer
import lib.datatransformer as transformer # pylint:disable=import-error,no-name-in-module


def main(args):
Expand Down
12 changes: 6 additions & 6 deletions contrib/packs/actions/pack_mgmt/get_pack_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def get_pack_version(pack=None):
pack_metadata = get_pack_metadata(pack_dir=pack_path)
result = pack_metadata.get("version", None)
except Exception:
result = None
finally:
return result
return None

return result


def get_dependency_list(pack=None):
Expand All @@ -138,6 +138,6 @@ def get_dependency_list(pack=None):
result = pack_metadata.get("dependencies", None)
except Exception:
print("Could not open pack.yaml at location %s" % pack_path)
result = None
finally:
return result
return None

return result
10 changes: 2 additions & 8 deletions lint-configs/python/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
[MESSAGES CONTROL]
# C0111 Missing docstring
# I0011 Warning locally suppressed using disable-msg
# I0012 Warning locally suppressed using disable-msg
# W0704 Except doesn't do anything Used when an except clause does nothing but "pass" and there is no "else" clause
# W0142 Used * or * magic* Used when a function or method is called using *args or **kwargs to dispatch arguments.
# W0212 Access to a protected member %s of a client class
# W0232 Class has no __init__ method Used when a class has no __init__ method, neither its parent classes.
# W0613 Unused argument %r Used when a function or method argument is not used.
# W0702 No exception's type specified Used when an except clause doesn't specify exceptions type to catch.
# R0201 Method could be a function
# W0614 Unused import XYZ from wildcard import
# R0914 Too many local variables
# R0912 Too many branches
Expand All @@ -18,14 +13,13 @@
# E0211: Method has no argument
# E1128: Assigning to function call which only returns None Used when an assignment is done on a function call but the inferred function returns nothing but None.
# E1129: Context manager ‘%s’ doesn’t implement __enter__ and __exit__. Used when an instance in a with statement doesn’t implement the context manager protocol(__enter__/__exit__).
disable=C0103,C0111,I0011,I0012,W0704,W0142,W0212,W0232,W0613,W0702,R0201,W0614,R0914,R0912,R0915,R0913,R0904,R0801,not-context-manager,assignment-from-none
disable=C0103,C0111,I0011,W0212,W0613,W0702,W0614,R0914,R0912,R0915,R0913,R0904,R0801,not-context-manager,assignment-from-none

[BASIC]
property-classes=abc.abstractproperty

[TYPECHECK]
# Note: This modules are manipulated during the runtime so we can't detect all the properties during
# static analysis
# Note: These modules are manipulated during the runtime so we can't detect all the properties during static analysis
# orjson has type stubs, but pylint doesn't support __init__.pyi yet: https://github.com/PyCQA/pylint/issues/2873
ignored-modules=distutils,eventlet.green.subprocess,six,six.moves,orjson

Expand Down
224 changes: 117 additions & 107 deletions lockfiles/pylint.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pylint_plugins/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python_tests(
python_requirement(
name="pylint",
requirements=[
"pylint~=2.8.2",
"pylint~=3.1.0",
"setuptools", # includes pkg_resources
],
)
Expand Down
47 changes: 41 additions & 6 deletions pylint_plugins/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Now, we return because Pylint can finally understand our API model objects without
importing them.
"""
# pylint: disable=E1120,E1125

import astroid

Expand Down Expand Up @@ -275,9 +276,21 @@ def transform(cls: nodes.ClassDef):
# Now, we can construct the AST node that we'll add to the API model class.

if property_type == "object":
node = nodes.Dict()
node = nodes.Dict(
property_data_node.lineno,
property_data_node.col_offset,
parent=property_data_node,
end_lineno=property_data_node.end_lineno,
end_col_offset=property_data_node.end_col_offset,
)
elif property_type == "array":
node = nodes.List()
node = nodes.List(
property_data_node.lineno,
property_data_node.col_offset,
parent=property_data_node,
end_lineno=property_data_node.end_lineno,
end_col_offset=property_data_node.end_col_offset,
)
elif property_type == "integer":
node = scoped_nodes.builtin_lookup("int")[1][0]
elif property_type == "number":
Expand All @@ -290,12 +303,34 @@ def transform(cls: nodes.ClassDef):
node = scoped_nodes.builtin_lookup("None")[1][0]
else:
# Unknown type
node = astroid.ClassDef(property_name, None)
node = astroid.ClassDef(
property_name,
property_data_node.lineno,
property_data_node.col_offset,
parent=property_data_node,
end_lineno=property_data_node.end_lineno,
end_col_offset=property_data_node.end_col_offset,
)

# Create a "property = node" assign node
assign_node = nodes.Assign(parent=cls)
assign_name_node = nodes.AssignName(property_name, parent=assign_node)
assign_node.postinit(targets=[assign_name_node], value=node)
assign_node = nodes.Assign(
property_name_node.lineno,
property_name_node.col_offset,
parent=cls,
end_lineno=property_data_node.end_lineno,
end_col_offset=property_data_node.end_col_offset,
)
assign_name_node = nodes.AssignName(
property_name,
property_name_node.lineno,
property_name_node.col_offset,
parent=assign_node,
end_lineno=property_name_node.end_lineno,
end_col_offset=property_name_node.end_col_offset,
)
assign_node.postinit(
targets=[assign_name_node], value=node, type_annotation=None
)

# Finally, add the property node as an attribute on the class.
cls.locals[property_name] = [assign_name_node]
Expand Down
10 changes: 9 additions & 1 deletion pylint_plugins/api_models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import pylint.checkers.typecheck
import pylint.testutils
from pylint.interfaces import Confidence

# merely importing this registers it in astroid
# so parse() will use our predicate and transform functions.
Expand Down Expand Up @@ -301,10 +302,17 @@ def test():

# accessing a property NOT defined in the schema
with self.assertAddsMessages(
pylint.testutils.Message(
pylint.testutils.MessageTest(
msg_id="no-member", # E1101
args=("Instance of", "TestAPI", "missing", ""),
node=assign_node_missing.value,
line=assign_node_missing.value.lineno,
col_offset=assign_node_missing.value.col_offset,
end_line=assign_node_missing.value.end_lineno,
end_col_offset=assign_node_missing.value.end_col_offset,
confidence=Confidence(
name="INFERENCE", description="Warning based on inference result."
),
)
):
self.checker.visit_attribute(assign_node_missing.value)
20 changes: 18 additions & 2 deletions pylint_plugins/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
Plugin which tells Pylint how to handle mongoengine document classes.
"""
# pylint: disable=E1120,E1125

import astroid

Expand All @@ -37,12 +38,27 @@ def transform(cls):
if cls.name == "StormFoundationDB":
# _fields get added automagically by mongoengine
if "_fields" not in cls.locals:
cls.locals["_fields"] = [nodes.Dict()]
cls.locals["_fields"] = [
nodes.Dict(
cls.lineno,
cls.col_offset,
parent=cls,
end_lineno=cls.end_lineno,
end_col_offset=cls.end_col_offset,
)
]

if cls.name.endswith("DB"):
# mongoengine explicitly declared "id" field on each class so we teach pylint about that
property_name = "id"
node = astroid.ClassDef(property_name, None)
node = astroid.ClassDef(
property_name,
cls.lineno,
cls.col_offset,
parent=cls,
end_lineno=cls.end_lineno,
end_col_offset=cls.end_col_offset,
)
cls.locals[property_name] = [node]


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
max-line-length = 100
target_version = ['py36']
target_version = ['py38']
include = '\.pyi?$'
exclude = '''
(
Expand Down
4 changes: 4 additions & 0 deletions st2actions/st2actions/container/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def _do_cancel(self, runner):
return runner.liveaction

def _do_pause(self, runner):
# Initialise to avoid E0601: Use before assignment.
status = result = context = None
try:
extra = {"runner": runner}
LOG.debug(
Expand Down Expand Up @@ -240,6 +242,8 @@ def _do_pause(self, runner):
return runner.liveaction

def _do_resume(self, runner):
# Initialise to avoid E0601: Use before assignment.
status = result = context = None
try:
extra = {"runner": runner}
LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def migrate_executions(start_dt: datetime.datetime, end_dt: datetime.datetime) -
if not liveaction_id:
continue

liveaction_db = None
try:
liveaction_db = LiveAction.get_by_id(liveaction_id)
except StackStormDBObjectNotFoundError:
Expand Down Expand Up @@ -262,6 +263,7 @@ def migrate_workflow_objects(
print("Will migrate %s TaskExecutionDB objects" % (objects_count))
print("")

task_execution_db = None
for index, task_execution_id in enumerate(task_execution_ids, 1):
try:
task_execution_db = TaskExecution.get_by_id(task_execution_id)
Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/services/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,6 @@ def is_action_execution_under_action_chain_context(liveaction):


def get_requester(requester):
if type(requester) == UserDB:
if isinstance(requester, UserDB):
return requester["name"]
return requester
6 changes: 4 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# 7.5 causing errors with orquesta integration tests (probably interaction w/ nose)
coverage<7.5
pep8==1.7.1
# st2flake8 does not support flake8 v5 yet
flake8==4.0.1
st2flake8==0.1.0
astroid==2.5.6
pylint==2.8.2
astroid==3.1.0
pylint==3.1.0
pylint-plugin-utils>=0.4
black==22.3.0
pre-commit==2.1.0
Expand Down
Loading