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
For example the function hash() in reliablebroadcast.py could be confused with the Python built-in function hash(). It could perhaps be renamed something like sha256_digest() just to avoid confusion and potential problems in the future.
Another example is the usage of the callable namedinput() (e.g. in reliablebroadcast():
defreliablebroadcast(sid, pid, N, f, leader, input, receive, send):
"""Reliable broadcast ... """"
# ...ifpid==leader:
# The leader erasure encodes the input, sending one strip to each participantm=input() # block until an input is received# ...
input() is also a Python built-in function. If somehow input() is the best name, one trick that is often recommended is to suffix the name with an underscore _. In this case the callable would be renamed input_() and the above code snippet would become:
defreliablebroadcast(sid, pid, N, f, leader, input, receive, send):
"""Reliable broadcast ... """"
# ...ifpid==leader:
# The leader erasure encodes the input, sending one strip to each participantm=input_() # block until an input is received# ...
Notice how the highlighting of the input() function differs in each code snippet. I assume that is because Github uses MagicPython to highlight the code and MagicPython highlights Python built-in functions.
If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than clss. (Perhaps better is to avoid such clashes by using a synonym.)
From @sbellem on August 17, 2017 23:17
For example the function
hash()
in reliablebroadcast.py could be confused with the Python built-in functionhash()
. It could perhaps be renamed something likesha256_digest()
just to avoid confusion and potential problems in the future.Another example is the usage of the callable named
input()
(e.g. inreliablebroadcast()
:input()
is also a Python built-in function. If somehowinput()
is the best name, one trick that is often recommended is to suffix the name with an underscore_
. In this case the callable would be renamedinput_()
and the above code snippet would become:Notice how the highlighting of the
input()
function differs in each code snippet. I assume that is because Github uses MagicPython to highlight the code and MagicPython highlights Python built-in functions.See related thread https://www.reddit.com/r/pythontips/comments/4m9wiw/avoid_overwriting_python_functions/?st=j6h17gu8&sh=f483ed6e
Also somewhat related Function and method arguments in PEP 8:
Copied from original issue: amiller/HoneyBadgerBFT#23
The text was updated successfully, but these errors were encountered: