Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use dunder instance attributes or methods #9

Open
peterbe opened this issue Apr 22, 2019 · 0 comments
Open

Don't use dunder instance attributes or methods #9

peterbe opened this issue Apr 22, 2019 · 0 comments

Comments

@peterbe
Copy link
Contributor

peterbe commented Apr 22, 2019

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

class MyKeyCDNAPI(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'

class Api:
     def __init__(self, api_key, endpoint=ENDPOINT):
          self.api_key = api_key
          self.endpoint = endpoint

    ... 
    def get(...):
    def post(...):
    def put(...):
    def delete(...):

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants