Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Barebones version of ImportAll #3965

Closed
HLWeil opened this issue Dec 2, 2024 · 3 comments · Fixed by #4035
Closed

[Python] Barebones version of ImportAll #3965

HLWeil opened this issue Dec 2, 2024 · 3 comments · Fixed by #4035

Comments

@HLWeil
Copy link

HLWeil commented Dec 2, 2024

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
Copy link
Author

HLWeil commented Dec 2, 2024

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.

@HLWeil HLWeil changed the title [Python] ImportAll [Python] Barebones version of ImportAll Dec 2, 2024
alfonsogarciacaro added a commit to alfonsogarciacaro/Fable that referenced this issue Feb 6, 2025
@alfonsogarciacaro
Copy link
Member

There's also importSideEffects which should have the effect you want but it was also somewhat broken, I sent #4035 to fix it

MangelMaxime pushed a commit to alfonsogarciacaro/Fable that referenced this issue Feb 9, 2025
MangelMaxime added a commit that referenced this issue Feb 9, 2025
* [Python] Fix #3965: importSideEffects shouldn't generate identifier

* [Python] Fix #3481: Resolve also paths for non-qualified imports

* [Python] Ignore backwards paths in imports & tests

* Update changelog

---------

Co-authored-by: Maxime Mangel <[email protected]>
@HLWeil
Copy link
Author

HLWeil commented Feb 11, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants