How to use the libcst._nodes.base.CSTValidationError function in libcst

To help you get started, we’ve selected a few libcst examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Instagram / LibCST / libcst / _nodes / expression.py View on Github external
def _validate(self) -> None:
        if self.keyword is None and isinstance(self.equal, AssignEqual):
            raise CSTValidationError(
                "Must have a keyword when specifying an AssignEqual."
            )
        if self.star not in ("", "*", "**"):
            raise CSTValidationError("Must specify either '', '*' or '**' for star.")
        if self.star in ("*", "**") and self.keyword is not None:
            raise CSTValidationError("Cannot specify a star and a keyword together.")
github Instagram / LibCST / libcst / _nodes / statement.py View on Github external
def _validate(self) -> None:
        name = self.name
        if self.type is None and name is not None:
            raise CSTValidationError("Cannot have a name for an empty type.")
        if name is not None and not isinstance(name.name, Name):
            raise CSTValidationError(
                "Must use a Name node for AsName name inside ExceptHandler."
            )
        if self.type is not None and self.whitespace_after_except.empty:
            raise CSTValidationError(
                "Must have at least one space after except when ExceptHandler has a type."
            )
github Instagram / LibCST / libcst / _nodes / expression.py View on Github external
def _validate_defaults(self) -> None:
        for param in self.params:
            if param.default is not None:
                raise CSTValidationError(
                    "Cannot have defaults for params. Place them in default_params."
                )
        for param in self.default_params:
            if param.default is None:
                raise CSTValidationError(
                    "Must have defaults for default_params. Place non-defaults in params."
                )
        star_arg = self.star_arg
        if isinstance(star_arg, Param) and star_arg.default is not None:
            raise CSTValidationError("Cannot have default for star_arg.")
        star_kwarg = self.star_kwarg
        if star_kwarg is not None and star_kwarg.default is not None:
            raise CSTValidationError("Cannot have default for star_kwarg.")
github Instagram / LibCST / libcst / _nodes / expression.py View on Github external
def _validate(self) -> None:
        super(Imaginary, self)._validate()
        if not re.fullmatch(IMAGNUMBER_RE, self.value):
            raise CSTValidationError("Number is not a valid imaginary.")
github Instagram / LibCST / libcst / _nodes / statement.py View on Github external
def _validate_module(self) -> None:
        if self.module is None and len(self.relative) == 0:
            raise CSTValidationError(
                "Must have a module specified if there is no relative import."
            )
github Instagram / LibCST / libcst / _nodes / expression.py View on Github external
def _validate(self) -> None:
        super(Name, self)._validate()
        if len(self.value) == 0:
            raise CSTValidationError("Cannot have empty name identifier.")
        if not self.value.isidentifier():
            raise CSTValidationError("Name is not a valid identifier.")
github Instagram / LibCST / libcst / _nodes / statement.py View on Github external
def _validate_names(self) -> None:
        names = self.names
        if isinstance(names, Sequence):
            if len(names) == 0:
                raise CSTValidationError(
                    "An ImportFrom must have at least one ImportAlias"
                )
            for name in names[:-1]:
                if name.comma is None:
                    raise CSTValidationError("Non-final ImportAliases require a comma")
            if self.lpar is not None and self.rpar is None:
                raise CSTValidationError("Cannot have left paren without right paren.")
            if self.lpar is None and self.rpar is not None:
                raise CSTValidationError("Cannot have right paren without left paren.")
        if isinstance(names, ImportStar):
            if self.lpar is not None or self.rpar is not None:
                raise CSTValidationError(
                    "An ImportFrom using ImportStar cannot have parens"
                )
github Instagram / LibCST / libcst / _nodes / expression.py View on Github external
# pyre-ignore Pyre seems to think star_kwarg.star.__eq__ is not callable
            and star_arg.star != "*"
        ):
            raise CSTValidationError(
                "Expecting a star prefix of '*' for star_arg Param."
            )
        if len(self.kwonly_params) > 0:
            self._validate_stars_sequence(self.kwonly_params, section="kwonly_params")
        star_kwarg = self.star_kwarg
        if (
            star_kwarg is not None
            and isinstance(star_kwarg.star, str)
            # pyre-ignore Pyre seems to think star_kwarg.star.__eq__ is not callable
            and star_kwarg.star != "**"
        ):
            raise CSTValidationError(
                "Expecting a star prefix of '**' for star_kwarg Param."
            )
github Instagram / LibCST / libcst / _nodes / expression.py View on Github external
"""

        if arg.keyword is not None:
            # Valid, keyword argument
            return None
        elif arg.star == "**":
            # Valid, kwargs
            return None
        elif arg.star == "*":
            # Invalid, cannot have "*" follow "**"
            raise CSTValidationError(
                "Cannot have iterable argument unpacking after keyword argument unpacking."
            )
        else:
            # Invalid, cannot have positional argument follow **/keyword
            raise CSTValidationError(
                "Cannot have positional argument after keyword argument unpacking."
            )