Python Forum
using mutable in function defintion as optional paramter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using mutable in function defintion as optional paramter
#8
(Apr-27-2024, 04:57 PM)Pedroski55 Wrote: Is there a good reason why we should not pass the dictionary we want modified by name?

It's not expected that a function mutates objects from the arguments. But sporadically, it's even done in the standard library. One example is heapq.heapify, which mutates the list.

The example with the dataclass is better because it has isolation. The item dict is attached as an attribute to the dataclass-instance.
Pedroski55 likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: using mutable in function defintion as optional paramter - by DeaD_EyE - Apr-27-2024, 07:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 541 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  mutable values to string items? fozz 15 3,045 Aug-30-2022, 07:20 PM
Last Post: deanhystad
  "'DataFrame' objects are mutable, thus they cannot be hashed" Mark17 1 6,939 Dec-25-2020, 02:31 AM
Last Post: tinh
  Mutable Strings millpond 3 2,655 Aug-24-2020, 08:42 AM
Last Post: millpond
  What is the meaning of mutable data type? qliu 3 3,050 Apr-17-2020, 07:20 PM
Last Post: deanhystad
  copying parts of mutable sequences Skaperen 1 2,286 Dec-02-2019, 10:34 AM
Last Post: Gribouillis
  A mutable string?? silentknight85 5 4,757 May-31-2019, 10:11 AM
Last Post: silentknight85
  Trouble making an argument optional linuxnoob 2 2,971 Aug-31-2018, 01:52 AM
Last Post: linuxnoob
  compacting a mutable sequence Skaperen 6 4,523 Jan-23-2018, 03:54 AM
Last Post: Skaperen
  Paramter lists when shift+tab doesn't work sobrio1 0 3,201 Oct-15-2017, 03:41 PM
Last Post: sobrio1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020