feat: support `typing.Any`

This commit is contained in:
Shunsuke Shibayama 2024-10-04 16:07:40 +09:00
parent ec539b013f
commit d650569de6
2 changed files with 8 additions and 1 deletions

View File

@ -124,8 +124,9 @@ pylyzer converts Python ASTs to Erg ASTs and passes them to Erg's type checker.
* [x] `Optional`
* [x] `Literal`
* [x] `Callable`
* [ ] `TypedDict`
* [x] `Any`
* [x] `TypeVar`
* [ ] `TypedDict`
* [ ] `ClassVar`
* [ ] `Generic`
* [ ] `Protocol`

View File

@ -1077,6 +1077,12 @@ impl ASTConverter {
py_ast::Expr::Attribute(attr) => {
let namespace = Box::new(self.convert_expr(*attr.value));
let t = self.convert_ident(attr.attr.to_string(), attr_name_loc(&namespace));
if namespace
.get_name()
.is_some_and(|n| n == "typing" && t.inspect() == "Any")
{
return TypeSpec::PreDeclTy(PreDeclTypeSpec::Mono(t));
}
let predecl = PreDeclTypeSpec::Attr { namespace, t };
TypeSpec::PreDeclTy(predecl)
}