コード例 #1
0
    def _ensure_length(self, node: ast.AST, name: str) -> None:
        min_length = self._options.min_name_length
        if logical.is_too_short_name(name, min_length=min_length):
            self._error_callback(naming.TooShortNameViolation(node, text=name))

        max_length = self._options.max_name_length
        if logical.is_too_long_name(name, max_length=max_length):
            self._error_callback(naming.TooLongNameViolation(node, text=name))
コード例 #2
0
    def _check_module_name_length(self) -> None:
        min_length = self.options.min_name_length
        if logical.is_too_short_name(self.stem, min_length=min_length):
            self.add_violation(naming.TooShortNameViolation(text=self.stem))
        elif not constants.MODULE_NAME_PATTERN.match(self.stem):
            self.add_violation(naming.WrongModuleNamePatternViolation())

        max_length = self.options.max_name_length
        if logical.is_too_long_name(self.stem, max_length=max_length):
            self.add_violation(naming.TooLongNameViolation(text=self.stem))
コード例 #3
0
def is_vague_import(name: str) -> bool:
    """
    Tells whether this import name is vague or not.

    >>> is_vague_import('a')
    True

    >>> is_vague_import('from_model')
    True

    >>> is_vague_import('dumps')
    True

    >>> is_vague_import('regular')
    False

    """
    blacklisted = name in constants.VAGUE_IMPORTS_BLACKLIST
    with_from_or_to = (name.startswith('from_') or name.startswith('to_'))
    too_short = logical.is_too_short_name(name, 2, trim=True)
    return blacklisted or with_from_or_to or too_short