diff --git a/README.md b/README.md index a4d7b99..bcf5246 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,13 @@ Python Standard Library List This package includes lists of all of the standard libraries for Python 2.6, 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, and 3.9 along with the code for scraping the official Python docs to get said lists. +Note: from Python 3.10 onwards one can use the following one-liner to get the list of available modules: + + >>> builtin_modules = list(set(list(sys.stdlib_module_names) + list(sys.builtin_module_names))) + +Thus, this package will not get any more updates. + + Listing the modules in the standard library? Wait, why on Earth would you care about that?! ------------------------------------------------------------------------------------------- @@ -21,4 +28,3 @@ Usage ['AL', 'BaseHTTPServer', 'Bastion', 'CGIHTTPServer', 'ColorPicker', 'ConfigParser', 'Cookie', 'DEVICE', 'DocXMLRPCServer', 'EasyDialogs'] For more details, check out [the docs](http://python-stdlib-list.readthedocs.org/en/latest/). - diff --git a/stdlib_list/base.py b/stdlib_list/base.py index 0cde17a..cb41016 100644 --- a/stdlib_list/base.py +++ b/stdlib_list/base.py @@ -3,6 +3,7 @@ import os import pkgutil import sys +import warnings try: from functools import lru_cache @@ -10,10 +11,15 @@ from functools32 import lru_cache long_versions = ["2.6.9", "2.7.9", "3.2.6", "3.3.6", "3.4.3", "3.5", "3.6", - "3.7", "3.8", "3.9"] + "3.7", "3.8", "3.9", "3.10", "3.11"] short_versions = [".".join(x.split(".")[:2]) for x in long_versions] +builtin_versions = ["3.10", "3.11"] +warning_message = ( + "This package is no longer needed to get Python stdlib modules on Python 3.10+." + "Python itself provides such list, see the one line on the README." +) def get_canonical_version(version): @@ -42,11 +48,16 @@ def stdlib_list(version=None): version = get_canonical_version(version) if version is not None else '.'.join( str(x) for x in sys.version_info[:2]) - module_list_file = os.path.join("lists", "{}.txt".format(version)) + if version in builtin_versions: + result = list(set(list(sys.stdlib_module_names) + list(sys.builtin_module_names))) - data = pkgutil.get_data("stdlib_list", module_list_file).decode() + warnings.warn(warning_message, DeprecationWarning) + else: + module_list_file = os.path.join("lists", "{}.txt".format(version)) - result = [y for y in [x.strip() for x in data.splitlines()] if y] + data = pkgutil.get_data("stdlib_list", module_list_file).decode() + + result = [y for y in [x.strip() for x in data.splitlines()] if y] return result