CraftSpider / dpytest

A package that assists in writing tests for discord.py
MIT License
103 stars 24 forks source link

Changed make_message_dict default values to [] and added test #42

Closed JayDwee closed 3 years ago

JayDwee commented 3 years ago

Previously had this issue: image

This is a fix for this

CraftSpider commented 3 years ago

Note: [] (Or {}) as a default argument is bad style, as contrary to expectation, it doesn't create a new list each call. Instead, default is always the same list, meaning if that list is changed, it changes for all iterations of the call. Better to keep None as the default, but add

if var is None:
     var = []

for each argument. It's a bit verbose, but avoids the issue.

JayDwee commented 3 years ago

Fixed!

Note: [] (Or {}) as a default argument is bad style, as contrary to expectation, it doesn't create a new list each call. Instead, default is always the same list, meaning if that list is changed, it changes for all iterations of the call. Better to keep None as the default, but add

if var is None:
     var = []

for each argument. It's a bit verbose, but avoids the issue.

Sergeileduc commented 3 years ago

There's also the pretty good stuff in python :

if not foo:
    print("Not foo")

It works with booleans (obviously), integers (0 is falsy), float (0.0), None, empty lists, empty dictionaries', empty strings (""), etc...

(no changes asked ! just to talk about a really cool thing !)