_backport_stdlib_names.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  2. # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
  3. # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
  4. """
  5. Shim to support Python versions < 3.10 that don't have sys.stdlib_module_names
  6. These values were created by cherry-picking the commits from
  7. https://bugs.python.org/issue42955 into each version, but may be updated
  8. manually if changes are needed.
  9. """
  10. import sys
  11. # TODO: Remove this file when Python 3.9 is no longer supported
  12. PY_3_7 = frozenset(
  13. {
  14. "__future__",
  15. "_abc",
  16. "_ast",
  17. "_asyncio",
  18. "_bisect",
  19. "_blake2",
  20. "_bootlocale",
  21. "_bz2",
  22. "_codecs",
  23. "_codecs_cn",
  24. "_codecs_hk",
  25. "_codecs_iso2022",
  26. "_codecs_jp",
  27. "_codecs_kr",
  28. "_codecs_tw",
  29. "_collections",
  30. "_collections_abc",
  31. "_compat_pickle",
  32. "_compression",
  33. "_contextvars",
  34. "_crypt",
  35. "_csv",
  36. "_ctypes",
  37. "_curses",
  38. "_curses_panel",
  39. "_datetime",
  40. "_dbm",
  41. "_decimal",
  42. "_dummy_thread",
  43. "_elementtree",
  44. "_functools",
  45. "_gdbm",
  46. "_hashlib",
  47. "_heapq",
  48. "_imp",
  49. "_io",
  50. "_json",
  51. "_locale",
  52. "_lsprof",
  53. "_lzma",
  54. "_markupbase",
  55. "_md5",
  56. "_msi",
  57. "_multibytecodec",
  58. "_multiprocessing",
  59. "_opcode",
  60. "_operator",
  61. "_osx_support",
  62. "_pickle",
  63. "_posixsubprocess",
  64. "_py_abc",
  65. "_pydecimal",
  66. "_pyio",
  67. "_queue",
  68. "_random",
  69. "_sha1",
  70. "_sha256",
  71. "_sha3",
  72. "_sha512",
  73. "_signal",
  74. "_sitebuiltins",
  75. "_socket",
  76. "_sqlite3",
  77. "_sre",
  78. "_ssl",
  79. "_stat",
  80. "_string",
  81. "_strptime",
  82. "_struct",
  83. "_symtable",
  84. "_thread",
  85. "_threading_local",
  86. "_tkinter",
  87. "_tracemalloc",
  88. "_uuid",
  89. "_warnings",
  90. "_weakref",
  91. "_weakrefset",
  92. "_winapi",
  93. "abc",
  94. "aifc",
  95. "antigravity",
  96. "argparse",
  97. "array",
  98. "ast",
  99. "asynchat",
  100. "asyncio",
  101. "asyncore",
  102. "atexit",
  103. "audioop",
  104. "base64",
  105. "bdb",
  106. "binascii",
  107. "binhex",
  108. "bisect",
  109. "builtins",
  110. "bz2",
  111. "cProfile",
  112. "calendar",
  113. "cgi",
  114. "cgitb",
  115. "chunk",
  116. "cmath",
  117. "cmd",
  118. "code",
  119. "codecs",
  120. "codeop",
  121. "collections",
  122. "colorsys",
  123. "compileall",
  124. "concurrent",
  125. "configparser",
  126. "contextlib",
  127. "contextvars",
  128. "copy",
  129. "copyreg",
  130. "crypt",
  131. "csv",
  132. "ctypes",
  133. "curses",
  134. "dataclasses",
  135. "datetime",
  136. "dbm",
  137. "decimal",
  138. "difflib",
  139. "dis",
  140. "distutils",
  141. "doctest",
  142. "dummy_threading",
  143. "email",
  144. "encodings",
  145. "ensurepip",
  146. "enum",
  147. "errno",
  148. "faulthandler",
  149. "fcntl",
  150. "filecmp",
  151. "fileinput",
  152. "fnmatch",
  153. "formatter",
  154. "fractions",
  155. "ftplib",
  156. "functools",
  157. "gc",
  158. "genericpath",
  159. "getopt",
  160. "getpass",
  161. "gettext",
  162. "glob",
  163. "grp",
  164. "gzip",
  165. "hashlib",
  166. "heapq",
  167. "hmac",
  168. "html",
  169. "http",
  170. "idlelib",
  171. "imaplib",
  172. "imghdr",
  173. "imp",
  174. "importlib",
  175. "inspect",
  176. "io",
  177. "ipaddress",
  178. "itertools",
  179. "json",
  180. "keyword",
  181. "lib2to3",
  182. "linecache",
  183. "locale",
  184. "logging",
  185. "lzma",
  186. "macpath",
  187. "mailbox",
  188. "mailcap",
  189. "marshal",
  190. "math",
  191. "mimetypes",
  192. "mmap",
  193. "modulefinder",
  194. "msilib",
  195. "msvcrt",
  196. "multiprocessing",
  197. "netrc",
  198. "nis",
  199. "nntplib",
  200. "nt",
  201. "ntpath",
  202. "nturl2path",
  203. "numbers",
  204. "opcode",
  205. "operator",
  206. "optparse",
  207. "os",
  208. "ossaudiodev",
  209. "parser",
  210. "pathlib",
  211. "pdb",
  212. "pickle",
  213. "pickletools",
  214. "pipes",
  215. "pkgutil",
  216. "platform",
  217. "plistlib",
  218. "poplib",
  219. "posix",
  220. "posixpath",
  221. "pprint",
  222. "profile",
  223. "pstats",
  224. "pty",
  225. "pwd",
  226. "py_compile",
  227. "pyclbr",
  228. "pydoc",
  229. "pydoc_data",
  230. "pyexpat",
  231. "queue",
  232. "quopri",
  233. "random",
  234. "re",
  235. "readline",
  236. "reprlib",
  237. "resource",
  238. "rlcompleter",
  239. "runpy",
  240. "sched",
  241. "secrets",
  242. "select",
  243. "selectors",
  244. "shelve",
  245. "shlex",
  246. "shutil",
  247. "signal",
  248. "site",
  249. "smtpd",
  250. "smtplib",
  251. "sndhdr",
  252. "socket",
  253. "socketserver",
  254. "spwd",
  255. "sqlite3",
  256. "sre_compile",
  257. "sre_constants",
  258. "sre_parse",
  259. "ssl",
  260. "stat",
  261. "statistics",
  262. "string",
  263. "stringprep",
  264. "struct",
  265. "subprocess",
  266. "sunau",
  267. "symbol",
  268. "symtable",
  269. "sys",
  270. "sysconfig",
  271. "syslog",
  272. "tabnanny",
  273. "tarfile",
  274. "telnetlib",
  275. "tempfile",
  276. "termios",
  277. "textwrap",
  278. "this",
  279. "threading",
  280. "time",
  281. "timeit",
  282. "tkinter",
  283. "token",
  284. "tokenize",
  285. "trace",
  286. "traceback",
  287. "tracemalloc",
  288. "tty",
  289. "turtle",
  290. "turtledemo",
  291. "types",
  292. "typing",
  293. "unicodedata",
  294. "unittest",
  295. "urllib",
  296. "uu",
  297. "uuid",
  298. "venv",
  299. "warnings",
  300. "wave",
  301. "weakref",
  302. "webbrowser",
  303. "winreg",
  304. "winsound",
  305. "wsgiref",
  306. "xdrlib",
  307. "xml",
  308. "xmlrpc",
  309. "zipapp",
  310. "zipfile",
  311. "zipimport",
  312. "zlib",
  313. }
  314. )
  315. PY_3_8 = frozenset(
  316. PY_3_7
  317. - {
  318. "macpath",
  319. }
  320. | {
  321. "_posixshmem",
  322. "_statistics",
  323. "_xxsubinterpreters",
  324. }
  325. )
  326. PY_3_9 = frozenset(
  327. PY_3_8
  328. - {
  329. "_dummy_thread",
  330. "dummy_threading",
  331. }
  332. | {
  333. "_aix_support",
  334. "_bootsubprocess",
  335. "_peg_parser",
  336. "_zoneinfo",
  337. "graphlib",
  338. "zoneinfo",
  339. }
  340. )
  341. if sys.version_info[:2] == (3, 7):
  342. stdlib_module_names = PY_3_7
  343. elif sys.version_info[:2] == (3, 8):
  344. stdlib_module_names = PY_3_8
  345. elif sys.version_info[:2] == (3, 9):
  346. stdlib_module_names = PY_3_9
  347. else:
  348. raise AssertionError("This module is only intended as a backport for Python <= 3.9")