def _check_protected_import_from_members( self, node: ast.ImportFrom, ) -> None: for alias in node.names: if access.is_protected(alias.name): self._error_callback(ProtectedModuleMemberViolation(node))
def _check_protected_import(self, node: ast.Import) -> None: names: Iterable[str] = chain.from_iterable([ alias.name.split(_MODULE_MEMBERS_SEPARATOR) for alias in node.names ]) for name in names: if access.is_protected(name): self._error_callback(ProtectedModuleViolation(node, text=name))
def _check_protected_import(self, node: ast.Import) -> None: names: Iterable[str] = chain.from_iterable( [alias.name.split('.') for alias in node.names], ) for name in names: if access.is_protected(name): self._error_callback(ProtectedModuleViolation(node))
def _check_used_variables( self, local_variables: Dict[str, List[LocalVariable]], ) -> None: for varname, usages in local_variables.items(): for node in usages: if access.is_protected(varname) or varname == UNUSED_VARIABLE: self.add_violation( UnusedVariableIsUsedViolation(node, text=varname), )
def _ideal_order(self, first: str) -> int: if first == '__new__': return 4 # highest priority if first == '__init__': return 3 if access.is_protected(first): return 1 if access.is_private(first): return 0 # lowest priority return 2 # public and magic methods
def _ensure_used_variables( self, local_variables: Mapping[str, List[_LocalVariable]], ) -> None: for varname, usages in local_variables.items(): for node in usages: if access.is_protected(varname): self.add_violation( naming.UnusedVariableIsUsedViolation( node, text=varname, ), )
def _ideal_order(self, first: str) -> int: base_methods_order = { '__new__': 5, # highest priority '__init__': 4, '__call__': 3, } public_and_magic_methods_priority = 2 if access.is_protected(first): return 1 if access.is_private(first): return 0 # lowest priority return base_methods_order.get(first, public_and_magic_methods_priority)
def _check_assign_unused( self, node: ast.AST, all_names: Iterable[str], *, is_local: bool = True, ) -> None: all_names = list(all_names) # we are using it twice all_unused = all( is_local if access.is_protected(vn) else access.is_unused(vn) for vn in all_names) if all_names and all_unused: self.add_violation( naming.UnusedVariableIsDefinedViolation( node, text=', '.join(all_names), ), )
def check_protected_import(self, node: AnyImport) -> None: import_names = [alias.name for alias in node.names] for name in chain(imports.get_import_parts(node), import_names): if access.is_protected(name): self._error_callback(ProtectedModuleViolation(node))
def _check_protected_import_from_module(self, node: ast.ImportFrom) -> None: for name in imports.get_import_parts(node): if access.is_protected(name): self._error_callback(ProtectedModuleViolation(node, text=name))
def _check_protected_attribute(self, node: ast.Attribute) -> None: if access.is_protected(node.attr): self._ensure_attribute_type(node, ProtectedAttributeViolation)