X Tutup
Skip to content

Use explicit keyword arguments #424

@jsmnbom

Description

@jsmnbom

Currently we have the following in our style guide:

It's always good to not initialize optional arguments at class creation, instead use **kwargs to get them. It's well known Telegram API can change without notice, in that case if a new argument is added it won't break the API classes.

The issue with this is that many IDEs and text editors do not properly support autocompletion and other features when the keywords are not defined at class creation, which can be quite frustrating.

While per the style guide the following might be bad:

# BAD
def __init__(self, id, name, last_name=''):
   self.last_name = last_name

There's no need to go the full mile and use:

# GOOD
def __init__(self, id, name, **kwargs):
   self.last_name = kwargs.get('last_name', '')

Instead we could do something akin to:

# BETTER??
def __init__(self, id, name, last_name='', **kwargs):
    self.last_name = last_name

This would still allow new arguments from the api without breaking, and optional arguments work exactly the same too, unless @jh0ker and me misunderstood something along the way...

Thanks to @PeterZhizhin (telegram) who brought this matter up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup