On Jun 18, 8:56 pm, Matthew Wilson <m...@tplus1.com> wrote: > Here's the code that I'm feeding to pylint: > > $ cat f.py > from datetime import datetime > > def f(c="today"): > > if c == "today": > c = datetime.today() > > return c.date() > > And here's what pylint says: > > $ pylint -e f.py > No config file found, using default configuration > ************* Module f > E: 10:f: Instance of 'str' has no 'date' member (but some types could > not be inferred) > > Is this a valid error message? Is the code above bad? If so, what is > the right way? > > 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 f(c=None): > > if c is None: > c = datetime.today() > > return c.date() > > $ pylint -e f.py > No config file found, using default configuration > > I don't see any difference between using a string vs None. Both are > immutable. I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt
>>> 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) >>> midnight_next_day() Traceback (most recent call last): File "<pyshell#24>", line 1, in <module> midnight_next_day() File "<pyshell#23>", line 6, in midnight_next_day return initial_time.date() + timedelta(days=1) AttributeError: 'str' object has no attribute 'date' -- http://mail.python.org/mailman/listinfo/python-list