diff --git a/README.md b/README.md index 2c8a4d7..36284f7 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ pylyzer converts Python ASTs to Erg ASTs and passes them to Erg's type checker. * [ ] others * [x] type assertion (`typing.cast`) * [x] type narrowing (`is`, `isinstance`) +* [ ] `pyi` (stub) files support --- diff --git a/crates/py2erg/convert.rs b/crates/py2erg/convert.rs index 1a7daa7..2ce5734 100644 --- a/crates/py2erg/convert.rs +++ b/crates/py2erg/convert.rs @@ -947,7 +947,22 @@ impl ASTConverter { self.convert_ident_type_spec(name.id.to_string(), name.location()) } py_ast::Expr::Constant(cons) => { - self.convert_ident_type_spec("NoneType".into(), cons.location()) + if cons.value.is_none() { + self.convert_ident_type_spec("NoneType".into(), cons.location()) + } else if let Some(name) = cons.value.as_str() { + self.convert_ident_type_spec(name.into(), cons.location()) + } else { + let err = CompileError::syntax_error( + self.cfg.input.clone(), + line!() as usize, + pyloc_to_ergloc(cons.range()), + self.cur_namespace(), + format!("{:?} is not a type", cons.value), + None, + ); + self.errs.push(err); + Self::gen_dummy_type_spec(cons.location()) + } } py_ast::Expr::Attribute(attr) => { let namespace = Box::new(self.convert_expr(*attr.value)); diff --git a/tests/class.py b/tests/class.py index 40ae684..ee31761 100644 --- a/tests/class.py +++ b/tests/class.py @@ -19,6 +19,8 @@ class C: return self.x def id(self) -> Self: return self + def id2(self) -> "C": + return self c = C(1, 2) assert c.x == 1