Skip to content

Commit 046a4e3

Browse files
gh-136571: Convert more code in datetime to Argument Clinic (GH-136573)
This adds signatures for some classes and methods. date.fromisocalendar() can now raise OverflowError for arguments that don't fit in the C int.
1 parent af15e1d commit 046a4e3

File tree

11 files changed

+2407
-660
lines changed

11 files changed

+2407
-660
lines changed

Doc/library/datetime.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,7 @@ locations where different offsets are used in different days of the year or
23832383
where historical changes have been made to civil time.
23842384

23852385

2386-
.. class:: timezone(offset, name=None)
2386+
.. class:: timezone(offset[, name])
23872387

23882388
The *offset* argument must be specified as a :class:`timedelta`
23892389
object representing the difference between the local time and UTC. It must

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ struct _Py_global_strings {
382382
STRUCT_FOR_ID(d_parameter_type)
383383
STRUCT_FOR_ID(data)
384384
STRUCT_FOR_ID(database)
385+
STRUCT_FOR_ID(date)
385386
STRUCT_FOR_ID(day)
387+
STRUCT_FOR_ID(days)
386388
STRUCT_FOR_ID(debug)
387389
STRUCT_FOR_ID(decode)
388390
STRUCT_FOR_ID(decoder)
@@ -489,6 +491,7 @@ struct _Py_global_strings {
489491
STRUCT_FOR_ID(hi)
490492
STRUCT_FOR_ID(hook)
491493
STRUCT_FOR_ID(hour)
494+
STRUCT_FOR_ID(hours)
492495
STRUCT_FOR_ID(id)
493496
STRUCT_FOR_ID(ident)
494497
STRUCT_FOR_ID(identity_hint)
@@ -583,8 +586,10 @@ struct _Py_global_strings {
583586
STRUCT_FOR_ID(metadata)
584587
STRUCT_FOR_ID(method)
585588
STRUCT_FOR_ID(microsecond)
589+
STRUCT_FOR_ID(microseconds)
586590
STRUCT_FOR_ID(milliseconds)
587591
STRUCT_FOR_ID(minute)
592+
STRUCT_FOR_ID(minutes)
588593
STRUCT_FOR_ID(mod)
589594
STRUCT_FOR_ID(mode)
590595
STRUCT_FOR_ID(module)
@@ -695,6 +700,7 @@ struct _Py_global_strings {
695700
STRUCT_FOR_ID(scheduler)
696701
STRUCT_FOR_ID(script)
697702
STRUCT_FOR_ID(second)
703+
STRUCT_FOR_ID(seconds)
698704
STRUCT_FOR_ID(security_attributes)
699705
STRUCT_FOR_ID(seek)
700706
STRUCT_FOR_ID(seekable)
@@ -758,9 +764,12 @@ struct _Py_global_strings {
758764
STRUCT_FOR_ID(text)
759765
STRUCT_FOR_ID(threading)
760766
STRUCT_FOR_ID(throw)
767+
STRUCT_FOR_ID(time)
761768
STRUCT_FOR_ID(timeout)
762769
STRUCT_FOR_ID(timer)
763770
STRUCT_FOR_ID(times)
771+
STRUCT_FOR_ID(timespec)
772+
STRUCT_FOR_ID(timestamp)
764773
STRUCT_FOR_ID(timetuple)
765774
STRUCT_FOR_ID(timeunit)
766775
STRUCT_FOR_ID(top)
@@ -792,6 +801,7 @@ struct _Py_global_strings {
792801
STRUCT_FOR_ID(wbits)
793802
STRUCT_FOR_ID(week)
794803
STRUCT_FOR_ID(weekday)
804+
STRUCT_FOR_ID(weeks)
795805
STRUCT_FOR_ID(which)
796806
STRUCT_FOR_ID(who)
797807
STRUCT_FOR_ID(withdata)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/_pydatetime.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ def fromisocalendar(cls, year, week, day):
10831083

10841084
@classmethod
10851085
def strptime(cls, date_string, format):
1086-
"""Parse a date string according to the given format (like time.strptime())."""
1086+
"""Parse string according to the given date format (like time.strptime())."""
10871087
import _strptime
10881088
return _strptime._strptime_datetime_date(cls, date_string, format)
10891089

@@ -1310,7 +1310,7 @@ def __reduce__(self):
13101310

13111311

13121312
class tzinfo:
1313-
"""Abstract base class for time zone info classes.
1313+
"""Abstract base class for time zone info objects.
13141314
13151315
Subclasses must override the tzname(), utcoffset() and dst() methods.
13161316
"""
@@ -1468,7 +1468,7 @@ def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold
14681468

14691469
@classmethod
14701470
def strptime(cls, date_string, format):
1471-
"""string, format -> new time parsed from a string (like time.strptime())."""
1471+
"""Parse string according to the given time format (like time.strptime())."""
14721472
import _strptime
14731473
return _strptime._strptime_datetime_time(cls, date_string, format)
14741474

@@ -1776,7 +1776,7 @@ def __reduce__(self):
17761776

17771777

17781778
class datetime(date):
1779-
"""datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
1779+
"""A combination of a date and a time.
17801780
17811781
The year, month and day arguments are required. tzinfo may be None, or an
17821782
instance of a tzinfo subclass. The remaining arguments may be ints.
@@ -2209,7 +2209,7 @@ def __str__(self):
22092209

22102210
@classmethod
22112211
def strptime(cls, date_string, format):
2212-
'string, format -> new datetime parsed from a string (like time.strptime()).'
2212+
"""Parse string according to the given date and time format (like time.strptime())."""
22132213
import _strptime
22142214
return _strptime._strptime_datetime_datetime(cls, date_string, format)
22152215

@@ -2435,6 +2435,8 @@ def _isoweek1monday(year):
24352435

24362436

24372437
class timezone(tzinfo):
2438+
"""Fixed offset from UTC implementation of tzinfo."""
2439+
24382440
__slots__ = '_offset', '_name'
24392441

24402442
# Sentinel value to disallow None

0 commit comments

Comments
 (0)