Skip to content

datetime.date.replace() description not clear enough #115684

Closed

Description

@HopedForLuck

Documentation

In documentation explanation to command date.replace() is not clear enough.
I'm not that experienced, so it's maybe look from junior perspective, but since documentation quite needed for beginers i think my opinion might be valuable.

In documentation description to this function says "Return a date with the same value, except for those parameters given new values by whichever keyword arguments are specified." and gives an examle:

--- from datetime import date
--- d = date(2002, 12, 31)
--- d.replace(day=26)
datetime.date(2002, 12, 26)

But it confused me, since it looks like you can change datetime object and as documentation says - datetime objects are immutable, so i had to check and of course you can't change variable like that, the only way that works if you create a new variable (for example: d2 = d.replace(day=26))

So i propose to make this part that there won't be any confusion for anyone by rephrasing it.
For example:

Return a new date object with the same value as initial, except for those parameters given new values by whichever keyword arguments are specified.

--- from datetime import date
--- d = date(2002, 12, 31)
--- d2 = d.replace(day=26)
--- d2
datetime.date(2002, 12, 26)

I haven't seen any tickets issued about this one, but i apologise if there is and i've missed it, or if i miss something in documentation itself.

Linked PRs

Activity

  1. added
    docs
    on Feb 19, 2024
  2. Privat33r-dev commented on Mar 14, 2024

    @Privat33r-dev
    Contributor

    Thank you for creating this issue, you are right that the documentation is not concise enough.

    Rule of thumb for the future: usually if something is returning a value, it doesn't change the original element.

  3. added a commit that references this issue on Mar 24, 2025
  4. added a commit that references this issue on Mar 24, 2025
  5. added a commit that references this issue on Mar 24, 2025
  6. added a commit that references this issue on Apr 1, 2025
  7. added 2 commits that reference this issue on Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions