fable-compiler / Fable

F# to JavaScript, TypeScript, Python, Rust and Dart Compiler
http://fable.io/
MIT License
2.93k stars 301 forks source link

[Python] Barebones version of ImportAll #3965

Open HLWeil opened 2 hours ago

HLWeil commented 2 hours ago

Description

I would like to just import the shutil module in python so I can use it in an emit statement somewhere in my code. The problem is I can't seem to get the example from the documentation to work.

Repro code`

REPL

Best case would be if I could just write something like this

[<ImportAll("shutil")>]
let shutil : unit -> unit = nativeOnly

and get

import shutil

but instead I don't get any import statement at all.

So I add a call to the import "function" (as seen in #3481).

[<ImportAll("shutil")>]
let shutil : unit -> unit = nativeOnly
shutil()

Now I get the import statement, but unfortunately also the call which fails, as you can't call a module:

import shutil

shutil()

Related information

HLWeil commented 2 hours ago

Also found

importAll "shutil"

which returns

import shutil
shutil

Also looks a bit weird, but it doesn't fail so I'll go with it now.