mirror of https://github.com/mtshiba/pylyzer
Update gen_decl.rs
This commit is contained in:
parent
a088185612
commit
679a2fdadd
|
|
@ -2177,6 +2177,7 @@ impl ASTConverter {
|
||||||
imports.push(VarRecordAttr::new(true_name, alias));
|
imports.push(VarRecordAttr::new(true_name, alias));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let no_import = imports.is_empty();
|
||||||
let attrs = VarRecordAttrs::new(imports);
|
let attrs = VarRecordAttrs::new(imports);
|
||||||
let pat = VarRecordPattern::new(Token::DUMMY, attrs, Token::DUMMY);
|
let pat = VarRecordPattern::new(Token::DUMMY, attrs, Token::DUMMY);
|
||||||
let var = VarSignature::new(VarPattern::Record(pat), None);
|
let var = VarSignature::new(VarPattern::Record(pat), None);
|
||||||
|
|
@ -2184,7 +2185,9 @@ impl ASTConverter {
|
||||||
Signature::Var(var),
|
Signature::Var(var),
|
||||||
DefBody::new(EQUAL, Block::new(vec![call]), DefId(0)),
|
DefBody::new(EQUAL, Block::new(vec![call]), DefId(0)),
|
||||||
));
|
));
|
||||||
if exprs.is_empty() {
|
if no_import {
|
||||||
|
Expr::Dummy(Dummy::new(None, exprs))
|
||||||
|
} else if exprs.is_empty() {
|
||||||
def
|
def
|
||||||
} else {
|
} else {
|
||||||
exprs.push(def);
|
exprs.push(def);
|
||||||
|
|
|
||||||
|
|
@ -70,10 +70,9 @@ impl DeclFileGenerator {
|
||||||
.ident()
|
.ident()
|
||||||
.inspect()
|
.inspect()
|
||||||
.replace('\0', "")
|
.replace('\0', "")
|
||||||
.replace('%', "___");
|
.replace(['%', '*'], "___");
|
||||||
let ref_t = def.sig.ident().ref_t();
|
let ref_t = def.sig.ident().ref_t();
|
||||||
let typ = ref_t.replace_failure().to_string_unabbreviated();
|
let typ = escape_type(ref_t.replace_failure().to_string_unabbreviated());
|
||||||
let typ = escape_type(typ);
|
|
||||||
// Erg can automatically import nested modules
|
// Erg can automatically import nested modules
|
||||||
// `import http.client` => `http = pyimport "http"`
|
// `import http.client` => `http = pyimport "http"`
|
||||||
let decl = if ref_t.is_py_module() {
|
let decl = if ref_t.is_py_module() {
|
||||||
|
|
@ -104,14 +103,19 @@ impl DeclFileGenerator {
|
||||||
.ident()
|
.ident()
|
||||||
.inspect()
|
.inspect()
|
||||||
.replace('\0', "")
|
.replace('\0', "")
|
||||||
.replace('%', "___");
|
.replace(['%', '*'], "___");
|
||||||
let src = format!("{}.{class_name}", self.namespace);
|
let src = format!("{}.{class_name}", self.namespace);
|
||||||
let stash = std::mem::replace(&mut self.namespace, src);
|
let stash = std::mem::replace(&mut self.namespace, src);
|
||||||
let decl = format!(".{class_name}: ClassType");
|
let decl = format!(".{class_name}: ClassType");
|
||||||
self.code += &decl;
|
self.code += &decl;
|
||||||
self.code.push('\n');
|
self.code.push('\n');
|
||||||
if let GenTypeObj::Subclass(class) = &def.obj {
|
if let GenTypeObj::Subclass(class) = &def.obj {
|
||||||
let sup = class.sup.as_ref().typ().to_string_unabbreviated();
|
let sup = class
|
||||||
|
.sup
|
||||||
|
.as_ref()
|
||||||
|
.typ()
|
||||||
|
.replace_failure()
|
||||||
|
.to_string_unabbreviated();
|
||||||
let sup = escape_type(sup);
|
let sup = escape_type(sup);
|
||||||
let decl = format!(".{class_name} <: {sup}\n");
|
let decl = format!(".{class_name} <: {sup}\n");
|
||||||
self.code += &decl;
|
self.code += &decl;
|
||||||
|
|
@ -122,7 +126,7 @@ impl DeclFileGenerator {
|
||||||
}) = def.obj.base_or_sup()
|
}) = def.obj.base_or_sup()
|
||||||
{
|
{
|
||||||
for (attr, t) in rec.iter() {
|
for (attr, t) in rec.iter() {
|
||||||
let typ = escape_type(t.to_string_unabbreviated());
|
let typ = escape_type(t.replace_failure().to_string_unabbreviated());
|
||||||
let decl = format!("{}.{}: {typ}\n", self.namespace, attr.symbol);
|
let decl = format!("{}.{}: {typ}\n", self.namespace, attr.symbol);
|
||||||
self.code += &decl;
|
self.code += &decl;
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +137,7 @@ impl DeclFileGenerator {
|
||||||
}) = def.obj.additional()
|
}) = def.obj.additional()
|
||||||
{
|
{
|
||||||
for (attr, t) in rec.iter() {
|
for (attr, t) in rec.iter() {
|
||||||
let typ = escape_type(t.to_string_unabbreviated());
|
let typ = escape_type(t.replace_failure().to_string_unabbreviated());
|
||||||
let decl = format!("{}.{}: {typ}\n", self.namespace, attr.symbol);
|
let decl = format!("{}.{}: {typ}\n", self.namespace, attr.symbol);
|
||||||
self.code += &decl;
|
self.code += &decl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import export
|
import export
|
||||||
import foo
|
import foo
|
||||||
|
from . import foo
|
||||||
from foo import bar
|
from foo import bar
|
||||||
from foo import baz
|
from foo import baz
|
||||||
import random
|
import random
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue