style: add more pylint checks and update code for them

This commit is contained in:
arcanis committed 2026-11-18 10:36:19 +02:00
1 parent 4f839a7e6a
commit 36b7972b26
211 files changed
+951 -955

No files matched your search

@@ -30,24 +30,24 @@ class MethodType(StrEnum):
method type enumeration
Attributes:
Class(MethodType): (class attribute) class method
Delete(MethodType): (class attribute) destructor-like methods
Init(MethodType): (class attribute) initialization method
Magic(MethodType): (class attribute) other magical methods
New(MethodType): (class attribute) constructor method
Normal(MethodType): (class attribute) usual method
Property(MethodType): (class attribute) property method
Static(MethodType): (class attribute) static method
CLASS(MethodType): (class attribute) class method
DELETE(MethodType): (class attribute) destructor-like methods
INIT(MethodType): (class attribute) initialization method
MAGIC(MethodType): (class attribute) other magical methods
NEW(MethodType): (class attribute) constructor method
NORMAL(MethodType): (class attribute) usual method
PROPERTY(MethodType): (class attribute) property method
STATIC(MethodType): (class attribute) static method
"""
Class = "classmethod"
Delete = "del"
Init = "init"
Magic = "magic"
New = "new"
Normal = "regular"
Property = "property"
Static = "staticmethod"
CLASS = "classmethod"
DELETE = "del"
INIT = "init"
MAGIC = "magic"
NEW = "new"
NORMAL = "regular"
PROPERTY = "property"
STATIC = "staticmethod"
class DefinitionOrder(BaseRawFileChecker):
@@ -59,14 +59,14 @@ class DefinitionOrder(BaseRawFileChecker):
"""
DECORATED_METHODS_ORDER = {
"cached_property": MethodType.Property,
"classmethod": MethodType.Class,
"property": MethodType.Property,
"staticmethod": MethodType.Static,
"cached_property": MethodType.PROPERTY,
"classmethod": MethodType.CLASS,
"property": MethodType.PROPERTY,
"staticmethod": MethodType.STATIC,
}
msgs = {
"W6001": (
"E5101": (
"Invalid method order %s, expected %s",
"methods-out-of-order",
"Methods are defined out of recommended order.",
@@ -126,11 +126,11 @@ class DefinitionOrder(BaseRawFileChecker):
"""
# init methods
if function.name in ("__init__", "__post_init__"):
return MethodType.Init
return MethodType.INIT
if function.name in ("__new__",):
return MethodType.New
return MethodType.NEW
if function.name in ("__del__",):
return MethodType.Delete
return MethodType.DELETE
# decorated methods
decorators = []
@@ -142,10 +142,10 @@ class DefinitionOrder(BaseRawFileChecker):
# magic methods
if function.name.startswith("__") and function.name.endswith("__"):
return MethodType.Magic
return MethodType.MAGIC
# normal method
return MethodType.Normal
return MethodType.NORMAL
def check_class(self, clazz: nodes.ClassDef) -> None:
"""
+12 -12
View File
@@ -33,15 +33,15 @@ class ImportType(StrEnum):
Future(MethodTypeOrder): (class attribute) from __future__ import
Package(MethodTypeOrder): (class attribute) package import
PackageFrom(MethodTypeOrder): (class attribute) package import, from clause
System(ImportType): (class attribute) system installed packages
SYSTEM(ImportType): (class attribute) system installed packages
SystemFrom(MethodTypeOrder): (class attribute) system installed packages, from clause
"""
Future = "future"
Package = "package"
PackageFrom = "package-from"
System = "system"
SystemFrom = "system-from"
FUTURE = "future"
PACKAGE = "package"
PACKAGE_FROM = "package-from"
SYSTEM = "system"
SYSTEM_FROM = "system-from"
class ImportOrder(BaseRawFileChecker):
@@ -50,17 +50,17 @@ class ImportOrder(BaseRawFileChecker):
"""
msgs = {
"W6002": (
"E5201": (
"Invalid import order %s, expected before %s",
"imports-out-of-order",
"Imports are defined out of recommended order.",
),
"W6003": (
"E5202": (
"Import contains more than one package: %s",
"multiple-package-imports",
"Multiple package imports are not allowed.",
),
"W6004": (
"E5203": (
"Invalid from import order %s, expected %s",
"from-imports-out-of-order",
"From imports are defined out of recommended order.",
@@ -157,17 +157,17 @@ class ImportOrder(BaseRawFileChecker):
match statement:
case nodes.ImportFrom() if statement.modname == "__future__":
import_name = statement.modname
import_type = ImportType.Future
import_type = ImportType.FUTURE
case nodes.ImportFrom():
import_name = statement.modname
root, *_ = import_name.split(".", maxsplit=1)
import_type = ImportType.PackageFrom if root_package == root else ImportType.SystemFrom
import_type = ImportType.PACKAGE_FROM if root_package == root else ImportType.SYSTEM_FROM
# check from import itself
self.check_from_imports(statement)
case nodes.Import():
import_name = next(name for name, _ in statement.names)
root, *_ = import_name.split(".", maxsplit=1)
import_type = ImportType.Package if root_package == root else ImportType.System
import_type = ImportType.PACKAGE if root_package == root else ImportType.SYSTEM
# check import itself
self.check_package_imports(statement)
case _: