https://pantsbuild.org/ logo
#general
Title
# general
d

dazzling-diamond-4749

09/14/2021, 10:18 PM
TIL: This works
Copy code
kwargs.get("tags", []) + ["my_tag"]
This doesn't work
Copy code
kwargs["tags"] = kwargs.get("tags", []).append("my_tag")
Any reason why the later doesn't work? maybe all lists are read only and
+
creates a new list that is the combination of the two?
h

hundreds-father-404

09/14/2021, 10:27 PM
It's because
.append()
returns
None
Copy code
❯ python3
Python 3.9.6 (default, Jun 28 2021, 19:24:41)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = [1, 2].append(3)
>>> x
>>> type(x)
<class 'NoneType'>
You could also do
kwargs["tags"] = [*kwargs.get("tags", []), "my_tag"]
d

dazzling-diamond-4749

09/14/2021, 10:28 PM
😂
🤦‍♂️ thanks
🤣 1
❤️ 1
b

busy-vase-39202

09/14/2021, 10:52 PM
I think we've all done this at some point or another. Or maybe that's just me and you @dazzling-diamond-4749. :-)
👍🏽 1
d

dazzling-diamond-4749

09/14/2021, 10:54 PM
Here is my excuse, I never qualify my c++ hash map with
const
just so that I can use default left values (I'm terrible)
7 Views