https://pantsbuild.org/ logo
#development
Title
# development
b

bitter-ability-32190

01/03/2022, 1:29 AM
Why does
importlib.import_module("a.module")
go in the "string imports" bucket, but
__import__("a.module")
not?
Is it just harder to identify because you'd techincally have to look for: •
import importlib
...
importlib.import_module
from importlib import import_module
...
import_module
from importlib import import_module as imp_mod
...
imp_mod
h

hundreds-father-404

01/03/2022, 1:50 AM
it should make no difference. String imports literally just analyze every string using Python's AST Are you sure it's
a.module
in both cases? You may need to play with this option: https://www.pantsbuild.org/docs/reference-python-infer#section-string-imports-min-dots
b

bitter-ability-32190

01/03/2022, 2:02 AM
I'm asking just because I'm using this as prior art for another feature 🤓
❤️ 1
h

happy-kitchen-89482

01/03/2022, 5:08 AM
Are you saying that we treat
__import__
the same as
import
, so its arg is treated like a literal import instead of a string import?
I forget how that code goes
h

happy-kitchen-89482

01/03/2022, 10:26 AM
Ah right
I think we did that because it's commonly used in
__init__.py
files
So I don't think there's a strong reason we didn't do the same for
importlib.import_module
other than it's not commonly used
If there was a need, those could be considered "real" imports
b

bitter-ability-32190

01/03/2022, 1:53 PM
I assume the only case it'd be catching is either string imports are off, or the module name doesn't meet the min dots requirement