Skip to content

Don't use dunder instance attributes or methods #9

Description

@peterbe

Class instance attributes called __dunder_name are not override'able. For example, you can't do this:

classMyKeyCDNAPI(keycdn.Api):
def__execute(self, *a, **k): # Never gets called!blablabla

As a point, why are any of them private at all? What's the point of hiding things like __api_key? Why not just call it api_key. Then you don't need the setter or the getter. E.g.:

ENDPOINT='https://api.keycdn.com'classApi:
def__init__(self, api_key, endpoint=ENDPOINT):
self.api_key=api_keyself.endpoint=endpoint
... defget(...):
defpost(...):
defput(...):
defdelete(...):
def_execute(self, call, **params): # the only one that makes sense to make private
...
a=Api(MY_API_KEY)
print(a.endpoint)
print(a.api_key)
a.api_key=MY_OTHER_API_KEY

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions