Skip to content

Commit

Permalink
fix: type decl generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Nov 30, 2024
1 parent fa4cefd commit 4c57e6e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/py2erg/gen_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,23 @@ impl DeclFileGenerator {
fn escape_type(&self, typ: String) -> String {
typ.replace('%', "Type_")
.replace("<module>", "")
.replace('/', ".")
.trim_start_matches(self.filename.trim_end_matches(".d.er"))
.trim_start_matches(&self.namespace)
.to_string()
}

// e.g. `x: foo.Bar` => `foo = pyimport "foo"; x: foo.Bar`
fn prepare_using_type(&mut self, typ: &Type) {
let namespace = Str::rc(typ.namespace().split('.').next().unwrap());
let namespace = Str::rc(
typ.namespace()
.split('/')
.next()
.unwrap()
.split('.')
.next()
.unwrap(),
);
if namespace != self.namespace
&& !namespace.is_empty()
&& self.imported.insert(namespace.clone())
Expand Down

0 comments on commit 4c57e6e

Please sign in to comment.