Exemple #1
0
    def parse_class_by_jedi_name(self, jedi_name: Name) -> ParsedClass:
        """
        To parse a class definition by its Jedi Name.

        Args:
            jedi_name: the Jedi Name of the target class to parse

        Returns:
            The parsed class in ParsedClass
        """
        # case of being the object class
        if jedi_name.full_name == 'builtins.object':
            return PARSED_OBJECT_CLASS
        # case of a class not defined by a recognised script, so external class
        if not jedi_name.module_path:
            return ParsedPackageClass(jedi_name)
        # case of a custom class definition, which should have a dot-separate
        # full name starting with the full name of the module/script, and its
        # type should be `class`. There is case that the first condition is
        # satisfied but the second not, like a type alias definition/assignment
        # has a type `statement`.
        # use `class_name.goto()[0]` to fetch the full content Jedi Name which
        # has the `full_name` field
        if jedi_name.goto()[0].full_name.startswith(
                jedi_name.module_name) and jedi_name.type == 'class':
            return ParsedCustomClass(jedi_name, self)
        else:
            return ParsedPackageClass(jedi_name)
Exemple #2
0
    def _is_original_class(class_name: Name, script_context: Name) -> bool:
        """
        To check if a jedi Name is an originally defined class in a script.

        Args:
            class_name: the Name of the target class
            script_context: the context of the target script

        Returns:
            `True` if the class is an originally defined class or `False`
            otherwise
        """
        if not script_context.module_name:
            return class_name.type == 'class'
        # use `class_name.goto()[0]` to fetch the full content Jedi Name which
        # has the `full_name` field
        return class_name.type == 'class' and \
            class_name.goto()[0].full_name.startswith(
                script_context.module_name
            )