I read PEP 8 for to know whether (an imaginary) me creating an object with a name such as __foo__
is a good idea or not. PEP 8 says this about __double_leading_and_trailing_underscore__
:
Never invent such names; only use them as documented.
My question is: who?
I am a programmer. I write an API for other programmers. Python was implemented by programmers. The language reference for the implementation was written by programmers or at least ex-programmers, and the programmers using my API will write something that may or may not be used by further programmers.
Now this unfolded, which programmer is PEP 8 speaking of when they say, "Never invent such names"?
Someone is obviously encouraged to invent such names, since they exist, while others are uninvited to do so.
Which group of programmers should "Never invent such names" ?
You are discouraged from using such names in your APIs, yes, because if and when the Python core developers pick the same name for Python itself, you'll lose out, your API can break.
So, if you are not a Python core developer or writing a PEP that may be one day become part of the Python standard library or core language definition, try to stay away from using dunder names in your API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With