-
-
Notifications
You must be signed in to change notification settings - Fork 412
Fix #133: Allow deepcopy on Timezone classes. #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
datetime.tzinfo also has an empty constructor, so would it not make sense to provide that here as well?
| def __init__(self, name=None, transitions=(), | ||
| tzinfos=(), | ||
| default_tzinfo_index=0, | ||
| utc_transition_times=[]): |
There was a problem hiding this comment.
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__.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Why would you want to be able to deepcopy a TimeZone object? Not saying I haven't done the same sort of thing before, but my understanding is that |
|
@pganssle If you're deep-copying something that holds onto an object that holds onto an object ... etc ... that eventually holds onto |
|
@SethMichaelLarson Hm.. But is this desirable if One reason this can be a problem is that the logic for inter-zone comparison and intra-zone comparison is slightly different, and two things are considered different if |
|
It's not desirable for them to be copied if they're meant to be singletons. People who know this library's internals should answer your question better than me. I'm just saying that this object should probably not raise an exception when it's copied otherwise it makes all objects that want to be copied and also hold onto this object into more difficult beasts. |
|
@pganssle I agree that, ideally, tzinfo subclasses should be singletons. However, |
|
@sdispater so what should be the eventual solution? Default |
|
@AndreasBackx The |
|
@sdispater I don't think we need to implement I'd see these methods calling the constructors again with the same parameters or do you suggest another way? |
|
@AndreasBackx You don't need to implement |
|
I found something while looking at the Django's source for their
Snippet is from the Python docs. So we should follow this requirement and provide either default I would go with the default values and not overcomplicate things with |
|
@AndreasBackx This is for pickling which has different requirements. So we can go with only implementing |
|
@sdispater alright. I'm currently on holiday and get back at the beginning of August so I won't be able to make a new commit until then. If I haven't committed anything by then (let's say the first week of August), don't be afraid to ping me. |
|
@AndreasBackx friendly nudge. We could really use this for Apache Airflow which is dependent on the possibility of pickling |
|
Fixed by #161 |
|
@bolkedebruin sorry for leaving this in the dust. I've been getting swamped these last few weeks. Thanks for putting forth your own PR. 👍 |
I've added default values to the Timezone classes so that they can be deepcopied. I think it's appropriate to provide these as
datetime.tzinfoalso has an empty constructor.