-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add __all__ to the datetime module #82336
Comments
Currently the datetime module has no all, which means we only advertise what is public and private based on leading underscores. Additionally, because there are two implementations (Python and C), you actually get different things when you do The "easy" part is to add an __all__ variable to Lib/datetime.py for all the documented attributes: __all__ = ["date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR"] A "stretch goal" would be to add a test to ensure that cpython/Lib/test/test_datetime.py Line 1 in 6a517c6
|
Hello! I'm interested in picking up this task. Is it okay if I grab it? The import test bit seems tricky, since (from what I understand) inspecting on an "import *" statement might conflict against other global imports in that test file. I'm a new contributor and open to suggestions on that bit :) |
Hi Tahia: Go ahead and make a PR, no need to worry about the test. I mainly put in the bit about tests because I was hoping to nerd-snipe someone into figuring out how to do it for me ;) It's not a particularly important test. |
Actually, how about adding this simpler test into cpython/Lib/test/datetimetester.py Line 65 in ff2e182
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) This will at least test that __all__ only contains valid attributes on the module. |
Good news, When this issue is solved. |
I'll definitely add that test @paul. Speaking of, what do you guys think of this test: def test_c_all(self):
"""Test that __all__ symbols between the c datetime module and
the python datetime library are equivalent."""
c_datetime = import_fresh_module('datetime', fresh=['_datetime'])
py_datetime = import_fresh_module('datetime', blocked=['_datetime'])
self.assertEqual(c_datetime.__all__, py_datetime.__all__) I found the import_fresh_module here: https://docs.python.org/3/library/test.html#test.support.import_fresh_module - super handy! The test currently passes for me locally, but I wanted to check if my usage was correct before submitting a PR. |
My idea is that both tests should be added. |
Thanks @corona10. I've posted a PR with all these bits. |
Closing this as resolved. I don't think we should backport this, as it's more of an enhancement than a bug fix (and since no one has ever complained about it to my knowledge, I don't think there's any big rush to see this released). Thanks Tahia and all the reviewers! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: