Skip to content

Commit 8231ace

Browse files
committed
CPython needs C99
1 parent 872a3e0 commit 8231ace

File tree

3 files changed

+24
-37
lines changed

3 files changed

+24
-37
lines changed

Lib/test/datetimetester.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ def test_bool(self):
18071807
self.assertTrue(self.theclass.min)
18081808
self.assertTrue(self.theclass.max)
18091809

1810-
def test_strftime_y2k(self):
1810+
def check_strftime_y2k(self, specifier):
18111811
# Test that years less than 1000 are 0-padded; note that the beginning
18121812
# of an ISO 8601 year may fall in an ISO week of the year before, and
18131813
# therefore needs an offset of -1 when formatting with '%G'.
@@ -1821,22 +1821,28 @@ def test_strftime_y2k(self):
18211821
(1000, 0),
18221822
(1970, 0),
18231823
)
1824-
specifiers = 'YG'
1825-
if _time.strftime('%F', (1900, 1, 1, 0, 0, 0, 0, 1, 0)) == '1900-01-01':
1826-
specifiers += 'FC'
18271824
for year, g_offset in dataset:
1828-
for specifier in specifiers:
1829-
with self.subTest(year=year, specifier=specifier):
1830-
d = self.theclass(year, 1, 1)
1831-
if specifier == 'G':
1832-
year += g_offset
1833-
if specifier == 'C':
1834-
expected = f"{year // 100:02d}"
1835-
else:
1836-
expected = f"{year:04d}"
1837-
if specifier == 'F':
1838-
expected += f"-01-01"
1839-
self.assertEqual(d.strftime(f"%{specifier}"), expected)
1825+
with self.subTest(year=year, specifier=specifier):
1826+
d = self.theclass(year, 1, 1)
1827+
if specifier == 'G':
1828+
year += g_offset
1829+
if specifier == 'C':
1830+
expected = f"{year // 100:02d}"
1831+
else:
1832+
expected = f"{year:04d}"
1833+
if specifier == 'F':
1834+
expected += f"-01-01"
1835+
self.assertEqual(d.strftime(f"%{specifier}"), expected)
1836+
1837+
def test_strftime_y2k(self):
1838+
self.check_strftime_y2k('Y')
1839+
self.check_strftime_y2k('G')
1840+
1841+
def test_strftime_y2k_c99(self):
1842+
# CPython requires C11; specifiers new in C99 must work.
1843+
# (Other implementations may want to disable this test.)
1844+
self.check_strftime_y2k('F')
1845+
self.check_strftime_y2k('C')
18401846

18411847
def test_replace(self):
18421848
cls = self.theclass

Modules/_datetimemodule.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,24 +1781,6 @@ normalize_century(void)
17811781
return cache;
17821782
}
17831783

1784-
/* Check whether C99-specific strftime specifiers are supported. */
1785-
inline static int
1786-
strftime_c99_support(void)
1787-
{
1788-
static int cache = -1;
1789-
if (cache < 0) {
1790-
char full_date[11];
1791-
struct tm date = {
1792-
.tm_year = 0,
1793-
.tm_mon = 0,
1794-
.tm_mday = 1
1795-
};
1796-
cache = (strftime(full_date, sizeof(full_date), "%F", &date) &&
1797-
strcmp(full_date, "1900-01-01") == 0);
1798-
}
1799-
return cache;
1800-
}
1801-
18021784
static PyObject *
18031785
make_somezreplacement(PyObject *object, char *sep, PyObject *tzinfoarg)
18041786
{
@@ -1970,8 +1952,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
19701952
}
19711953
replacement = freplacement;
19721954
}
1973-
else if (normalize_century() && (ch == 'Y' || ch == 'G' ||
1974-
(strftime_c99_support() && (ch == 'F' || ch == 'C'))))
1955+
else if (normalize_century()
1956+
&& (ch == 'Y' || ch == 'G' || ch == 'F' || ch == 'C'))
19751957
{
19761958
/* 0-pad year with century as necessary */
19771959
PyObject *item = PySequence_GetItem(timetuple, 0);

Tools/c-analyzer/cpython/ignored.tsv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ Modules/_datetimemodule.c parse_hh_mm_ss_ff correction -
227227
Modules/_datetimemodule.c time_isoformat specs -
228228
Modules/_datetimemodule.c - capi_types -
229229
Modules/_datetimemodule.c normalize_century cache -
230-
Modules/_datetimemodule.c strftime_c99_support cache -
231230
Modules/_decimal/_decimal.c - cond_map_template -
232231
Modules/_decimal/_decimal.c - dec_signal_string -
233232
Modules/_decimal/_decimal.c - dflt_ctx -

0 commit comments

Comments
 (0)