2 ms·
It would be interesting to compare this with an alternative based on static analysis. The Python ecosystem has many standard tools nowadays to enforce consiste
by gorgoiler 2y ago
It would be interesting to compare this with an alternative based on static analysis.
The Python ecosystem has many standard tools nowadays to enforce consistent style, including how modules import each other. The ast and libcst modules are very fast and can quickly identify any imported symbols beginning with an underscore:
from a import _naughty
It’s also quite possible to build a list of symbols that were imported and ensure that their underscore-prefixed attributes are not accessed:
import a
a._naughty()
You could get creative I suppose…
import a
f = next(
getattr(a, f“_{s}”)
for s in synonyms(“cheeky”)
)
f()
…but at that point one hopes that, as a last resort, ones reviewers would cry foul.