Style question: When passing an optional callback method as an argument, is it smellier to use None or an empty lambda function as the default value? /u/OhGodSoManyQuestions Python Education

examples:

def my_function(callback=None):

This is smelly because callback’s data type could be none or function. That’s not hard to get around but I know many consider this ambiguity a faux pas.

def my_function(callback=lambda x: None):

This seems smelly to me just because it’s creating a function inside the kwargs list – which is an unexpected place to instantiate anything other than numbers, bools, and empty strings.

Whaddaya think?

submitted by /u/OhGodSoManyQuestions
[link] [comments]

​r/learnpython examples: def my_function(callback=None): This is smelly because callback’s data type could be none or function. That’s not hard to get around but I know many consider this ambiguity a faux pas. def my_function(callback=lambda x: None): This seems smelly to me just because it’s creating a function inside the kwargs list – which is an unexpected place to instantiate anything other than numbers, bools, and empty strings. Whaddaya think? submitted by /u/OhGodSoManyQuestions [link] [comments] 

examples:

def my_function(callback=None):

This is smelly because callback’s data type could be none or function. That’s not hard to get around but I know many consider this ambiguity a faux pas.

def my_function(callback=lambda x: None):

This seems smelly to me just because it’s creating a function inside the kwargs list – which is an unexpected place to instantiate anything other than numbers, bools, and empty strings.

Whaddaya think?

submitted by /u/OhGodSoManyQuestions
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *