On Wed, Dec 1, 2021 at 8:18 PM Abdulla Al Kathiri firstname.lastname@example.org wrote:
On 1 Dec 2021, at 12:01 PM, Chris Angelico email@example.com wrote:
On Wed, Dec 1, 2021 at 6:43 PM Abdulla Al Kathiri firstname.lastname@example.org wrote:
On 1 Dec 2021, at 10:16 AM, Chris Angelico email@example.com wrote: 3) If "yes" to question 1, would you use it for any/all of (a) mutable defaults, (b) referencing things that might have changed, (c) referencing other arguments, (d) something else?
I will definitely use it for default mutable collections like list, set, dictionary etc. I will also use it to reference things that might have changed. For example, when making callbacks to GUI push buttons, I find myself at the start of the function/callback to be fetching the values from other widgets so we can do something with them. Now those values can be directly passed as late-bound defaults from their respective widgets (e.g., def callback(self, text1 => self.line_edit.text()): …).
Very interesting. That doesn't normally seem like a function default - is the callback ever going to be passed two arguments (self and actual text) such that the default would be ignored?
Yeah. Let’s say the callback prints the text on the main window console. I could use the same function to print something on the console not related to the default widget changing text. Maybe another push button that prints literal “WOW”. If I made the second argument a default widget (def callback(self, line_edit=self.line_edit):...) and then call line_edit.text() inside the function, I would be able to pass any other widget that has the method text() but I wouldn’t be able to pass a literal text.
Ahh gotcha. Then yes, you have a function that takes up to two parameters (or one if you don't count self), and yes, omitting the second argument will have the same effect as fetching the text from that control. So, sounds like a great use for it!