Mar-02-2023, 06:35 PM
This is so weird. Just a day or two ago there was another thread wondering if there was a way to clump together imports so they are all done at once. I am so averse to changing anything in builtins that it didn't occure to me that adding import objects to builtins would do exactly what he wanted. That still doesn't stop it from being a REALLY BAD IDEA.
file imports.py
file imports.py
import math, builtins # As long as I am doing bad things builtins.math = mathfile test.py
import imports # Only need to do this once. Now math is in builtins print(math.cos(math.pi))
Output:-1
This works. After math gets added to builtins, other files don't even have to import "imports". If I set this up as a package, I could pollute the builtins namespace inside an __init__.py file and make it even harder to track down when math was promoted to a builtin. This not only creates confusion when anyone reads your code, it also hamstrings nice programming tools like autocomplete, snippets and kite. pylance hates the code: 'imprts' imported but not used, 'math' is not defined.