Pylint: pytz.UTC.localize false positive for no-value-for-parameter

Created on 9 Sep 2016  路  7Comments  路  Source: PyCQA/pylint

Steps to reproduce

pylint the following program

import pytz


def example(datetime_obj):
    return pytz.UTC.localize(datetime_obj)

Current behavior

E:  5,11: No value for argument 'dt' in unbound method call (no-value-for-parameter)

Expected behavior

pylint not complaining about no-value-for-parameter. pytz.UTC is a singleton instance.

pylint --version output

No config file found, using default configuration
pylint 1.6.4, 
astroid 1.4.8
Python 2.7.11 (default, Jan 22 2016, 08:28:37) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
bug

Most helpful comment

pytz.utc.localize(datetime.now()) seems to work as well.

All 7 comments

I can reproduce this and I think it is an occurence of issue https://github.com/PyCQA/pylint/issues/181. What is tripping Pylint in this case is this assignment from pytz (https://github.com/newvem/pytz/blob/master/pytz/__init__.py#L135).

i ran into this today as well in my project when I used exactly the same code as above.
will this be fixed?

EDIT: just saw https://github.com/newvem/pytz/blob/master/pytz/__init__.py#L135
I guess this is beyond pylint's control :/

Work around:

Before:

pytz.UTC.localize(datetime.now())

After:

datetime.now().replace(tzinfo=pytz.UTC)

kinda verbose but works

pytz.utc.localize(datetime.now()) seems to work as well.

I was able to use UTC().localize(myDate, myFormatter) and it stopped complaining as well. Sorry to necro this thread, but hope it helps somebody else in the future!

@CosmicCandi no pb! :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrginglymus picture mrginglymus  路  3Comments

adamtheturtle picture adamtheturtle  路  3Comments

GergelyKalmar picture GergelyKalmar  路  3Comments

thanatos picture thanatos  路  3Comments

pylint-bot picture pylint-bot  路  3Comments