Explicit imports for facts
See original GitHub issueCurrently facts are loaded “by magic” into a global namespace (available via host.fact.X
). Importing a module containing a fact automatically adds it to the fact list while converting the camel cased class name into snake case. This presents a few issues:
- Potential for custom facts to override builtin facts
- Hard to understand what facts are available/loaded
- Linting/type checking hard/impossible
Potential alternative API:
from pyinfra import host
from pyinfra.facts.apt import AptSources
# Legacy
sources = host.fact.apt_sources
# New
sources = host.get_fact(AptSources)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Importing modules implicit vs explicit - python - Stack Overflow
When the sub packages are closely related, this doesn't add much information—if you imported importlib.util I won't be surprised if you call ...
Read more >Absolute vs Relative Imports in Python
There are two types of relative imports: implicit and explicit. Implicit relative imports have been deprecated in Python 3, so I won't be...
Read more >explicit relative imports (intermediate) anthony explains #298
today I talk about explicit relative imports in python -- how they work, what their syntax is, and why you might want to...
Read more >5. The import system — Python 3.11.1 documentation
There is no longer any implicit import machinery - the full import system is ... In fact, there may be multiple parent directories...
Read more >Telling Intellij to do explicit imports instead of * (Java)
I would like explicit imports instead of just condensing things into something like...import java.awt.*Very annoying when it does it even...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah yes, good point - entrypoints would work well I think. I’m not against simply removing all facts as well, I think it’s a bit of an edge case and having the explicit imports removes all the magic entirely (and makes facts consistent with external/custom operations).
This has now been released in
v1.4
!