As we all know, python as a programming language is known to have an elegant code and an ability to express intent very clearly in a few lines of code that look even like a prose.
However, there are situations when the names of function does not express the intent, and there is need of additional documentation when a simple name should suffice for most cases.
The situation is like follow:
def contains_subset_(this_set, set_list):
return any(a_set.issubset(this_set) for a_set in set_list)
Instead of this function, if it were contains_substring(str1, str2)
, both parameters would be string, and it would be confusing for users to know which is supposed to be the substring, str1
or str2
.
I would like to suggest a feature that would fix this issue, enhance code readability, and improve ability to use the code without having to perform mental conversion to keep track of where should each parameter go.
I would like a support for codes written in the following way:
def check_if_(this_set)_has_subset_in_(list_of_sets):
return any(a_set.issubset(this_set) for a_set in list_of_sets)
my_list_of_sets = [{1,2}, {1,3}, {2,3}]
check_if_({1,2,4})_has_subset_in_(my_list_of_sets) # true
I believe this can be done very easily and automatically by a parser in the following way:
def check_if_(this_set)_has_subset_in_(list_of_sets):
becomesdef check_if__has_subset_in_(this_set, list_of_sets):
check_if_({1,2,4})_has_subset_in_(my_list_of_sets)
becomescheck_if__has_subset_in_({1,2,4}, my_list_of_sets)
i.e. when parser sees a function called in following way, it finds the complete function name has ended by keeping track of delimiters such as ' '
(space) or '.'
(dot) or similar meanwhile, keeping track of the parameters passed midway through the name. Then the name parts of function are connected together and all parameters are bubbled all the way to the end.
It would be so nice to see this implemented in python.