Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pendulum/tz/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Timezone(tzinfo):
POST_TRANSITION = 'post'
TRANSITION_ERROR = 'error'

def __init__(self, name, transitions,
tzinfos,
default_tzinfo_index,
utc_transition_times):
def __init__(self, name=None, transitions=(),
tzinfos=(),
default_tzinfo_index=0,
utc_transition_times=[]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's dangerous to use mutable default parameters. I'd suggest using None values and converting to the proper defaults within __init__.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add flake8 to be a part of Travis CI to catch things like this @sdispater

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, I can change that in a follow-up commit. Let me know what else needs to be changed before it can be merged so I can make a new commit and squash.

Copy link

@sethmlarson sethmlarson Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beyond this I think it'd be a good idea to implement __copy__() and __deepcopy__() which are referenced in the Python docs for the copy module rather than adding default parameters. TBH I've never used these methods myself so some experimentation might be required.

"""
Constructor.

Expand Down Expand Up @@ -457,7 +457,7 @@ class FixedTimezone(Timezone):

_cache = {}

def __init__(self, offset, name=None, transition_type=None):
def __init__(self, offset=0, name=None, transition_type=None):
"""
:param offset: offset to UTC in seconds.
:type offset: int
Expand Down
2 changes: 1 addition & 1 deletion pendulum/tz/timezone_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class TimezoneInfo(tzinfo):

def __init__(self, tz, utc_offset, is_dst, dst, abbrev):
def __init__(self, tz=None, utc_offset=0, is_dst=False, dst=None, abbrev='GMT'):
"""
:param tz: The parent timezone.
:type tz: Timezone
Expand Down
12 changes: 12 additions & 0 deletions tests/pendulum_tests/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pickle
import pendulum
from copy import deepcopy
from datetime import datetime, date, time, timedelta
from pendulum import Pendulum, timezone
from .. import AbstractTestCase
Expand Down Expand Up @@ -103,3 +104,14 @@ def test_proper_dst(self):
dt = pendulum.create(1941, 7, 1, tz='Europe/Amsterdam')

self.assertEqual(timedelta(0, 6000), dt.dst())

def test_deepcopy(self):
dt = pendulum.create(1941, 7, 1, tz='Europe/Amsterdam')

self.assertEqual(dt, deepcopy(dt))


def test_deepcopy_datetime(self):
dt = pendulum.create(1941, 7, 1, tz='Europe/Amsterdam')

self.assertEqual(dt._datetime, deepcopy(dt._datetime))