mirror of https://github.com/mtshiba/pylyzer
feat: string literal type (forward reference)
This commit is contained in:
parent
dcae47070a
commit
6e88efebe8
|
|
@ -134,6 +134,7 @@ pylyzer converts Python ASTs to Erg ASTs and passes them to Erg's type checker.
|
||||||
* [ ] others
|
* [ ] others
|
||||||
* [x] type assertion (`typing.cast`)
|
* [x] type assertion (`typing.cast`)
|
||||||
* [x] type narrowing (`is`, `isinstance`)
|
* [x] type narrowing (`is`, `isinstance`)
|
||||||
|
* [ ] `pyi` (stub) files support
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -947,7 +947,22 @@ impl ASTConverter {
|
||||||
self.convert_ident_type_spec(name.id.to_string(), name.location())
|
self.convert_ident_type_spec(name.id.to_string(), name.location())
|
||||||
}
|
}
|
||||||
py_ast::Expr::Constant(cons) => {
|
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) => {
|
py_ast::Expr::Attribute(attr) => {
|
||||||
let namespace = Box::new(self.convert_expr(*attr.value));
|
let namespace = Box::new(self.convert_expr(*attr.value));
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ class C:
|
||||||
return self.x
|
return self.x
|
||||||
def id(self) -> Self:
|
def id(self) -> Self:
|
||||||
return self
|
return self
|
||||||
|
def id2(self) -> "C":
|
||||||
|
return self
|
||||||
|
|
||||||
c = C(1, 2)
|
c = C(1, 2)
|
||||||
assert c.x == 1
|
assert c.x == 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue