Skip to content

It is strongly recommended that the time module in your datetime library not be named "time", or be merged into the datetime module of datetime #135003

Closed as not planned
@zyy37

Description

@zyy37

Feature or enhancement

Proposal:

It is strongly recommended that the time module in your datetime library not be named time module, or be merged into the datetime module of datetime. Because the time module of datetime has the same name as the time module of the standard library and has low performance, the latter is more commonly used. If the former is used, organizations generally do not want to give the datetime.time module various aliases to avoid conflicts.

For example, how does python compare whether the current time is past 9:30? The implement is,

from datetime import datetime, time

current_time = datetime.now().time()
nine_thirty = time(9, 30)
status = current_time > nine_thirty

The from datetime import time will cause time name conflicts with import time which is a lightweight and high-performance standard libraries. But if developers use your datetime module to construct hours, minutes, and seconds with many lines, like now = datetime.now() hour, minute = now.hour, now.minute, or string way nine_thirty = datetime.strptime("09:30:00", "%H:%M:%S").time(), it will be very troublesome and far less elegant than a single line of code like nine_thirty = time(9, 30).

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions