class ClassChecker(BaseChecker): (source)
Checker for class nodes. Checks for : * methods without self as first argument * overridden methods signature * access only to existent members via self * attributes not defined in the __init__ method * unreachable code
Method | __init__ |
Checker instances should have the linter as argument. |
Method | leave |
Checker for Class nodes. |
Method | leave |
On method node, check if this method couldn't be a function. |
Method | open |
Called before visiting project (i.e. set of modules). |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Check if the getattr is an access to a class member if so, register it. |
Method | visit |
Init visit variable _accessed. |
Method | visit |
Check method arguments, overriding. |
Class Variable | name |
Name of the provider. |
Class Variable | options |
Options provided by this provider. |
Static Method | _is |
Returns true if the node is located inside a special (aka dunder) method. |
Static Method | _is |
Check if the given attribute *name* is a class or instance member of the given *klass*. |
Static Method | _is |
Check if the given *func* node is a class method. |
Static Method | _is |
Check if the inferred value of the given *expr* is an instance of *klass*. |
Method | _check |
Check that accessed members are defined. |
Method | _check |
Undocumented |
Method | _check |
Check that the given class node implements abstract methods from base classes. |
Method | _check |
Checks for uses of classmethod() or staticmethod(). |
Method | _check |
Detect that a class has a consistent mro or duplicate bases. |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Check the name of first argument, expect:. |
Method | _check |
Check that the given AssignAttr node is defined in the class slots. |
Method | _check |
Check that the __init__ method call super or ancestors'__init__ method (unless it is used for type hinting with `typing.overload`). |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Detect that a class inherits something which is not a class or a type. |
Method | _check |
Undocumented |
Method | _check |
Given an attribute access node (set or get), check if attribute access is legitimate. |
Method | _check |
Check if `node` redefines a slot which is defined in an ancestor class. |
Method | _check |
Check that the signature of the two given methods match. |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Check if there is a function call on a super call without brackets. |
Method | _check |
Detect that a class does not subclass a class decorated with `typing.final`. |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Check if private variables are never used within a class. |
Method | _check |
Check if the given function node is an useless method override. |
Method | _is |
Check if nodes.Name corresponds to first attribute variable name. |
Method | _is |
Undocumented |
Method | _uses |
Check that attribute lookup name use first attribute variable name. |
Instance Variable | _accessed |
Undocumented |
Instance Variable | _first |
Undocumented |
Instance Variable | _mixin |
Undocumented |
Instance Variable | _py38 |
Undocumented |
Property | _dummy |
Undocumented |
Inherited from BaseChecker
:
Method | __eq__ |
Permit to assert Checkers are equal. |
Method | __gt__ |
Sorting of checkers. |
Method | __hash__ |
Make Checker hashable. |
Method | __repr__ |
Undocumented |
Method | __str__ |
This might be incomplete because multiple classes inheriting BaseChecker can have the same name. |
Method | add |
Undocumented |
Method | check |
Check the consistency of msgid. |
Method | close |
Called after visiting project (i.e set of modules). |
Method | create |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | reduce |
Undocumented |
Class Variable | enabled |
Undocumented |
Class Variable | msgs |
Undocumented |
Class Variable | reports |
Undocumented |
Instance Variable | linter |
Undocumented |
Property | messages |
Undocumented |
Inherited from _ArgumentsProvider
(via BaseChecker
):
Method | get |
DEPRECATED: Return the dictionary defining an option given its name. |
Method | level |
Undocumented |
Method | load |
DEPRECATED: Initialize the provider using default values. |
Method | option |
DEPRECATED: Get the config attribute corresponding to opt. |
Method | option |
DEPRECATED: Get the current value for the given option. |
Method | options |
DEPRECATED. |
Method | options |
DEPRECATED: Return an iterator on options grouped by section. |
Method | set |
DEPRECATED: Method called to set an option (registered in the options list). |
Class Variable | option |
Option groups of this provider and their descriptions. |
Property | config |
Undocumented |
Property | level |
Undocumented |
Instance Variable | _arguments |
The manager that will parse and register any options provided. |
Instance Variable | _level |
Undocumented |
pylint.checkers.BaseChecker.__init__
Checker instances should have the linter as argument.
def leave_classdef(self, node:
nodes.ClassDef
):
(source)
¶
Checker for Class nodes. check that instance attributes are defined in __init__ and check access to existent members
On method node, check if this method couldn't be a function. ignore class, static and abstract methods, initializer, methods overridden from a parent class.
def visit_assign(self, assign_node:
nodes.Assign
):
(source)
¶
Undocumented
def visit_assignattr(self, node:
nodes.AssignAttr
):
(source)
¶
Undocumented
Check if the getattr is an access to a class member if so, register it. Also check for access to protected class member from outside its class (but ignore __special__ methods)
def visit_classdef(self, node:
nodes.ClassDef
):
(source)
¶
Init visit variable _accessed.
def _is_class_or_instance_attribute(name:
str
, klass: nodes.ClassDef
) -> bool
:
(source)
¶
Check if the given attribute *name* is a class or instance member of the given *klass*. Returns ``True`` if the name is a property in the given klass, ``False`` otherwise.
def _is_inferred_instance(expr:
nodes.NodeNG
, klass: nodes.ClassDef
) -> bool
:
(source)
¶
Check if the inferred value of the given *expr* is an instance of *klass*.
nodes.ClassDef
, accessed: dict[ str, list[ _AccessNodes]]
):
(source)
¶
Check that accessed members are defined.
Checks for uses of classmethod() or staticmethod(). When a @classmethod or @staticmethod decorator should be used instead. A message will be emitted only if the assignment is at a class scope and only if the classmethod's argument belongs to the class where it is defined. `node` is an assign node.
str|None
, config: Sequence[ str]
, node: nodes.FunctionDef
, message: str
, method_name: str
):
(source)
¶
Undocumented
Check the name of first argument, expect:. * 'self' for a regular method * 'cls' for a class method or a metaclass regular method (actually valid-classmethod-first-arg value) * 'mcs' for a metaclass class method (actually valid-metaclass-classmethod-first-arg) * not one of the above for a static method
Check that the __init__ method call super or ancestors'__init__ method (unless it is used for type hinting with `typing.overload`).
nodes.FunctionDef
, parent_function_node: nodes.FunctionDef
):
(source)
¶
Undocumented
Given an attribute access node (set or get), check if attribute access is legitimate. Call _check_first_attr with node before calling this method. Valid cases are: * self._attr in a method or cls._attr in a classmethod. Checked by _check_first_attr. * Klass._attr inside "Klass" class. * Klass2._attr inside "Klass" class when Klass2 is a base class of Klass.
nodes.ClassDef
, slots_node: nodes.NodeNG
, slots_list: list[ nodes.NodeNG]
):
(source)
¶
Check if `node` redefines a slot which is defined in an ancestor class.
nodes.FunctionDef
, refmethod: nodes.FunctionDef
, cls: nodes.ClassDef
):
(source)
¶
Check that the signature of the two given methods match.
Check if the given function node is an useless method override. We consider it *useless* if it uses the super() builtin, but having nothing additional whatsoever than not implementing the method at all. If the method uses super() to delegate an operation to the rest of the MRO, and if the method called is the same as the current one, the arguments passed to super() are the same as the parameters that were passed to this method, then the method could be removed altogether, by letting other implementation to take precedence.
Check if nodes.Name corresponds to first attribute variable name. Name is `self` for method, `cls` for classmethod and `mcs` for metaclass. Static methods return False.
(nodes.Attribute|nodes.Assign)|nodes.AssignAttr
) -> bool
:
(source)
¶
Check that attribute lookup name use first attribute variable name. Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.