From: t k Date: Thu, 19 Sep 2019 13:34:41 +0000 (-0400) Subject: bpo-38155: Add __all__ to datetime module (GH-16203) X-Git-Tag: v3.9.0a1~385 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=96b1c59c71534db3f0f3799cd84e2006923a5098;p=thirdparty%2FPython%2Fcpython.git bpo-38155: Add __all__ to datetime module (GH-16203) https://bugs.python.org/issue38155 --- diff --git a/Lib/datetime.py b/Lib/datetime.py index 0adf1dd67dfb..67555191d02c 100644 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -4,6 +4,10 @@ See http://www.iana.org/time-zones/repository/tz-link.html for time zone and DST data sources. """ +__all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", + "MINYEAR", "MAXYEAR") + + import time as _time import math as _math import sys diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 32977b12ebae..42e2cecaeb72 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -62,6 +62,12 @@ class TestModule(unittest.TestCase): self.assertEqual(datetime.MINYEAR, 1) self.assertEqual(datetime.MAXYEAR, 9999) + def test_all(self): + """Test that __all__ only points to valid attributes.""" + all_attrs = dir(datetime_module) + for attr in datetime_module.__all__: + self.assertIn(attr, all_attrs) + def test_name_cleanup(self): if '_Pure' in self.__class__.__name__: self.skipTest('Only run for Fast C implementation') diff --git a/Misc/NEWS.d/next/Library/2019-09-16-21-47-48.bpo-38155.d92lRc.rst b/Misc/NEWS.d/next/Library/2019-09-16-21-47-48.bpo-38155.d92lRc.rst new file mode 100644 index 000000000000..14b6e2da67f9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-09-16-21-47-48.bpo-38155.d92lRc.rst @@ -0,0 +1 @@ +Add ``__all__`` to :mod:`datetime`. Patch by Tahia Khan.