X Tutup
Skip to content

Commit 2471eaa

Browse files
committed
Adding some style commandments
1 parent 6bfdff8 commit 2471eaa

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

CONTRIBUTING.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,55 @@ Here's how to make a one-off code change.
131131

132132
7. **Celebrate.** Congratulations, you have contributed to ``python-telegram-bot``!
133133

134+
Style commandments
135+
==================
136+
137+
Specific commandments
138+
---------------------
139+
140+
- Avoid using "double quotes" where you can reasonably use 'single quotes'.
141+
142+
AssertEqual argument order
143+
--------------------------
144+
145+
assertEqual method's arguments should be in ('actual', 'expected') order.
146+
147+
Properly calling callables
148+
--------------------------
149+
150+
Methods, functions and classes can specify optional parameters (with default
151+
values) using Python's keyword arg syntax. When providing a value to such a
152+
callable we prefer that the call also uses keyword arg syntax. For example::
153+
154+
def f(required, optional=None):
155+
pass
156+
157+
# GOOD
158+
f(0, optional=True)
159+
160+
# BAD
161+
f(0, True)
162+
163+
This gives us the flexibility to re-order arguments and more importantly
164+
to add new required arguments. It's also more explicit and easier to read.
165+
166+
Properly defining optional arguments
167+
------------------------------------
168+
169+
It's always good to not initialize optional arguments at class creation,
170+
instead use ``**kwargs`` to get them. It's well known Telegram API can
171+
change without notice, in that case if a new argument is added it won't
172+
break the API classes. For example::
173+
174+
# GOOD
175+
def __init__(self, id, name, **kwargs):
176+
self.last_name = kwargs.get('last_name', '')
177+
178+
# BAD
179+
def __init__(self, id, name, last_name=''):
180+
self.last_name = last_name
181+
182+
134183
.. _`Code of Conduct`: https://www.python.org/psf/codeofconduct/
135184
.. _`issue tracker`: https://github.com/python-telegram-bot/python-telegram-bot/issues
136185
.. _`developers' mailing list`: mailto:devs@python-telegram-bot.org

0 commit comments

Comments
 (0)
X Tutup