ITADN

Py 3.10+ support

#58Closedthebjorn 创建于 2023-06-09
enhancement
T
thebjorncommented
There have been several suggestions to do something similar to: ``` if python-version >= 3.10: return sys.stdlib_module_names else: return old-algorithm ``` Please don't do this, as the first half of the branch only returns the roots of the tree, while the else branch returns nested modules as well. Something more like a recursive version of: ``` import sys def find_names(roots, depth=2): res = list(roots) for root in roots: try: m = __import__(root) res.extend([f"{root}.{attr}" for attr in dir(m)]) except (ModuleNotFoundError, ImportError): print(f"Module {root} not found") return res if __name__ == '__main__': print(find_names(sys.stdlib_module_names)) ``` (you may want to filter out the `antigravity` module...)
关闭于 2023-06-20 2 条评论