-
Notifications
You must be signed in to change notification settings - Fork 523
gettz documentation #704
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
gettz documentation #704
Conversation
dateutil/tz/tz.py
Outdated
|
|
||
| class GettzFunc(object): | ||
| """ | ||
| gettz is designed not to be a public function. It is defined in a closure as a private function and called once. |
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.
This is not true. GettzFunc is not a public function. gettz is very much a public function, otherwise it wouldn't be in __all__ and wouldn't be getting any documentation.
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.
Ah sorry about that. I misunderstood your other comment in the original issue.
|
You seem to have checked in a I think this also needs to be rebased against master: git checkout master
git pull upstream master
git checkout WIP-gettz-documentation
git rebase -i masterIf you don't have an git remote add upstream git@github.com:dateutil/dateutil.git |
|
Thanks for the quick responses. I'll do another pass as soon as I'm able, but it might take a couple of days. |
add name added PR dateutil#704
|
I rebased my branch, which took a while. I correct the gettz description and added my name in the correct position. Thanks for your help with on this, if you'd like me to fix anything else, please let me know. |
|
Something seems to have gone wrong with the rebase because this PR now includes a bunch of commits unrelated to it. I'll go in there and clean up the history. |
|
Yeah, sorry about that, it was a bit of a mess trying to get all the merge conflicts sorted out. Thanks in advance for cleaning up the history. |
f1140ed to
075759d
Compare
|
OK, I've significantly cleaned up the history, including squashing all the fixup stuff. You'll need to do Also, I noticed that your If you don't want your e-mail address in the git history, you can set it to I can rewrite the git history to use that e-mail address if you'd prefer. |
dateutil/tz/tz.py
Outdated
| ..code-block:: | ||
| >>> from dateutil.tz import tzutc, UTC | ||
| >>> tgettz('AEST-10AEDT-11,M10.1.0/2,M4.1.0/3') |
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.
The UTC and tzutc imports are unnecessary, and tgettz is definitely not right.
|
Hi for the clean up. I did a |
075759d to
7e63884
Compare
|
OK done. Note that you'll need to do another |
|
Hello! I removed the import lines and corrected the gettz() typo. Had trouble with the pull --force again but I think I got it sorted out. Thanks for your patience! |
dateutil/tz/tz.py
Outdated
| Given a variety of inputs, like time zone name and ``TZ`` varible, | ||
| return a time zone. | ||
| :param object: |
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.
This is not actually the interface. GettzFunc is a class representing a callable function. object is the name of the base type of all objects in Python 3 ("new style classes"), and so GettzFunc is a subclass of object for backwards compatibility with Python 2.
I realize it's confusing, but what's being written here is actually the documentation for tz.gettz, which is an instance of GettzFunc, but for practical purposes is equivalent to a function.
When you call tz.gettz(), it actually invokes GettzFunc.__call__, which itself is a thin wrapper around GettzFunc.nocache.
The reason it's built this way is partially for performance reasons, but mostly because I want tz.gettz to satisfy the following invariant:
assert tz.gettz(name) is tz.gettz(name)So I need to store a reference to the arguments that have been passed to tz.gettz and all the results, so that I can return the same object if I get the same arguments. Those get stored on the GettzFunc instance in the _cache. Because you might want the old semantics, I've exposed a "nocache" variant that bypasses the cache: tz.gettz.nocache(name), and since cache misses are identical to calls to nocache, __call__ is implemented in terms of nocache.
There are also functions on gettz for manipulating the cache, like clear_cache.
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.
Thanks for the extended comments. I'm going to a little more time digest and a bit more research and make another pass. More coming.
Do you have an example (could be anywhere) of how much detail you prefer in the docstring?
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.
OK I took another pass and it's hopefully more accurate now. I also added the assertion as an example.
A couple questions:
Your explanation above was really helpful. Do you want me to make a new issue to put that information into the individual methods and functions as comments?
Also, I wanted to double check:
>>tz.gettz() is tz.gettz()
False
This is as designed (I think.) Because if name=None, then the time zone is not cached. Is that correct?
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.
Do you have an example (could be anywhere) of how much detail you prefer in the docstring?
I'm not really satisfied with the dateutil documentation in general. I personally originated the functions (and hence the docstrings) for isoparse and default_tzinfo, so something like that is likely what I would write, but I actually need to do a full re-organization of the documentation, and I'm not sure where information should go for each function / class.
I'm thinking in the end that however it's organized, somewhere in the documentation, the functions and classes would be documented roughly with a man page level of detail.
Your explanation above was really helpful. Do you want me to make a new issue to put that information into the individual methods and functions as comments?
Sure.
Also, I wanted to double check:
>>> tz.gettz() is tz.gettz
FalseThis is as designed (I think.) Because if name=None, then the time zone is not cached. Is that correct?
Yes and no. Ideally that would be True even for None, but since tz.gettz() represents local time it's made a bit more complicated by the fact that local time might change over the runtime of a program (which leads to a bunch of bugs, but we don't want to add to the bugginess by adding to the problem). As such, I'd rather err on the side of the previous non-cached behavior until we can work out how best to figure out if the "local zone" cache has been invalidated by changes in the execution environment.
pganssle
left a comment
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.
I think at this point the most productive thing would be for me to make an accurate description with the right level of detail. This is a complicated function and it's a bit much to ask anyone else to understand precisely what it does and what it is intended to do.
dateutil/tz/tz.py
Outdated
| A time zone name, a ``TZ`` variable, or ``None``. | ||
| :return: | ||
| A :class:`dateutil.tz.tzfile`. If name is ``None``, |
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.
This is also not accurate. If you look at the code, it can return tzfile, tzlocal, tzstr, possibly others.
This function is that it takes a string representing a time zone and returns the best-matching tzinfo subclass instance. The specific subclass returned is not part of the function's contract.
dateutil/tz/tz.py
Outdated
| tzlocal_classes += (tzwinlocal,) | ||
|
|
||
| class GettzFunc(object): | ||
| """gettz(name=None) |
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.
The function prototype will be auto-generated by sphinx and should not be included.
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.
Maybe there is another way, but without this added line, generating the docs locally, gettz() is returned without the name=None.
|
I agree that it would be good pause and regroup on this. If I can be of help, let me know. Thanks your time and all your responses. |
d7903ff to
df4747b
Compare
Add changelog for PR dateutil#704
df4747b to
c7fb96e
Compare
c7fb96e to
b403a00
Compare
|
@weatherpattern Thanks for your hard work on this! |
Summary of changes
Added parameters, return and examples to gettz.
Closes #647
Pull Request Checklist