aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2021-06-04 05:50:46 -0700
committerGravatar GitHub <[email protected]>2021-06-04 05:50:46 -0700
commit966277e3c4b27cdf31bf5d2d81e916e79ec37797 (patch)
tree79d37f447ee702d33d901454389b381109da4114
parentAdd discord.li to invite filter (#1616) (diff)
parentchore: ensmallen the star-imports tag (diff)
Merge pull request #1619 from python-discord/vcokltfre/chore/star-imports-smallening
chore: ensmallen the star-imports tag
-rw-r--r--bot/resources/tags/star-imports.md9
1 files changed, 0 insertions, 9 deletions
diff --git a/bot/resources/tags/star-imports.md b/bot/resources/tags/star-imports.md
index 2be6aab6e..3b1b6a858 100644
--- a/bot/resources/tags/star-imports.md
+++ b/bot/resources/tags/star-imports.md
@@ -16,33 +16,24 @@ Example:
>>> from math import *
>>> sin(pi / 2) # uses sin from math rather than your custom sin
```
-
• Potential namespace collision. Names defined from a previous import might get shadowed by a wildcard import.
-
• Causes ambiguity. From the example, it is unclear which `sin` function is actually being used. From the Zen of Python **[3]**: `Explicit is better than implicit.`
-
• Makes import order significant, which they shouldn't. Certain IDE's `sort import` functionality may end up breaking code due to namespace collision.
**How should you import?**
• Import the module under the module's namespace (Only import the name of the module, and names defined in the module can be used by prefixing the module's name)
-
```python
>>> import math
>>> math.sin(math.pi / 2)
```
-
• Explicitly import certain names from the module
-
```python
>>> from math import sin, pi
>>> sin(pi / 2)
```
-
Conclusion: Namespaces are one honking great idea -- let's do more of those! *[3]*
**[1]** If the module defines the variable `__all__`, the names defined in `__all__` will get imported by the wildcard import, otherwise all the names in the module get imported (except for names with a leading underscore)
-
**[2]** [Namespaces and scopes](https://www.programiz.com/python-programming/namespace)
-
**[3]** [Zen of Python](https://www.python.org/dev/peps/pep-0020/)