Skip to content


Is this pylint error message valid or bogus?

The vast majority of pythoners use None, but I prefer descriptive strings for default values, like this:

from datetime import datetime, timedelta

def midnight_next_day(initial_time="use today's date"):

    if initial_time == "use today's date":
        initial_time = datetime.now()

    return initial_time.date() + timedelta(days=1)

Pylint doesn’t like it though:

$ pylint -e f.py 
No config file found, using default configuration
************* Module f
E: 10:midnight_next_day: Instance of 'str' has no 'date' member (but some types could not be inferred)

I changed from using a string as the default to None, and then pylint
didn’t mind:

$ cat f.py
from datetime import datetime
def midnight_next_day(initial_time=None):

if initial_time is None:
    initial_time = datetime.now()

return initial_time.date() + timedelta(days=1)

$ pylint -e f.py
No config file found, using default configuration

Checking where a variable is None is probably much faster than doing string comparison, but I find the string more informative.

Looking for comments. I already posted this to comp.lang.python here and got some good feedback.

Posted in Programming, Python.

Viewing 8 Comments

 
close Reblog this comment
blog comments powered by Disqus