Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dyn methods: Change lambdas to functions
Replace lambdas with function definitions. In a later commit, we will switch to binding the function as a method to the class instead of to the instance. In that process, we will be changing some of its attributes, so then the function object needs to be assigned to a name. A regular function `def` takes care of that assignment already. Some other reasons: - Using lambdas as class/instance methods is frowned upon. Error code E731 in flake8, for example. [[1]] [[2]] - Easier to add docstrings to a function later. [[3]] - Lambdas cannot contain statements. Here this stands in the way of replacing `__setitem__()` with a regular assignment later. Lambdas return functions as well, so no changes in behavior are expected [[4]] [[5]]. Timeit is not showing any significant changes in performance. The use of the same name (`func`) for these two short-lived functions triggers pylint error `E0102`/`function-redefined`. Fixing this by giving the functions two different names might actually increase the risk of copy-paste bugs, while the redefining of the functions actually still continues because we are in a loop. It is just that pylint will not see it anymore then. I plan to discuss how this pylint error should be addressed in the pull request containing this commit. For now, a pragma is added to suppress it. [1]: https://realpython.com/python-lambda/#python-classes [2]: https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes [3]: f374f66 [4]: https://stackoverflow.com/questions/12264834/what-is-the-difference-for-python-between-lambda-and-regular-function [5]: https://stackoverflow.com/questions/44840101/in-python-lambda-expression-is-fast-or-the-normal-function (This commit is part of a series of changes in how the `get_*`, `set_*`, `create_*` and `write_*` methods are dynamically created.)
- Loading branch information