コード例 #1
0
    def validate(self) -> None:
        """
        Validate parsed module.

        Finds duplicated names.
        Finds conflicts with reserved Python words.
        """
        names = set()
        for name in (
            *(i.name for i in self.typed_dicts),
            *(i.name for i in self.literals),
            *(i.name for i in self.waiters),
            *(i.name for i in self.paginators),
            *(self.service_resource.get_all_names() if self.service_resource else []),
        ):
            if is_reserved(name):
                raise ValueError(f"{name} is a reserved keyword")
            if name in names:
                for typed_dict in self.typed_dicts:
                    if typed_dict.name == name:
                        self.logger.warning(
                            f"{typed_dict}: {[c.render() for c in typed_dict.children]}"
                        )
                raise ValueError(f"Duplicate name {name}")
            names.add(name)
コード例 #2
0
 def _find_name(self, name: str) -> str:
     # FIXME: hack for APIGWv2
     if name == "__stringType":
         children_name = "".join(sorted(f"{i[0].upper()}{i[1:]}" for i in self.children))
         return f"{children_name}Type"
     if is_reserved(name):
         return f"{name}Type"
     return name
コード例 #3
0
    def import_name(self) -> str:
        """
        Safe mudule import name.
        """
        name = self.name.replace("-", "_")
        if is_reserved(name):
            return f"{name}_"

        return name
コード例 #4
0
 def test_is_reserved(self) -> None:
     assert is_reserved("lambda")
     assert is_reserved("List")
     assert is_reserved("dict")
     assert not is_reserved("myname")