You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently use name mangling everywhere (self.__guild, etc.), and we even add properties that use these variables, which seems pointless:
@propertydefguild(self):
returnself.__guild
We currently have no sub classes and it therefore seems pointless to use name mangling in our use-case, see PEP 8. We should find a balance between name mangling and standard naming if we intend to extend our codebase further in the future, but for now I see no reason to use name mangling.
If your class is intended to be subclassed, and you have attributes that you do not want subclasses to use, consider naming them with double leading underscores and no trailing underscores. This invokes Python's name mangling algorithm, where the name of the class is mangled into the attribute name. This helps avoid attribute name collisions should subclasses inadvertently contain attributes with the same name.
Note 1: Note that only the simple class name is used in the mangled name, so if a subclass chooses both the same class name and attribute name, you can still get name collisions.
Note 2: Name mangling can make certain uses, such as debugging and getattr(), less convenient. However the name mangling algorithm is well documented and easy to perform manually.
Note 3: Not everyone likes name mangling. Try to balance the need to avoid accidental name clashes with potential use by advanced callers.
The text was updated successfully, but these errors were encountered:
We currently use name mangling everywhere (
self.__guild
, etc.), and we even add properties that use these variables, which seems pointless:We currently have no sub classes and it therefore seems pointless to use name mangling in our use-case, see PEP 8. We should find a balance between name mangling and standard naming if we intend to extend our codebase further in the future, but for now I see no reason to use name mangling.
The text was updated successfully, but these errors were encountered: