From ea03900b48305fa58ecd6c2705ea5f04f289c091 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Thu, 25 May 2017 16:29:01 +0300 Subject: [PATCH] PY-24182 Fixed: datetime.isoformat(timespec='seconds') argument is not recognized as valid Add `timespec` parameter to `datetime.datetime.isoformat` pyi-stub for Python 3.6+. --- python/helpers/typeshed/stdlib/3/datetime.pyi | 7 +++++-- python/testData/typeshed/stdlib/3/datetime_test.py | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/python/helpers/typeshed/stdlib/3/datetime.pyi b/python/helpers/typeshed/stdlib/3/datetime.pyi index a894ab859944..e81f9c8da3e3 100644 --- a/python/helpers/typeshed/stdlib/3/datetime.pyi +++ b/python/helpers/typeshed/stdlib/3/datetime.pyi @@ -1,7 +1,7 @@ # Stubs for datetime # NOTE: These are incomplete! - +import sys from typing import Optional, SupportsAbs, Tuple, overload MINYEAR = 0 @@ -202,7 +202,10 @@ class datetime: Optional[_tzinfo] = None) -> datetime: ... def astimezone(self, tz: Optional[_tzinfo] = ...) -> datetime: ... def ctime(self) -> str: ... - def isoformat(self, sep: str = ...) -> str: ... + if sys.version_info >= (3, 6): + def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... + else: + def isoformat(self, sep: str = ...) -> str: ... @classmethod def strptime(cls, date_string: str, format: str) -> datetime: ... def utcoffset(self) -> Optional[timedelta]: ... diff --git a/python/testData/typeshed/stdlib/3/datetime_test.py b/python/testData/typeshed/stdlib/3/datetime_test.py index bc285b8bdad3..0cae45534eee 100644 --- a/python/testData/typeshed/stdlib/3/datetime_test.py +++ b/python/testData/typeshed/stdlib/3/datetime_test.py @@ -178,6 +178,7 @@ def test_timedelta(): def test_datetime(): from datetime import datetime, timedelta, date, time + import sys datetime(2000, 12, 25) datetime(2000, 12, 25, 23) @@ -220,6 +221,11 @@ def test_datetime(): assert dt.timetz() == time(23, 59, 59) assert dt.ctime() == "Mon Dec 25 23:59:59 2000" assert dt.isoformat() == "2000-12-25T23:59:59" + assert dt.isoformat(' ') == "2000-12-25 23:59:59" + assert dt.isoformat(sep=' ') == "2000-12-25 23:59:59" + if sys.version_info >= (3, 6): + assert dt.isoformat(' ', 'minutes') == "2000-12-25 23:59" + assert dt.isoformat(sep=' ', timespec='minutes') == "2000-12-25 23:59" assert dt.utcoffset() is None assert dt.tzname() is None assert dt.dst() is None