#380 W0102, dangerous-default-value
Merged 5 years ago by msuchy. Opened 5 years ago by msuchy.
copr/ msuchy/copr dangerous-default-value  into  master

@@ -28,8 +28,10 @@ 

  

          self.tmp_root = None

  

-     def try_to_obtain_new_tasks(self, exclude=[], limit=1):

+     def try_to_obtain_new_tasks(self, exclude=None, limit=1):

          log.debug("Get task data...")

+         if exclude is None:

+             exclude = []

Personally, I prefer exclude = exclude or [], so it can be a single-liner. But I understand that it is not the exact the same thing and why docs recommend it this way.

          try:

              # get the data

              r = get(self.get_url)

Personally, I prefer exclude = exclude or [], so it can be a single-liner. But I understand that it is not the exact the same thing and why docs recommend it this way.

-1, default values belong to method headers:

if exclude is None:
    exclude = []

this is just redundant piece of code. You can also consider using immutable tuple if you want to use pylint and make it all happy.

This is also very well known feature of python ("what happens if you use mutable values as default values") that pretty much all at least intermediate programmers know of. Which means we all know about it as well. So this has no value for us to use :(. Python was designed to be a language that allows you to shoot yourself into the leg (Guido himself stated that). You just need to know about the feature and how to use it and not use it, you don't need to put redundant code everywhere showing that you know about it.

If you really want to get rid of the warning, use:

def try_to_obtain_new_tasks(self, exclude=(), limit=1):

We can also just ignore the warning.

+1, it's common idiom and the issue doesn't make sense to be ignored just to prove how clever we are that we know what we are doing. It is wasting of reader's time. I'm not against exclude=(), though the proposal is cleaner and more standard (no type mismatch).

Pull-Request has been merged by msuchy

5 years ago
Metadata