Beispiel #1
0
def does_contain_consecutive_underscores(name: str) -> bool:
    """
    Checks if name contains consecutive underscores in middle of name.

    >>> does_contain_consecutive_underscores('name')
    False

    >>> does_contain_consecutive_underscores('__magic__')
    False

    >>> does_contain_consecutive_underscores('__private')
    False

    >>> does_contain_consecutive_underscores('name')
    False

    >>> does_contain_consecutive_underscores('some__value')
    True

    >>> does_contain_consecutive_underscores('__some__value__')
    True

    >>> does_contain_consecutive_underscores('__private__value')
    True

    >>> does_contain_consecutive_underscores('some_value__')
    True

    """
    if access.is_magic(name) or access.is_private(name):
        return '__' in name.strip('_')
    return '__' in name
Beispiel #2
0
    def _check_module_name(self) -> None:
        if logical.is_wrong_name(self.stem, constants.MODULE_NAMES_BLACKLIST):
            self.add_violation(WrongModuleNameViolation())

        if access.is_magic(self.stem):
            if self.stem not in constants.MAGIC_MODULE_NAMES_WHITELIST:
                self.add_violation(WrongModuleMagicNameViolation())

        if access.is_private(self.stem):
            self.add_violation(PrivateNameViolation(text=self.stem))
    def _ensure_underscores(self, node: ast.AST, name: str):
        if access.is_private(name):
            self._error_callback(naming.PrivateNameViolation(node,
                                                             text=name), )

        if logical.does_contain_underscored_number(name):
            self._error_callback(
                naming.UnderscoredNumberNameViolation(node, text=name), )

        if logical.does_contain_consecutive_underscores(name):
            self._error_callback(
                naming.ConsecutiveUnderscoresInNameViolation(
                    node,
                    text=name,
                ), )
    def _check_name(self, node: ast.AST, name: str) -> None:

        if logical.is_wrong_name(name, VARIABLE_NAMES_BLACKLIST):
            self.add_violation(WrongVariableNameViolation(node, text=name))

        min_length = self.options.min_name_length
        if logical.is_too_short_name(name, min_length=min_length):
            self.add_violation(TooShortNameViolation(node, text=name))

        if access.is_private(name):
            self.add_violation(PrivateNameViolation(node, text=name))

        if logical.does_contain_underscored_number(name):
            self.add_violation(UnderscoredNumberNameViolation(node, text=name))
        if logical.does_contain_consecutive_underscores(name):
            self.add_violation(
                ConsecutiveUnderscoresInNameViolation(node, text=name),
            )