﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28323	Redundant use of normalize() in django.utils.timezone.localtime() and make_naive()	Sergei Zh	nobody	"I'm not 100% sure , but I didn't find any test on this and can't think of any. 
What the purpose of using `timezone.normalize` method after `dt.astimezone` if pytz installed?

Current implementation of `datetime.astimezone` (according to python 2/3 docs):

{{{
def astimezone(self, tz):
    if self.tzinfo is tz:
        return self
    # Convert self to UTC, and attach the new time zone object.
    utc = (self - self.utcoffset()).replace(tzinfo=tz)
    # Convert from UTC to tz's local time.
    return tz.fromutc(utc)
}}}

The implementation of `normalize` method for StaticTzInfo is `astimezone`:

{{{
if dt.tzinfo is self:
    return dt
if dt.tzinfo is None:
    raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
}}}

And for DstTzInfo `normalize` implementation is the same as `datetime.astimezone`:

{{{
if dt.tzinfo is None:
    raise ValueError('Naive time - no tzinfo set')

# Convert dt in localtime to UTC
offset = dt.tzinfo._utcoffset
dt = dt.replace(tzinfo=None)
dt = dt - offset
# convert it back, and return it
return self.fromutc(dt)
}}}

I've checked pytz 2011k and 2017.2 versions, looks like this code has never changed.

Also I found this conversation https://answers.launchpad.net/pytz/+question/249229"	Cleanup/optimization	closed	Utilities	1.10	Normal	fixed			Accepted	1	0	0	0	0	0
