Skip to content
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

datetime naive and aware types should have a well-defined definition that can be cross-referenced #53068

Closed
techtonik mannequin opened this issue May 26, 2010 · 14 comments
Labels
3.10 only security fixes docs Documentation in the Doc dir

Comments

@techtonik
Copy link
Mannequin

techtonik mannequin commented May 26, 2010

BPO 8822
Nosy @abalkin
Files
  • datetime_doc.patch: Patch for datetime.rst
  • datetime_doc_noreflow.patch: Patch for datetime.rst
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2010-05-26.12:07:26.281>
    labels = ['3.10', 'docs']
    title = 'datetime naive and aware types should have a well-defined definition that can be cross-referenced'
    updated_at = <Date 2020-12-29.04:39:53.267>
    user = 'https://bugs.python.org/techtonik'

    bugs.python.org fields:

    activity = <Date 2020-12-29.04:39:53.267>
    actor = 'orsenthil'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2010-05-26.12:07:26.281>
    creator = 'techtonik'
    dependencies = []
    files = ['23135', '23167']
    hgrepos = []
    issue_num = 8822
    keywords = ['patch']
    message_count = 13.0
    messages = ['106524', '106614', '143930', '143936', '143937', '143938', '143939', '144091', '144094', '144096', '144099', '144101', '220773']
    nosy_count = 5.0
    nosy_names = ['belopolsky', 'techtonik', 'Alexander.Belopolsky', 'docs@python', 'shaq']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue8822'
    versions = ['Python 3.10']

    @techtonik
    Copy link
    Mannequin Author

    techtonik mannequin commented May 26, 2010

    'naive' and 'aware' are key datetime types - they need a proper definition and anchor for crossrefences. If you take a look at http://docs.python.org/library/datetime.html - the definition of distinction between them is too vague and this seeds of uncertainty grow through the rest of the doc. It is not said how to make non-naive object, how to detect if object of naive or aware. All this stuff is very important for troubleshooting datetims issues in Python projects. It needs a proper documentation.

    @techtonik techtonik mannequin assigned docspython May 26, 2010
    @techtonik techtonik mannequin added the docs Documentation in the Doc dir label May 26, 2010
    @abalkin
    Copy link
    Member

    abalkin commented May 27, 2010

    'naive' and 'aware' are key datetime types - they need a proper
    definition and anchor for crossrefences.

    The definition is given in the introductory section:
    """
    There are two kinds of date and time objects: “naive” and “aware”. This distinction refers to whether the object has any notion of time zone, daylight saving time, or other kind of algorithmic or political time adjustment.
    """

    I am not sure what you propose to add to this. Do you wan't to dedicate a separate subsection to naive and aware time and datetime? I feel that would be an overkill. Would simply adding index entries for naive and aware time/datetime objects be enough?

    It is not said how to make non-naive object,

    This may be due to the fact that there is no concrete tzinfo implementation in stdlib. See bpo-5094.

    I think it can be added in datetime constructor section that providing a tzinfo argument results in an aware object. this is already so for datetime.fromtimestamp.

    how to detect if object of naive or aware.

    This is already clear IMO:

    """
    An object d of type time or datetime may be naive or aware. d is aware if d.tzinfo is not None and d.tzinfo.utcoffset(d) does not return None. If d.tzinfo is None, or if d.tzinfo is not None but d.tzinfo.utcoffset(d) returns None, d is naive.
    """

    @shaq
    Copy link
    Mannequin

    shaq mannequin commented Sep 12, 2011

    I agree with Alexander -- I think the current documentation is sufficient to describe 'naive' and 'aware' date and time objects.

    The sentence "There are two kinds of date and time objects: “naive” and “aware”." is perhaps a bit unfortunate, however. It appears that Anatoly had misinterpreted 'naive' and 'aware' objects to be of different Python types:

    'naive' and 'aware' are key datetime types

    Perhaps the sentence could be changed to something like:

    "date and time objects are either 'naive' or 'aware'.

    @shaq
    Copy link
    Mannequin

    shaq mannequin commented Sep 12, 2011

    I created a patch with the revised wording.

    @AlexanderBelopolsky
    Copy link
    Mannequin

    AlexanderBelopolsky mannequin commented Sep 12, 2011

    On Mon, Sep 12, 2011 at 4:30 PM, Jakob Malm <report@bugs.python.org> wrote:
    ..

    I created a patch with the revised wording.

    Your patch seems to reflow the entire paragraph which makes it hard to
    review and if applied will appear as a bigger change than it is. Can
    you regenerate the patch so that it does not have whitespace only
    diffs? Thanks.

    @techtonik
    Copy link
    Mannequin Author

    techtonik mannequin commented Sep 12, 2011

    The point was:

    1. Create an anchor to definition of "naive" object
    2. Create an anchor to definition of "aware" object
    3. Make definitions stand out from the inline text
    4. Create cross-references for "naive" and "aware" keywords in text that lead directly to appropriate definition
    5. Mention the fact: By default all objects are "naive", by definition, because they don't have any TZ information, and there are no classes in stdlib that provide this info (tzclass implemetations)
    6. Answer the questions: How to make non-naive object? How to detect if object of naive or aware?

    That's it. If it's already done - then this ticket can be closed.

    @AlexanderBelopolsky
    Copy link
    Mannequin

    AlexanderBelopolsky mannequin commented Sep 12, 2011

    On Mon, Sep 12, 2011 at 4:36 PM, anatoly techtonik
    <report@bugs.python.org> wrote:
    ..

    1. Mention the fact: By default all objects are "naive", by definition, because they don't have any
      TZ information, and there are no classes in stdlib that provide this info (tzclass implemetations)

    This is simply wrong: in py3k we have the timezone class that
    implements tzinfo interface.

    1. Answer the questions: How to make non-naive object? How to detect if object of naive or aware?

    I would go one step further: we should review the examples in datetime
    module documentation and use aware datetime objects unless the point
    of the example is to demonstrate a naive datetime. We should also
    replace examples that use sample implementations of tzinfo to use the
    timezone class.

    @shaq
    Copy link
    Mannequin

    shaq mannequin commented Sep 15, 2011

    Patch without reflow attached.

    This is my first patch to CPython. I considered submitting the patch without reflowing the paragraph, to make the changes clearer, but I thought that that would mean more work for the committer, if the patch were to be accepted. Are non-reflown paragraphs like this generally preferred, then?

    Concerning timezone aware objects in the examples, this may make the examples more verbose and less to-the-point, which may not be desirable. I'm still on Python 2.6 and haven't actually used the new timezone class yet...

    @AlexanderBelopolsky
    Copy link
    Mannequin

    AlexanderBelopolsky mannequin commented Sep 15, 2011

    -There are two kinds of date and time objects: "naive" and "aware". This
    +Date and time objects are either "naive" or "aware". This

    Shouldn't we say "datetime and time" instead of "date and time"?
    There is no tzinfo attribute in date objects.

    @shaq
    Copy link
    Mannequin

    shaq mannequin commented Sep 15, 2011

    Shouldn't we say "datetime and time" instead of "date and time"?
    There is no tzinfo attribute in date objects.

    Perhaps like this?

    :class:`datetime` and :class:`time` objects are...

    @techtonik
    Copy link
    Mannequin Author

    techtonik mannequin commented Sep 15, 2011

    On Thu, Sep 15, 2011 at 10:42 PM, Alexander Belopolsky
    <report@bugs.python.org> wrote:

    Shouldn't we say "datetime and time" instead of "date and time"?
    There is no tzinfo attribute in date objects.

    Does that mean that if aware datetime is converted to date and
    then back, the tzinfo information is lost and object implicitly
    becomes naive? In this case it should mentioned IMO.

    anatoly t.

    @AlexanderBelopolsky
    Copy link
    Mannequin

    AlexanderBelopolsky mannequin commented Sep 15, 2011

    On Thu, Sep 15, 2011 at 4:17 PM, anatoly techtonik
    report@bugs.python.org wrote:
    ..

    Does that mean that if aware datetime is converted to date and
    then back, the tzinfo information is lost and object implicitly
    becomes naive?

    Yes, but one cannot convert "back" from date to datetime. To get a
    datetime object, one needs to combine date and time and tzinfo is
    attached to the time component.

    In this case it should mentioned IMO.

    I agree. The following is not really intuitive:

    -> None

    In order to preserve tzinfo, one has to preserve it when extracting
    the time component:

    -> datetime.timezone.utc

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 16, 2014

    I like the wording in the patch as it's clearer than the original and so think it should be applied.

    @orsenthil orsenthil added the 3.10 only security fixes label Dec 29, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @slateny
    Copy link
    Contributor

    slateny commented Jul 8, 2022

    It looks to me that the current document addresses the main concerns here: the wording regarding types is clarified, there is an anchor to the aware/naive objects, and aware/naive are marked bold for clarity. There's also a pretty clear section on determining when an object's aware/naive.

    Since these sections are at the top of the document, imo they've got good enough visibility that not linking every instance of aware/naive is fine, so I think this can be considered resolved. If there are unaddressed issues though, feel free to comment/reopen.

    @slateny slateny closed this as completed Jul 8, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes docs Documentation in the Doc dir
    Projects
    Archived in project
    Development

    No branches or pull requests

    3 participants