Is this pylint error message valid or silly?

mblume mblume at socha.net
Fri Jun 19 10:38:42 EDT 2009


Am Fri, 19 Jun 2009 00:56:18 +0000 schrieb Matthew Wilson:

> 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

Think of what happens if somebody calls
some_result = f("yesterday")

HTH
Martin



More information about the Python-list mailing list