Skip to content

Many method parameters in the datetime module are positional-only in the C implementation but positional-or-keyword in the Python implementation #89979

Open

Description

@AlexWaygood
BPO 45821
Nosy @abalkin, @pganssle, @AlexWaygood

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 2021-11-16.19:21:08.113>
labels = ['type-bug', '3.9', '3.10', '3.11', 'extension-modules', 'library']
title = 'Many method parameters in the datetime module are positional-only in the C implementation but positional-or-keyword in the Python implementation'
updated_at = <Date 2021-11-21.13:45:40.155>
user = 'https://github.com/AlexWaygood'

bugs.python.org fields:

activity = <Date 2021-11-21.13:45:40.155>
actor = 'AlexWaygood'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Extension Modules', 'Library (Lib)']
creation = <Date 2021-11-16.19:21:08.113>
creator = 'AlexWaygood'
dependencies = []
files = []
hgrepos = []
issue_num = 45821
keywords = []
message_count = 3.0
messages = ['406423', '406592', '406715']
nosy_count = 3.0
nosy_names = ['belopolsky', 'p-ganssle', 'AlexWaygood']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue45821'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

Linked PRs

Activity

  1. AlexWaygood commented on Nov 16, 2021

    @AlexWaygood
    MemberAuthor

    The following methods have parameters that are positional-only in the C implementation of the datetime module, but positional-or-keyword in the pure-Python implementation:

    • tzinfo.tzname
    • tzinfo.utcoffset
    • tzinfo.dst
    • tzinfo.fromutc
    • date.fromordinal
    • date.fromisoformat
    • date.__format__
    • date.__le__
    • date.__lt__
    • date.__ge__
    • date.__gt__
    • date.__add__
    • date.__radd__
    • date.__sub__
    • date.__reduce_ex__
    • time.__le__
    • time.__lt__
    • time.__ge__
    • time.__gt__
    • time.fromisoformat
    • time.__format__
    • timedelta.__add__
    • timedelta.__radd__
    • timedelta.__sub__
    • timedelta.__rsub__
    • timedelta.__mul__
    • timedelta.__rmul__
    • timedelta.__floordiv__
    • timedelta.__truediv__
    • timedelta.__mod__
    • timedelta.__divmod__
    • timedelta.__le__
    • timedelta.__lt__
    • timedelta.__ge__
    • timedelta.__gt__
    • datetime.utcfromtimestamp
    • datetime.fromisoformat
    • datetime.strptime
    • datetime.__le__
    • datetime.__lt__
    • datetime.__ge__
    • datetime.__gt__

    These inconsistencies make it extremely difficult to provide an accurate stub for these methods in typeshed.

  2. added
    3.11only security fixes
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Nov 16, 2021
  3. AlexWaygood commented on Nov 19, 2021

    @AlexWaygood
    MemberAuthor

    It seems to me that there are two ways of resolving this:

    (1) Change the Python implementation to match the C implementation (make these parameters positional-only in the Python implementation).

    (2) Change the C implementation to match the Python implementation (make these parameters positional-or-keyword in the C implementation).

    If the decision is that solution (1) is the way to go, I'd be happy to submit a PR fixing this. If the decision is that solution (2) would be better, however, I'm not confident enough with writing C code to submit a PR.

    The C implementation is most widely used, so I think strategy (1) would not have too many backwards-compatibility concerns. Strategy (2) is still probably slightly more backwards-compatible, however.

  4. AlexWaygood commented on Nov 21, 2021

    @AlexWaygood
    MemberAuthor

    Ref to discussion on typeshed: python/typeshed#6343

  5. transferred this issue fromon Apr 10, 2022
  6. StanFromIreland commented on Mar 9, 2025

    @StanFromIreland
    Member

    I would say (1) is fine (with no backporting) as I doubt there are many use cases for using the Python implementation over the much faster C. I can implement one (or two I guess, using clinic for just a few functions is also not the nicest imo)

  7. serhiy-storchaka commented on Jul 7, 2025

    @serhiy-storchaka
    Member

    I support solution (1). We can add support for keyword arguments later if they are useful. See also #135312.

    @AlexWaygood, do you prefer to create PR yourself or leave it to others?

  8. AlexWaygood commented on Jul 7, 2025

    @AlexWaygood
    MemberAuthor

    @AlexWaygood, do you prefer to create PR yourself or leave it to others?

    I'm somewhat stretched for time right now — I probably won't have time to make a PR myself any time soon :-)

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

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions