question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Explicit imports for facts

See original GitHub issue

Currently 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:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Fizzadarcommented, Jan 7, 2021

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).

1reaction
Fizzadarcommented, Apr 29, 2021

This has now been released in v1.4!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found