mypy-dev 1.9.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1018) hide show
  1. mypy/__init__.py +1 -0
  2. mypy/__main__.py +37 -0
  3. mypy/api.py +94 -0
  4. mypy/applytype.py +156 -0
  5. mypy/argmap.py +268 -0
  6. mypy/binder.py +538 -0
  7. mypy/bogus_type.py +27 -0
  8. mypy/build.py +3562 -0
  9. mypy/checker.py +8372 -0
  10. mypy/checkexpr.py +6615 -0
  11. mypy/checkmember.py +1356 -0
  12. mypy/checkpattern.py +801 -0
  13. mypy/checkstrformat.py +1109 -0
  14. mypy/config_parser.py +670 -0
  15. mypy/constant_fold.py +187 -0
  16. mypy/constraints.py +1624 -0
  17. mypy/copytype.py +133 -0
  18. mypy/defaults.py +46 -0
  19. mypy/dmypy/__init__.py +0 -0
  20. mypy/dmypy/__main__.py +6 -0
  21. mypy/dmypy/client.py +749 -0
  22. mypy/dmypy_os.py +42 -0
  23. mypy/dmypy_server.py +1107 -0
  24. mypy/dmypy_util.py +117 -0
  25. mypy/erasetype.py +278 -0
  26. mypy/errorcodes.py +285 -0
  27. mypy/errors.py +1280 -0
  28. mypy/evalexpr.py +205 -0
  29. mypy/expandtype.py +510 -0
  30. mypy/exprtotype.py +206 -0
  31. mypy/fastparse.py +2147 -0
  32. mypy/find_sources.py +243 -0
  33. mypy/fixup.py +426 -0
  34. mypy/freetree.py +23 -0
  35. mypy/fscache.py +309 -0
  36. mypy/fswatcher.py +106 -0
  37. mypy/gclogger.py +47 -0
  38. mypy/git.py +34 -0
  39. mypy/graph_utils.py +112 -0
  40. mypy/indirection.py +121 -0
  41. mypy/infer.py +75 -0
  42. mypy/inspections.py +627 -0
  43. mypy/ipc.py +310 -0
  44. mypy/join.py +866 -0
  45. mypy/literals.py +306 -0
  46. mypy/lookup.py +61 -0
  47. mypy/main.py +1574 -0
  48. mypy/maptype.py +106 -0
  49. mypy/meet.py +1140 -0
  50. mypy/memprofile.py +121 -0
  51. mypy/message_registry.py +326 -0
  52. mypy/messages.py +3171 -0
  53. mypy/metastore.py +225 -0
  54. mypy/mixedtraverser.py +112 -0
  55. mypy/modulefinder.py +875 -0
  56. mypy/moduleinspect.py +184 -0
  57. mypy/mro.py +62 -0
  58. mypy/nodes.py +4112 -0
  59. mypy/operators.py +126 -0
  60. mypy/options.py +556 -0
  61. mypy/parse.py +30 -0
  62. mypy/partially_defined.py +675 -0
  63. mypy/patterns.py +150 -0
  64. mypy/plugin.py +901 -0
  65. mypy/plugins/__init__.py +0 -0
  66. mypy/plugins/attrs.py +1152 -0
  67. mypy/plugins/common.py +440 -0
  68. mypy/plugins/ctypes.py +245 -0
  69. mypy/plugins/dataclasses.py +1101 -0
  70. mypy/plugins/default.py +518 -0
  71. mypy/plugins/enums.py +259 -0
  72. mypy/plugins/functools.py +104 -0
  73. mypy/plugins/proper_plugin.py +175 -0
  74. mypy/plugins/singledispatch.py +224 -0
  75. mypy/py.typed +1 -0
  76. mypy/pyinfo.py +78 -0
  77. mypy/reachability.py +362 -0
  78. mypy/refinfo.py +92 -0
  79. mypy/renaming.py +568 -0
  80. mypy/report.py +924 -0
  81. mypy/scope.py +125 -0
  82. mypy/semanal.py +7023 -0
  83. mypy/semanal_classprop.py +187 -0
  84. mypy/semanal_enum.py +253 -0
  85. mypy/semanal_infer.py +128 -0
  86. mypy/semanal_main.py +511 -0
  87. mypy/semanal_namedtuple.py +670 -0
  88. mypy/semanal_newtype.py +273 -0
  89. mypy/semanal_pass1.py +156 -0
  90. mypy/semanal_shared.py +490 -0
  91. mypy/semanal_typeargs.py +265 -0
  92. mypy/semanal_typeddict.py +575 -0
  93. mypy/server/__init__.py +0 -0
  94. mypy/server/astdiff.py +518 -0
  95. mypy/server/astmerge.py +562 -0
  96. mypy/server/aststrip.py +281 -0
  97. mypy/server/deps.py +1137 -0
  98. mypy/server/mergecheck.py +83 -0
  99. mypy/server/objgraph.py +101 -0
  100. mypy/server/subexpr.py +198 -0
  101. mypy/server/target.py +11 -0
  102. mypy/server/trigger.py +26 -0
  103. mypy/server/update.py +1339 -0
  104. mypy/sharedparse.py +112 -0
  105. mypy/solve.py +562 -0
  106. mypy/split_namespace.py +35 -0
  107. mypy/state.py +28 -0
  108. mypy/stats.py +489 -0
  109. mypy/strconv.py +641 -0
  110. mypy/stubdoc.py +491 -0
  111. mypy/stubgen.py +1873 -0
  112. mypy/stubgenc.py +993 -0
  113. mypy/stubinfo.py +173 -0
  114. mypy/stubtest.py +2079 -0
  115. mypy/stubutil.py +807 -0
  116. mypy/subtypes.py +1967 -0
  117. mypy/suggestions.py +1046 -0
  118. mypy/test/__init__.py +0 -0
  119. mypy/test/config.py +28 -0
  120. mypy/test/data.py +823 -0
  121. mypy/test/helpers.py +476 -0
  122. mypy/test/meta/__init__.py +0 -0
  123. mypy/test/meta/_pytest.py +72 -0
  124. mypy/test/meta/test_diff_helper.py +47 -0
  125. mypy/test/meta/test_parse_data.py +73 -0
  126. mypy/test/meta/test_update_data.py +135 -0
  127. mypy/test/test_find_sources.py +376 -0
  128. mypy/test/test_ref_info.py +45 -0
  129. mypy/test/testapi.py +45 -0
  130. mypy/test/testargs.py +77 -0
  131. mypy/test/testcheck.py +322 -0
  132. mypy/test/testcmdline.py +152 -0
  133. mypy/test/testconstraints.py +134 -0
  134. mypy/test/testdaemon.py +132 -0
  135. mypy/test/testdeps.py +77 -0
  136. mypy/test/testdiff.py +67 -0
  137. mypy/test/testerrorstream.py +46 -0
  138. mypy/test/testfinegrained.py +438 -0
  139. mypy/test/testfinegrainedcache.py +18 -0
  140. mypy/test/testformatter.py +85 -0
  141. mypy/test/testfscache.py +101 -0
  142. mypy/test/testgraph.py +83 -0
  143. mypy/test/testinfer.py +373 -0
  144. mypy/test/testipc.py +119 -0
  145. mypy/test/testmerge.py +238 -0
  146. mypy/test/testmodulefinder.py +278 -0
  147. mypy/test/testmypyc.py +14 -0
  148. mypy/test/testparse.py +107 -0
  149. mypy/test/testpep561.py +211 -0
  150. mypy/test/testpythoneval.py +117 -0
  151. mypy/test/testreports.py +55 -0
  152. mypy/test/testsemanal.py +209 -0
  153. mypy/test/testsolve.py +285 -0
  154. mypy/test/teststubgen.py +1412 -0
  155. mypy/test/teststubinfo.py +12 -0
  156. mypy/test/teststubtest.py +2492 -0
  157. mypy/test/testsubtypes.py +303 -0
  158. mypy/test/testtransform.py +64 -0
  159. mypy/test/testtypegen.py +83 -0
  160. mypy/test/testtypes.py +1551 -0
  161. mypy/test/testutil.py +111 -0
  162. mypy/test/typefixture.py +415 -0
  163. mypy/test/update_data.py +87 -0
  164. mypy/test/visitors.py +63 -0
  165. mypy/traverser.py +961 -0
  166. mypy/treetransform.py +800 -0
  167. mypy/tvar_scope.py +147 -0
  168. mypy/type_visitor.py +564 -0
  169. mypy/typeanal.py +2510 -0
  170. mypy/typeops.py +1082 -0
  171. mypy/types.py +3686 -0
  172. mypy/types_utils.py +166 -0
  173. mypy/typeshed/LICENSE +237 -0
  174. mypy/typeshed/stdlib/VERSIONS +308 -0
  175. mypy/typeshed/stdlib/__future__.pyi +36 -0
  176. mypy/typeshed/stdlib/__main__.pyi +3 -0
  177. mypy/typeshed/stdlib/_ast.pyi +587 -0
  178. mypy/typeshed/stdlib/_bisect.pyi +84 -0
  179. mypy/typeshed/stdlib/_bootlocale.pyi +1 -0
  180. mypy/typeshed/stdlib/_codecs.pyi +133 -0
  181. mypy/typeshed/stdlib/_collections_abc.pyi +94 -0
  182. mypy/typeshed/stdlib/_compat_pickle.pyi +8 -0
  183. mypy/typeshed/stdlib/_compression.pyi +25 -0
  184. mypy/typeshed/stdlib/_csv.pyi +90 -0
  185. mypy/typeshed/stdlib/_ctypes.pyi +205 -0
  186. mypy/typeshed/stdlib/_curses.pyi +557 -0
  187. mypy/typeshed/stdlib/_decimal.pyi +281 -0
  188. mypy/typeshed/stdlib/_dummy_thread.pyi +27 -0
  189. mypy/typeshed/stdlib/_dummy_threading.pyi +164 -0
  190. mypy/typeshed/stdlib/_heapq.pyi +11 -0
  191. mypy/typeshed/stdlib/_imp.pyi +28 -0
  192. mypy/typeshed/stdlib/_json.pyi +49 -0
  193. mypy/typeshed/stdlib/_locale.pyi +100 -0
  194. mypy/typeshed/stdlib/_markupbase.pyi +16 -0
  195. mypy/typeshed/stdlib/_msi.pyi +91 -0
  196. mypy/typeshed/stdlib/_operator.pyi +147 -0
  197. mypy/typeshed/stdlib/_osx_support.pyi +34 -0
  198. mypy/typeshed/stdlib/_posixsubprocess.pyi +32 -0
  199. mypy/typeshed/stdlib/_py_abc.pyi +14 -0
  200. mypy/typeshed/stdlib/_pydecimal.pyi +43 -0
  201. mypy/typeshed/stdlib/_random.pyi +12 -0
  202. mypy/typeshed/stdlib/_sitebuiltins.pyi +16 -0
  203. mypy/typeshed/stdlib/_socket.pyi +802 -0
  204. mypy/typeshed/stdlib/_stat.pyi +103 -0
  205. mypy/typeshed/stdlib/_thread.pyi +52 -0
  206. mypy/typeshed/stdlib/_threading_local.pyi +17 -0
  207. mypy/typeshed/stdlib/_tkinter.pyi +120 -0
  208. mypy/typeshed/stdlib/_tracemalloc.pyi +17 -0
  209. mypy/typeshed/stdlib/_typeshed/__init__.pyi +347 -0
  210. mypy/typeshed/stdlib/_typeshed/dbapi.pyi +37 -0
  211. mypy/typeshed/stdlib/_typeshed/wsgi.pyi +44 -0
  212. mypy/typeshed/stdlib/_typeshed/xml.pyi +9 -0
  213. mypy/typeshed/stdlib/_warnings.pyi +55 -0
  214. mypy/typeshed/stdlib/_weakref.pyi +41 -0
  215. mypy/typeshed/stdlib/_weakrefset.pyi +51 -0
  216. mypy/typeshed/stdlib/_winapi.pyi +251 -0
  217. mypy/typeshed/stdlib/abc.pyi +49 -0
  218. mypy/typeshed/stdlib/aifc.pyi +91 -0
  219. mypy/typeshed/stdlib/antigravity.pyi +3 -0
  220. mypy/typeshed/stdlib/argparse.pyi +571 -0
  221. mypy/typeshed/stdlib/array.pyi +92 -0
  222. mypy/typeshed/stdlib/ast.pyi +277 -0
  223. mypy/typeshed/stdlib/asynchat.pyi +21 -0
  224. mypy/typeshed/stdlib/asyncio/__init__.pyi +41 -0
  225. mypy/typeshed/stdlib/asyncio/base_events.pyi +440 -0
  226. mypy/typeshed/stdlib/asyncio/base_futures.pyi +19 -0
  227. mypy/typeshed/stdlib/asyncio/base_subprocess.pyi +63 -0
  228. mypy/typeshed/stdlib/asyncio/base_tasks.pyi +9 -0
  229. mypy/typeshed/stdlib/asyncio/constants.pyi +20 -0
  230. mypy/typeshed/stdlib/asyncio/coroutines.pyi +26 -0
  231. mypy/typeshed/stdlib/asyncio/events.pyi +574 -0
  232. mypy/typeshed/stdlib/asyncio/exceptions.pyi +43 -0
  233. mypy/typeshed/stdlib/asyncio/format_helpers.pyi +20 -0
  234. mypy/typeshed/stdlib/asyncio/futures.pyi +57 -0
  235. mypy/typeshed/stdlib/asyncio/locks.pyi +121 -0
  236. mypy/typeshed/stdlib/asyncio/log.pyi +3 -0
  237. mypy/typeshed/stdlib/asyncio/mixins.pyi +9 -0
  238. mypy/typeshed/stdlib/asyncio/proactor_events.pyi +64 -0
  239. mypy/typeshed/stdlib/asyncio/protocols.pyi +34 -0
  240. mypy/typeshed/stdlib/asyncio/queues.pyi +47 -0
  241. mypy/typeshed/stdlib/asyncio/runners.pyi +32 -0
  242. mypy/typeshed/stdlib/asyncio/selector_events.pyi +8 -0
  243. mypy/typeshed/stdlib/asyncio/sslproto.pyi +163 -0
  244. mypy/typeshed/stdlib/asyncio/staggered.pyi +10 -0
  245. mypy/typeshed/stdlib/asyncio/streams.pyi +148 -0
  246. mypy/typeshed/stdlib/asyncio/subprocess.pyi +229 -0
  247. mypy/typeshed/stdlib/asyncio/taskgroups.pyi +25 -0
  248. mypy/typeshed/stdlib/asyncio/tasks.pyi +477 -0
  249. mypy/typeshed/stdlib/asyncio/threads.pyi +9 -0
  250. mypy/typeshed/stdlib/asyncio/timeouts.pyi +19 -0
  251. mypy/typeshed/stdlib/asyncio/transports.pyi +47 -0
  252. mypy/typeshed/stdlib/asyncio/trsock.pyi +98 -0
  253. mypy/typeshed/stdlib/asyncio/unix_events.pyi +173 -0
  254. mypy/typeshed/stdlib/asyncio/windows_events.pyi +83 -0
  255. mypy/typeshed/stdlib/asyncio/windows_utils.pyi +49 -0
  256. mypy/typeshed/stdlib/asyncore.pyi +90 -0
  257. mypy/typeshed/stdlib/atexit.pyi +12 -0
  258. mypy/typeshed/stdlib/audioop.pyi +42 -0
  259. mypy/typeshed/stdlib/base64.pyi +59 -0
  260. mypy/typeshed/stdlib/bdb.pyi +102 -0
  261. mypy/typeshed/stdlib/binascii.pyi +36 -0
  262. mypy/typeshed/stdlib/binhex.pyi +45 -0
  263. mypy/typeshed/stdlib/bisect.pyi +4 -0
  264. mypy/typeshed/stdlib/builtins.pyi +1937 -0
  265. mypy/typeshed/stdlib/bz2.pyi +146 -0
  266. mypy/typeshed/stdlib/cProfile.pyi +35 -0
  267. mypy/typeshed/stdlib/calendar.pyi +206 -0
  268. mypy/typeshed/stdlib/cgi.pyi +118 -0
  269. mypy/typeshed/stdlib/cgitb.pyi +32 -0
  270. mypy/typeshed/stdlib/chunk.pyi +20 -0
  271. mypy/typeshed/stdlib/cmath.pyi +36 -0
  272. mypy/typeshed/stdlib/cmd.pyi +45 -0
  273. mypy/typeshed/stdlib/code.pyi +33 -0
  274. mypy/typeshed/stdlib/codecs.pyi +285 -0
  275. mypy/typeshed/stdlib/codeop.pyi +13 -0
  276. mypy/typeshed/stdlib/collections/__init__.pyi +477 -0
  277. mypy/typeshed/stdlib/collections/abc.pyi +2 -0
  278. mypy/typeshed/stdlib/colorsys.pyi +13 -0
  279. mypy/typeshed/stdlib/compileall.pyi +111 -0
  280. mypy/typeshed/stdlib/concurrent/__init__.pyi +0 -0
  281. mypy/typeshed/stdlib/concurrent/futures/__init__.pyi +32 -0
  282. mypy/typeshed/stdlib/concurrent/futures/_base.pyi +120 -0
  283. mypy/typeshed/stdlib/concurrent/futures/process.pyi +233 -0
  284. mypy/typeshed/stdlib/concurrent/futures/thread.pyi +80 -0
  285. mypy/typeshed/stdlib/configparser.pyi +313 -0
  286. mypy/typeshed/stdlib/contextlib.pyi +207 -0
  287. mypy/typeshed/stdlib/contextvars.pyi +63 -0
  288. mypy/typeshed/stdlib/copy.pyi +16 -0
  289. mypy/typeshed/stdlib/copyreg.pyi +21 -0
  290. mypy/typeshed/stdlib/crypt.pyi +12 -0
  291. mypy/typeshed/stdlib/csv.pyi +147 -0
  292. mypy/typeshed/stdlib/ctypes/__init__.pyi +187 -0
  293. mypy/typeshed/stdlib/ctypes/_endian.pyi +19 -0
  294. mypy/typeshed/stdlib/ctypes/util.pyi +6 -0
  295. mypy/typeshed/stdlib/ctypes/wintypes.pyi +298 -0
  296. mypy/typeshed/stdlib/curses/__init__.pyi +21 -0
  297. mypy/typeshed/stdlib/curses/ascii.pyi +63 -0
  298. mypy/typeshed/stdlib/curses/has_key.pyi +4 -0
  299. mypy/typeshed/stdlib/curses/panel.pyi +25 -0
  300. mypy/typeshed/stdlib/curses/textpad.pyi +13 -0
  301. mypy/typeshed/stdlib/dataclasses.pyi +313 -0
  302. mypy/typeshed/stdlib/datetime.pyi +295 -0
  303. mypy/typeshed/stdlib/dbm/__init__.pyi +95 -0
  304. mypy/typeshed/stdlib/dbm/dumb.pyi +31 -0
  305. mypy/typeshed/stdlib/dbm/gnu.pyi +40 -0
  306. mypy/typeshed/stdlib/dbm/ndbm.pyi +36 -0
  307. mypy/typeshed/stdlib/decimal.pyi +2 -0
  308. mypy/typeshed/stdlib/difflib.pyi +140 -0
  309. mypy/typeshed/stdlib/dis.pyi +144 -0
  310. mypy/typeshed/stdlib/distutils/__init__.pyi +5 -0
  311. mypy/typeshed/stdlib/distutils/archive_util.pyi +20 -0
  312. mypy/typeshed/stdlib/distutils/bcppcompiler.pyi +3 -0
  313. mypy/typeshed/stdlib/distutils/ccompiler.pyi +152 -0
  314. mypy/typeshed/stdlib/distutils/cmd.pyi +66 -0
  315. mypy/typeshed/stdlib/distutils/command/__init__.pyi +0 -0
  316. mypy/typeshed/stdlib/distutils/command/bdist.pyi +25 -0
  317. mypy/typeshed/stdlib/distutils/command/bdist_dumb.pyi +21 -0
  318. mypy/typeshed/stdlib/distutils/command/bdist_msi.pyi +45 -0
  319. mypy/typeshed/stdlib/distutils/command/bdist_packager.pyi +0 -0
  320. mypy/typeshed/stdlib/distutils/command/bdist_rpm.pyi +52 -0
  321. mypy/typeshed/stdlib/distutils/command/bdist_wininst.pyi +16 -0
  322. mypy/typeshed/stdlib/distutils/command/build.pyi +31 -0
  323. mypy/typeshed/stdlib/distutils/command/build_clib.pyi +27 -0
  324. mypy/typeshed/stdlib/distutils/command/build_ext.pyi +50 -0
  325. mypy/typeshed/stdlib/distutils/command/build_py.pyi +44 -0
  326. mypy/typeshed/stdlib/distutils/command/build_scripts.pyi +24 -0
  327. mypy/typeshed/stdlib/distutils/command/check.pyi +39 -0
  328. mypy/typeshed/stdlib/distutils/command/clean.pyi +17 -0
  329. mypy/typeshed/stdlib/distutils/command/config.pyi +83 -0
  330. mypy/typeshed/stdlib/distutils/command/install.pyi +63 -0
  331. mypy/typeshed/stdlib/distutils/command/install_data.pyi +19 -0
  332. mypy/typeshed/stdlib/distutils/command/install_egg_info.pyi +18 -0
  333. mypy/typeshed/stdlib/distutils/command/install_headers.pyi +16 -0
  334. mypy/typeshed/stdlib/distutils/command/install_lib.pyi +25 -0
  335. mypy/typeshed/stdlib/distutils/command/install_scripts.pyi +18 -0
  336. mypy/typeshed/stdlib/distutils/command/register.pyi +18 -0
  337. mypy/typeshed/stdlib/distutils/command/sdist.pyi +42 -0
  338. mypy/typeshed/stdlib/distutils/command/upload.pyi +17 -0
  339. mypy/typeshed/stdlib/distutils/config.pyi +17 -0
  340. mypy/typeshed/stdlib/distutils/core.pyi +57 -0
  341. mypy/typeshed/stdlib/distutils/cygwinccompiler.pyi +20 -0
  342. mypy/typeshed/stdlib/distutils/debug.pyi +1 -0
  343. mypy/typeshed/stdlib/distutils/dep_util.pyi +3 -0
  344. mypy/typeshed/stdlib/distutils/dir_util.pyi +13 -0
  345. mypy/typeshed/stdlib/distutils/dist.pyi +146 -0
  346. mypy/typeshed/stdlib/distutils/errors.pyi +19 -0
  347. mypy/typeshed/stdlib/distutils/extension.pyi +36 -0
  348. mypy/typeshed/stdlib/distutils/fancy_getopt.pyi +34 -0
  349. mypy/typeshed/stdlib/distutils/file_util.pyi +14 -0
  350. mypy/typeshed/stdlib/distutils/filelist.pyi +50 -0
  351. mypy/typeshed/stdlib/distutils/log.pyi +25 -0
  352. mypy/typeshed/stdlib/distutils/msvccompiler.pyi +3 -0
  353. mypy/typeshed/stdlib/distutils/spawn.pyi +2 -0
  354. mypy/typeshed/stdlib/distutils/sysconfig.pyi +22 -0
  355. mypy/typeshed/stdlib/distutils/text_file.pyi +21 -0
  356. mypy/typeshed/stdlib/distutils/unixccompiler.pyi +3 -0
  357. mypy/typeshed/stdlib/distutils/util.pyi +46 -0
  358. mypy/typeshed/stdlib/distutils/version.pyi +36 -0
  359. mypy/typeshed/stdlib/doctest.pyi +248 -0
  360. mypy/typeshed/stdlib/dummy_threading.pyi +2 -0
  361. mypy/typeshed/stdlib/email/__init__.pyi +29 -0
  362. mypy/typeshed/stdlib/email/_header_value_parser.pyi +392 -0
  363. mypy/typeshed/stdlib/email/_policybase.pyi +51 -0
  364. mypy/typeshed/stdlib/email/base64mime.pyi +13 -0
  365. mypy/typeshed/stdlib/email/charset.pyi +34 -0
  366. mypy/typeshed/stdlib/email/contentmanager.pyi +11 -0
  367. mypy/typeshed/stdlib/email/encoders.pyi +8 -0
  368. mypy/typeshed/stdlib/email/errors.pyi +39 -0
  369. mypy/typeshed/stdlib/email/feedparser.pyi +23 -0
  370. mypy/typeshed/stdlib/email/generator.pyi +40 -0
  371. mypy/typeshed/stdlib/email/header.pyi +31 -0
  372. mypy/typeshed/stdlib/email/headerregistry.pyi +178 -0
  373. mypy/typeshed/stdlib/email/iterators.pyi +12 -0
  374. mypy/typeshed/stdlib/email/message.pyi +161 -0
  375. mypy/typeshed/stdlib/email/mime/__init__.pyi +0 -0
  376. mypy/typeshed/stdlib/email/mime/application.pyi +17 -0
  377. mypy/typeshed/stdlib/email/mime/audio.pyi +17 -0
  378. mypy/typeshed/stdlib/email/mime/base.pyi +8 -0
  379. mypy/typeshed/stdlib/email/mime/image.pyi +17 -0
  380. mypy/typeshed/stdlib/email/mime/message.pyi +8 -0
  381. mypy/typeshed/stdlib/email/mime/multipart.pyi +18 -0
  382. mypy/typeshed/stdlib/email/mime/nonmultipart.pyi +5 -0
  383. mypy/typeshed/stdlib/email/mime/text.pyi +9 -0
  384. mypy/typeshed/stdlib/email/parser.pyi +26 -0
  385. mypy/typeshed/stdlib/email/policy.pyi +38 -0
  386. mypy/typeshed/stdlib/email/quoprimime.pyi +28 -0
  387. mypy/typeshed/stdlib/email/utils.pyi +66 -0
  388. mypy/typeshed/stdlib/encodings/__init__.pyi +10 -0
  389. mypy/typeshed/stdlib/encodings/utf_8.pyi +21 -0
  390. mypy/typeshed/stdlib/encodings/utf_8_sig.pyi +22 -0
  391. mypy/typeshed/stdlib/ensurepip/__init__.pyi +12 -0
  392. mypy/typeshed/stdlib/enum.pyi +317 -0
  393. mypy/typeshed/stdlib/errno.pyi +222 -0
  394. mypy/typeshed/stdlib/faulthandler.pyi +13 -0
  395. mypy/typeshed/stdlib/fcntl.pyi +127 -0
  396. mypy/typeshed/stdlib/filecmp.pyi +57 -0
  397. mypy/typeshed/stdlib/fileinput.pyi +213 -0
  398. mypy/typeshed/stdlib/fnmatch.pyi +9 -0
  399. mypy/typeshed/stdlib/formatter.pyi +88 -0
  400. mypy/typeshed/stdlib/fractions.pyi +150 -0
  401. mypy/typeshed/stdlib/ftplib.pyi +178 -0
  402. mypy/typeshed/stdlib/functools.pyi +200 -0
  403. mypy/typeshed/stdlib/gc.pyi +37 -0
  404. mypy/typeshed/stdlib/genericpath.pyi +52 -0
  405. mypy/typeshed/stdlib/getopt.pyi +11 -0
  406. mypy/typeshed/stdlib/getpass.pyi +8 -0
  407. mypy/typeshed/stdlib/gettext.pyi +169 -0
  408. mypy/typeshed/stdlib/glob.pyi +42 -0
  409. mypy/typeshed/stdlib/graphlib.pyi +28 -0
  410. mypy/typeshed/stdlib/grp.pyi +21 -0
  411. mypy/typeshed/stdlib/gzip.pyi +160 -0
  412. mypy/typeshed/stdlib/hashlib.pyi +165 -0
  413. mypy/typeshed/stdlib/heapq.pyi +17 -0
  414. mypy/typeshed/stdlib/hmac.pyi +38 -0
  415. mypy/typeshed/stdlib/html/__init__.pyi +6 -0
  416. mypy/typeshed/stdlib/html/entities.pyi +6 -0
  417. mypy/typeshed/stdlib/html/parser.pyi +34 -0
  418. mypy/typeshed/stdlib/http/__init__.pyi +105 -0
  419. mypy/typeshed/stdlib/http/client.pyi +259 -0
  420. mypy/typeshed/stdlib/http/cookiejar.pyi +159 -0
  421. mypy/typeshed/stdlib/http/cookies.pyi +60 -0
  422. mypy/typeshed/stdlib/http/server.pyi +83 -0
  423. mypy/typeshed/stdlib/imaplib.pyi +168 -0
  424. mypy/typeshed/stdlib/imghdr.pyi +17 -0
  425. mypy/typeshed/stdlib/imp.pyi +62 -0
  426. mypy/typeshed/stdlib/importlib/__init__.pyi +24 -0
  427. mypy/typeshed/stdlib/importlib/_abc.pyi +15 -0
  428. mypy/typeshed/stdlib/importlib/abc.pyi +172 -0
  429. mypy/typeshed/stdlib/importlib/machinery.pyi +179 -0
  430. mypy/typeshed/stdlib/importlib/metadata/__init__.pyi +276 -0
  431. mypy/typeshed/stdlib/importlib/metadata/_meta.pyi +40 -0
  432. mypy/typeshed/stdlib/importlib/readers.pyi +68 -0
  433. mypy/typeshed/stdlib/importlib/resources/__init__.pyi +46 -0
  434. mypy/typeshed/stdlib/importlib/resources/abc.pyi +12 -0
  435. mypy/typeshed/stdlib/importlib/resources/readers.pyi +14 -0
  436. mypy/typeshed/stdlib/importlib/resources/simple.pyi +49 -0
  437. mypy/typeshed/stdlib/importlib/simple.pyi +11 -0
  438. mypy/typeshed/stdlib/importlib/util.pyi +43 -0
  439. mypy/typeshed/stdlib/inspect.pyi +631 -0
  440. mypy/typeshed/stdlib/io.pyi +204 -0
  441. mypy/typeshed/stdlib/ipaddress.pyi +208 -0
  442. mypy/typeshed/stdlib/itertools.pyi +293 -0
  443. mypy/typeshed/stdlib/json/__init__.pyi +61 -0
  444. mypy/typeshed/stdlib/json/decoder.pyi +32 -0
  445. mypy/typeshed/stdlib/json/encoder.pyi +38 -0
  446. mypy/typeshed/stdlib/json/tool.pyi +1 -0
  447. mypy/typeshed/stdlib/keyword.pyi +21 -0
  448. mypy/typeshed/stdlib/lib2to3/__init__.pyi +0 -0
  449. mypy/typeshed/stdlib/lib2to3/btm_matcher.pyi +28 -0
  450. mypy/typeshed/stdlib/lib2to3/fixer_base.pyi +42 -0
  451. mypy/typeshed/stdlib/lib2to3/fixes/__init__.pyi +0 -0
  452. mypy/typeshed/stdlib/lib2to3/fixes/fix_apply.pyi +8 -0
  453. mypy/typeshed/stdlib/lib2to3/fixes/fix_asserts.pyi +10 -0
  454. mypy/typeshed/stdlib/lib2to3/fixes/fix_basestring.pyi +8 -0
  455. mypy/typeshed/stdlib/lib2to3/fixes/fix_buffer.pyi +8 -0
  456. mypy/typeshed/stdlib/lib2to3/fixes/fix_dict.pyi +16 -0
  457. mypy/typeshed/stdlib/lib2to3/fixes/fix_except.pyi +14 -0
  458. mypy/typeshed/stdlib/lib2to3/fixes/fix_exec.pyi +8 -0
  459. mypy/typeshed/stdlib/lib2to3/fixes/fix_execfile.pyi +8 -0
  460. mypy/typeshed/stdlib/lib2to3/fixes/fix_exitfunc.pyi +13 -0
  461. mypy/typeshed/stdlib/lib2to3/fixes/fix_filter.pyi +9 -0
  462. mypy/typeshed/stdlib/lib2to3/fixes/fix_funcattrs.pyi +8 -0
  463. mypy/typeshed/stdlib/lib2to3/fixes/fix_future.pyi +8 -0
  464. mypy/typeshed/stdlib/lib2to3/fixes/fix_getcwdu.pyi +8 -0
  465. mypy/typeshed/stdlib/lib2to3/fixes/fix_has_key.pyi +8 -0
  466. mypy/typeshed/stdlib/lib2to3/fixes/fix_idioms.pyi +15 -0
  467. mypy/typeshed/stdlib/lib2to3/fixes/fix_import.pyi +16 -0
  468. mypy/typeshed/stdlib/lib2to3/fixes/fix_imports.pyi +21 -0
  469. mypy/typeshed/stdlib/lib2to3/fixes/fix_imports2.pyi +6 -0
  470. mypy/typeshed/stdlib/lib2to3/fixes/fix_input.pyi +11 -0
  471. mypy/typeshed/stdlib/lib2to3/fixes/fix_intern.pyi +9 -0
  472. mypy/typeshed/stdlib/lib2to3/fixes/fix_isinstance.pyi +8 -0
  473. mypy/typeshed/stdlib/lib2to3/fixes/fix_itertools.pyi +9 -0
  474. mypy/typeshed/stdlib/lib2to3/fixes/fix_itertools_imports.pyi +7 -0
  475. mypy/typeshed/stdlib/lib2to3/fixes/fix_long.pyi +7 -0
  476. mypy/typeshed/stdlib/lib2to3/fixes/fix_map.pyi +9 -0
  477. mypy/typeshed/stdlib/lib2to3/fixes/fix_metaclass.pyi +17 -0
  478. mypy/typeshed/stdlib/lib2to3/fixes/fix_methodattrs.pyi +10 -0
  479. mypy/typeshed/stdlib/lib2to3/fixes/fix_ne.pyi +8 -0
  480. mypy/typeshed/stdlib/lib2to3/fixes/fix_next.pyi +19 -0
  481. mypy/typeshed/stdlib/lib2to3/fixes/fix_nonzero.pyi +8 -0
  482. mypy/typeshed/stdlib/lib2to3/fixes/fix_numliterals.pyi +8 -0
  483. mypy/typeshed/stdlib/lib2to3/fixes/fix_operator.pyi +12 -0
  484. mypy/typeshed/stdlib/lib2to3/fixes/fix_paren.pyi +8 -0
  485. mypy/typeshed/stdlib/lib2to3/fixes/fix_print.pyi +12 -0
  486. mypy/typeshed/stdlib/lib2to3/fixes/fix_raise.pyi +8 -0
  487. mypy/typeshed/stdlib/lib2to3/fixes/fix_raw_input.pyi +8 -0
  488. mypy/typeshed/stdlib/lib2to3/fixes/fix_reduce.pyi +8 -0
  489. mypy/typeshed/stdlib/lib2to3/fixes/fix_reload.pyi +9 -0
  490. mypy/typeshed/stdlib/lib2to3/fixes/fix_renames.pyi +17 -0
  491. mypy/typeshed/stdlib/lib2to3/fixes/fix_repr.pyi +8 -0
  492. mypy/typeshed/stdlib/lib2to3/fixes/fix_set_literal.pyi +7 -0
  493. mypy/typeshed/stdlib/lib2to3/fixes/fix_standarderror.pyi +8 -0
  494. mypy/typeshed/stdlib/lib2to3/fixes/fix_sys_exc.pyi +9 -0
  495. mypy/typeshed/stdlib/lib2to3/fixes/fix_throw.pyi +8 -0
  496. mypy/typeshed/stdlib/lib2to3/fixes/fix_tuple_params.pyi +17 -0
  497. mypy/typeshed/stdlib/lib2to3/fixes/fix_types.pyi +8 -0
  498. mypy/typeshed/stdlib/lib2to3/fixes/fix_unicode.pyi +12 -0
  499. mypy/typeshed/stdlib/lib2to3/fixes/fix_urllib.pyi +15 -0
  500. mypy/typeshed/stdlib/lib2to3/fixes/fix_ws_comma.pyi +12 -0
  501. mypy/typeshed/stdlib/lib2to3/fixes/fix_xrange.pyi +20 -0
  502. mypy/typeshed/stdlib/lib2to3/fixes/fix_xreadlines.pyi +8 -0
  503. mypy/typeshed/stdlib/lib2to3/fixes/fix_zip.pyi +9 -0
  504. mypy/typeshed/stdlib/lib2to3/main.pyi +42 -0
  505. mypy/typeshed/stdlib/lib2to3/pgen2/__init__.pyi +9 -0
  506. mypy/typeshed/stdlib/lib2to3/pgen2/driver.pyi +27 -0
  507. mypy/typeshed/stdlib/lib2to3/pgen2/grammar.pyi +24 -0
  508. mypy/typeshed/stdlib/lib2to3/pgen2/literals.pyi +7 -0
  509. mypy/typeshed/stdlib/lib2to3/pgen2/parse.pyi +30 -0
  510. mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi +50 -0
  511. mypy/typeshed/stdlib/lib2to3/pgen2/token.pyi +67 -0
  512. mypy/typeshed/stdlib/lib2to3/pgen2/tokenize.pyi +96 -0
  513. mypy/typeshed/stdlib/lib2to3/pygram.pyi +114 -0
  514. mypy/typeshed/stdlib/lib2to3/pytree.pyi +117 -0
  515. mypy/typeshed/stdlib/lib2to3/refactor.pyi +82 -0
  516. mypy/typeshed/stdlib/linecache.pyi +23 -0
  517. mypy/typeshed/stdlib/locale.pyi +152 -0
  518. mypy/typeshed/stdlib/logging/__init__.pyi +655 -0
  519. mypy/typeshed/stdlib/logging/config.pyi +134 -0
  520. mypy/typeshed/stdlib/logging/handlers.pyi +275 -0
  521. mypy/typeshed/stdlib/lzma.pyi +197 -0
  522. mypy/typeshed/stdlib/mailbox.pyi +256 -0
  523. mypy/typeshed/stdlib/mailcap.pyi +11 -0
  524. mypy/typeshed/stdlib/marshal.pyi +33 -0
  525. mypy/typeshed/stdlib/math.pyi +125 -0
  526. mypy/typeshed/stdlib/mimetypes.pyi +46 -0
  527. mypy/typeshed/stdlib/mmap.pyi +113 -0
  528. mypy/typeshed/stdlib/modulefinder.pyi +66 -0
  529. mypy/typeshed/stdlib/msilib/__init__.pyi +176 -0
  530. mypy/typeshed/stdlib/msilib/schema.pyi +94 -0
  531. mypy/typeshed/stdlib/msilib/sequence.pyi +13 -0
  532. mypy/typeshed/stdlib/msilib/text.pyi +7 -0
  533. mypy/typeshed/stdlib/msvcrt.pyi +32 -0
  534. mypy/typeshed/stdlib/multiprocessing/__init__.pyi +90 -0
  535. mypy/typeshed/stdlib/multiprocessing/connection.pyi +75 -0
  536. mypy/typeshed/stdlib/multiprocessing/context.pyi +187 -0
  537. mypy/typeshed/stdlib/multiprocessing/dummy/__init__.pyi +77 -0
  538. mypy/typeshed/stdlib/multiprocessing/dummy/connection.pyi +39 -0
  539. mypy/typeshed/stdlib/multiprocessing/forkserver.pyi +31 -0
  540. mypy/typeshed/stdlib/multiprocessing/heap.pyi +36 -0
  541. mypy/typeshed/stdlib/multiprocessing/managers.pyi +212 -0
  542. mypy/typeshed/stdlib/multiprocessing/pool.pyi +103 -0
  543. mypy/typeshed/stdlib/multiprocessing/popen_fork.pyi +23 -0
  544. mypy/typeshed/stdlib/multiprocessing/popen_forkserver.pyi +16 -0
  545. mypy/typeshed/stdlib/multiprocessing/popen_spawn_posix.pyi +20 -0
  546. mypy/typeshed/stdlib/multiprocessing/popen_spawn_win32.pyi +30 -0
  547. mypy/typeshed/stdlib/multiprocessing/process.pyi +39 -0
  548. mypy/typeshed/stdlib/multiprocessing/queues.pyi +41 -0
  549. mypy/typeshed/stdlib/multiprocessing/reduction.pyi +89 -0
  550. mypy/typeshed/stdlib/multiprocessing/resource_sharer.pyi +20 -0
  551. mypy/typeshed/stdlib/multiprocessing/resource_tracker.pyi +18 -0
  552. mypy/typeshed/stdlib/multiprocessing/shared_memory.pyi +40 -0
  553. mypy/typeshed/stdlib/multiprocessing/sharedctypes.pyi +101 -0
  554. mypy/typeshed/stdlib/multiprocessing/spawn.pyi +32 -0
  555. mypy/typeshed/stdlib/multiprocessing/synchronize.pyi +54 -0
  556. mypy/typeshed/stdlib/multiprocessing/util.pyi +79 -0
  557. mypy/typeshed/stdlib/netrc.pyi +23 -0
  558. mypy/typeshed/stdlib/nis.pyi +9 -0
  559. mypy/typeshed/stdlib/nntplib.pyi +125 -0
  560. mypy/typeshed/stdlib/nt.pyi +111 -0
  561. mypy/typeshed/stdlib/ntpath.pyi +119 -0
  562. mypy/typeshed/stdlib/nturl2path.pyi +2 -0
  563. mypy/typeshed/stdlib/numbers.pyi +154 -0
  564. mypy/typeshed/stdlib/opcode.pyi +59 -0
  565. mypy/typeshed/stdlib/operator.pyi +110 -0
  566. mypy/typeshed/stdlib/optparse.pyi +252 -0
  567. mypy/typeshed/stdlib/os/__init__.pyi +1139 -0
  568. mypy/typeshed/stdlib/os/path.pyi +8 -0
  569. mypy/typeshed/stdlib/ossaudiodev.pyi +131 -0
  570. mypy/typeshed/stdlib/parser.pyi +24 -0
  571. mypy/typeshed/stdlib/pathlib.pyi +232 -0
  572. mypy/typeshed/stdlib/pdb.pyi +181 -0
  573. mypy/typeshed/stdlib/pickle.pyi +270 -0
  574. mypy/typeshed/stdlib/pickletools.pyi +167 -0
  575. mypy/typeshed/stdlib/pipes.pyi +16 -0
  576. mypy/typeshed/stdlib/pkgutil.pyi +53 -0
  577. mypy/typeshed/stdlib/platform.pyi +42 -0
  578. mypy/typeshed/stdlib/plistlib.pyi +113 -0
  579. mypy/typeshed/stdlib/poplib.pyi +71 -0
  580. mypy/typeshed/stdlib/posix.pyi +359 -0
  581. mypy/typeshed/stdlib/posixpath.pyi +161 -0
  582. mypy/typeshed/stdlib/pprint.pyi +112 -0
  583. mypy/typeshed/stdlib/profile.pyi +31 -0
  584. mypy/typeshed/stdlib/pstats.pyi +78 -0
  585. mypy/typeshed/stdlib/pty.pyi +19 -0
  586. mypy/typeshed/stdlib/pwd.pyi +27 -0
  587. mypy/typeshed/stdlib/py_compile.pyi +34 -0
  588. mypy/typeshed/stdlib/pyclbr.pyi +74 -0
  589. mypy/typeshed/stdlib/pydoc.pyi +261 -0
  590. mypy/typeshed/stdlib/pydoc_data/__init__.pyi +0 -0
  591. mypy/typeshed/stdlib/pydoc_data/topics.pyi +1 -0
  592. mypy/typeshed/stdlib/pyexpat/__init__.pyi +80 -0
  593. mypy/typeshed/stdlib/pyexpat/errors.pyi +49 -0
  594. mypy/typeshed/stdlib/pyexpat/model.pyi +11 -0
  595. mypy/typeshed/stdlib/queue.pyi +58 -0
  596. mypy/typeshed/stdlib/quopri.pyi +11 -0
  597. mypy/typeshed/stdlib/random.pyi +138 -0
  598. mypy/typeshed/stdlib/re.pyi +290 -0
  599. mypy/typeshed/stdlib/readline.pyi +36 -0
  600. mypy/typeshed/stdlib/reprlib.pyi +65 -0
  601. mypy/typeshed/stdlib/resource.pyi +92 -0
  602. mypy/typeshed/stdlib/rlcompleter.pyi +9 -0
  603. mypy/typeshed/stdlib/runpy.pyi +24 -0
  604. mypy/typeshed/stdlib/sched.pyi +42 -0
  605. mypy/typeshed/stdlib/secrets.pyi +15 -0
  606. mypy/typeshed/stdlib/select.pyi +151 -0
  607. mypy/typeshed/stdlib/selectors.pyi +67 -0
  608. mypy/typeshed/stdlib/shelve.pyi +46 -0
  609. mypy/typeshed/stdlib/shlex.pyi +43 -0
  610. mypy/typeshed/stdlib/shutil.pyi +189 -0
  611. mypy/typeshed/stdlib/signal.pyi +189 -0
  612. mypy/typeshed/stdlib/site.pyi +27 -0
  613. mypy/typeshed/stdlib/smtpd.pyi +91 -0
  614. mypy/typeshed/stdlib/smtplib.pyi +204 -0
  615. mypy/typeshed/stdlib/sndhdr.pyi +14 -0
  616. mypy/typeshed/stdlib/socket.pyi +825 -0
  617. mypy/typeshed/stdlib/socketserver.pyi +168 -0
  618. mypy/typeshed/stdlib/spwd.pyi +40 -0
  619. mypy/typeshed/stdlib/sqlite3/__init__.pyi +1 -0
  620. mypy/typeshed/stdlib/sqlite3/dbapi2.pyi +469 -0
  621. mypy/typeshed/stdlib/sre_compile.pyi +11 -0
  622. mypy/typeshed/stdlib/sre_constants.pyi +130 -0
  623. mypy/typeshed/stdlib/sre_parse.pyi +104 -0
  624. mypy/typeshed/stdlib/ssl.pyi +529 -0
  625. mypy/typeshed/stdlib/stat.pyi +1 -0
  626. mypy/typeshed/stdlib/statistics.pyi +132 -0
  627. mypy/typeshed/stdlib/string.pyi +83 -0
  628. mypy/typeshed/stdlib/stringprep.pyi +27 -0
  629. mypy/typeshed/stdlib/struct.pyi +26 -0
  630. mypy/typeshed/stdlib/subprocess.pyi +2614 -0
  631. mypy/typeshed/stdlib/sunau.pyi +86 -0
  632. mypy/typeshed/stdlib/symbol.pyi +93 -0
  633. mypy/typeshed/stdlib/symtable.pyi +58 -0
  634. mypy/typeshed/stdlib/sys/__init__.pyi +373 -0
  635. mypy/typeshed/stdlib/sys/_monitoring.pyi +52 -0
  636. mypy/typeshed/stdlib/sysconfig.pyi +43 -0
  637. mypy/typeshed/stdlib/syslog.pyi +46 -0
  638. mypy/typeshed/stdlib/tabnanny.pyi +16 -0
  639. mypy/typeshed/stdlib/tarfile.pyi +438 -0
  640. mypy/typeshed/stdlib/telnetlib.pyi +122 -0
  641. mypy/typeshed/stdlib/tempfile.pyi +477 -0
  642. mypy/typeshed/stdlib/termios.pyi +267 -0
  643. mypy/typeshed/stdlib/textwrap.pyi +103 -0
  644. mypy/typeshed/stdlib/this.pyi +2 -0
  645. mypy/typeshed/stdlib/threading.pyi +187 -0
  646. mypy/typeshed/stdlib/time.pyi +107 -0
  647. mypy/typeshed/stdlib/timeit.pyi +32 -0
  648. mypy/typeshed/stdlib/tkinter/__init__.pyi +3641 -0
  649. mypy/typeshed/stdlib/tkinter/colorchooser.pyi +20 -0
  650. mypy/typeshed/stdlib/tkinter/commondialog.pyi +14 -0
  651. mypy/typeshed/stdlib/tkinter/constants.pyi +80 -0
  652. mypy/typeshed/stdlib/tkinter/dialog.pyi +16 -0
  653. mypy/typeshed/stdlib/tkinter/dnd.pyi +20 -0
  654. mypy/typeshed/stdlib/tkinter/filedialog.pyi +151 -0
  655. mypy/typeshed/stdlib/tkinter/font.pyi +116 -0
  656. mypy/typeshed/stdlib/tkinter/messagebox.pyi +44 -0
  657. mypy/typeshed/stdlib/tkinter/scrolledtext.pyi +10 -0
  658. mypy/typeshed/stdlib/tkinter/simpledialog.pyi +54 -0
  659. mypy/typeshed/stdlib/tkinter/tix.pyi +299 -0
  660. mypy/typeshed/stdlib/tkinter/ttk.pyi +1191 -0
  661. mypy/typeshed/stdlib/token.pyi +159 -0
  662. mypy/typeshed/stdlib/tokenize.pyi +177 -0
  663. mypy/typeshed/stdlib/tomllib.pyi +10 -0
  664. mypy/typeshed/stdlib/trace.pyi +79 -0
  665. mypy/typeshed/stdlib/traceback.pyi +260 -0
  666. mypy/typeshed/stdlib/tracemalloc.pyi +124 -0
  667. mypy/typeshed/stdlib/tty.pyi +30 -0
  668. mypy/typeshed/stdlib/turtle.pyi +713 -0
  669. mypy/typeshed/stdlib/types.pyi +605 -0
  670. mypy/typeshed/stdlib/typing.pyi +968 -0
  671. mypy/typeshed/stdlib/typing_extensions.pyi +503 -0
  672. mypy/typeshed/stdlib/unicodedata.pyi +71 -0
  673. mypy/typeshed/stdlib/unittest/__init__.pyi +67 -0
  674. mypy/typeshed/stdlib/unittest/_log.pyi +27 -0
  675. mypy/typeshed/stdlib/unittest/async_case.pyi +21 -0
  676. mypy/typeshed/stdlib/unittest/case.pyi +342 -0
  677. mypy/typeshed/stdlib/unittest/loader.pyi +51 -0
  678. mypy/typeshed/stdlib/unittest/main.pyi +69 -0
  679. mypy/typeshed/stdlib/unittest/mock.pyi +430 -0
  680. mypy/typeshed/stdlib/unittest/result.pyi +46 -0
  681. mypy/typeshed/stdlib/unittest/runner.pyi +72 -0
  682. mypy/typeshed/stdlib/unittest/signals.pyi +15 -0
  683. mypy/typeshed/stdlib/unittest/suite.pyi +22 -0
  684. mypy/typeshed/stdlib/unittest/util.pyi +23 -0
  685. mypy/typeshed/stdlib/urllib/__init__.pyi +0 -0
  686. mypy/typeshed/stdlib/urllib/error.pyi +23 -0
  687. mypy/typeshed/stdlib/urllib/parse.pyi +210 -0
  688. mypy/typeshed/stdlib/urllib/request.pyi +399 -0
  689. mypy/typeshed/stdlib/urllib/response.pyi +43 -0
  690. mypy/typeshed/stdlib/urllib/robotparser.pyi +20 -0
  691. mypy/typeshed/stdlib/uu.pyi +13 -0
  692. mypy/typeshed/stdlib/uuid.pyi +100 -0
  693. mypy/typeshed/stdlib/venv/__init__.pyi +79 -0
  694. mypy/typeshed/stdlib/warnings.pyi +112 -0
  695. mypy/typeshed/stdlib/wave.pyi +85 -0
  696. mypy/typeshed/stdlib/weakref.pyi +150 -0
  697. mypy/typeshed/stdlib/webbrowser.pyi +74 -0
  698. mypy/typeshed/stdlib/winreg.pyi +103 -0
  699. mypy/typeshed/stdlib/winsound.pyi +28 -0
  700. mypy/typeshed/stdlib/wsgiref/__init__.pyi +0 -0
  701. mypy/typeshed/stdlib/wsgiref/handlers.pyi +91 -0
  702. mypy/typeshed/stdlib/wsgiref/headers.pyi +26 -0
  703. mypy/typeshed/stdlib/wsgiref/simple_server.pyi +37 -0
  704. mypy/typeshed/stdlib/wsgiref/types.pyi +32 -0
  705. mypy/typeshed/stdlib/wsgiref/util.pyi +24 -0
  706. mypy/typeshed/stdlib/wsgiref/validate.pyi +50 -0
  707. mypy/typeshed/stdlib/xdrlib.pyi +57 -0
  708. mypy/typeshed/stdlib/xml/__init__.pyi +1 -0
  709. mypy/typeshed/stdlib/xml/dom/NodeFilter.pyi +19 -0
  710. mypy/typeshed/stdlib/xml/dom/__init__.pyi +69 -0
  711. mypy/typeshed/stdlib/xml/dom/domreg.pyi +8 -0
  712. mypy/typeshed/stdlib/xml/dom/expatbuilder.pyi +100 -0
  713. mypy/typeshed/stdlib/xml/dom/minicompat.pyi +22 -0
  714. mypy/typeshed/stdlib/xml/dom/minidom.pyi +404 -0
  715. mypy/typeshed/stdlib/xml/dom/pulldom.pyi +94 -0
  716. mypy/typeshed/stdlib/xml/dom/xmlbuilder.pyi +108 -0
  717. mypy/typeshed/stdlib/xml/etree/ElementInclude.pyi +28 -0
  718. mypy/typeshed/stdlib/xml/etree/ElementPath.pyi +34 -0
  719. mypy/typeshed/stdlib/xml/etree/ElementTree.pyi +321 -0
  720. mypy/typeshed/stdlib/xml/etree/__init__.pyi +0 -0
  721. mypy/typeshed/stdlib/xml/etree/cElementTree.pyi +1 -0
  722. mypy/typeshed/stdlib/xml/parsers/__init__.pyi +1 -0
  723. mypy/typeshed/stdlib/xml/parsers/expat/__init__.pyi +1 -0
  724. mypy/typeshed/stdlib/xml/parsers/expat/errors.pyi +1 -0
  725. mypy/typeshed/stdlib/xml/parsers/expat/model.pyi +1 -0
  726. mypy/typeshed/stdlib/xml/sax/__init__.pyi +25 -0
  727. mypy/typeshed/stdlib/xml/sax/_exceptions.pyi +19 -0
  728. mypy/typeshed/stdlib/xml/sax/handler.pyi +55 -0
  729. mypy/typeshed/stdlib/xml/sax/saxutils.pyi +60 -0
  730. mypy/typeshed/stdlib/xml/sax/xmlreader.pyi +87 -0
  731. mypy/typeshed/stdlib/xmlrpc/__init__.pyi +0 -0
  732. mypy/typeshed/stdlib/xmlrpc/client.pyi +296 -0
  733. mypy/typeshed/stdlib/xmlrpc/server.pyi +143 -0
  734. mypy/typeshed/stdlib/xxlimited.pyi +22 -0
  735. mypy/typeshed/stdlib/zipapp.pyi +20 -0
  736. mypy/typeshed/stdlib/zipfile/__init__.pyi +306 -0
  737. mypy/typeshed/stdlib/zipfile/_path.pyi +95 -0
  738. mypy/typeshed/stdlib/zipimport.pyi +32 -0
  739. mypy/typeshed/stdlib/zlib.pyi +56 -0
  740. mypy/typeshed/stdlib/zoneinfo/__init__.pyi +38 -0
  741. mypy/typeshed/stubs/mypy-extensions/mypy_extensions.pyi +218 -0
  742. mypy/typestate.py +323 -0
  743. mypy/typetraverser.py +142 -0
  744. mypy/typevars.py +93 -0
  745. mypy/typevartuples.py +32 -0
  746. mypy/util.py +869 -0
  747. mypy/version.py +1 -0
  748. mypy/visitor.py +621 -0
  749. mypy/xml/mypy-html.css +104 -0
  750. mypy/xml/mypy-html.xslt +81 -0
  751. mypy/xml/mypy-txt.xslt +100 -0
  752. mypy/xml/mypy.xsd +50 -0
  753. mypy_dev-1.9.0.dev0.dist-info/LICENSE +229 -0
  754. mypy_dev-1.9.0.dev0.dist-info/METADATA +39 -0
  755. mypy_dev-1.9.0.dev0.dist-info/RECORD +1018 -0
  756. mypy_dev-1.9.0.dev0.dist-info/WHEEL +5 -0
  757. mypy_dev-1.9.0.dev0.dist-info/entry_points.txt +6 -0
  758. mypy_dev-1.9.0.dev0.dist-info/top_level.txt +2 -0
  759. mypyc/README.md +133 -0
  760. mypyc/__init__.py +0 -0
  761. mypyc/__main__.py +57 -0
  762. mypyc/analysis/__init__.py +0 -0
  763. mypyc/analysis/attrdefined.py +436 -0
  764. mypyc/analysis/blockfreq.py +32 -0
  765. mypyc/analysis/dataflow.py +624 -0
  766. mypyc/analysis/ircheck.py +429 -0
  767. mypyc/analysis/selfleaks.py +207 -0
  768. mypyc/build.py +616 -0
  769. mypyc/codegen/__init__.py +0 -0
  770. mypyc/codegen/cstring.py +54 -0
  771. mypyc/codegen/emit.py +1193 -0
  772. mypyc/codegen/emitclass.py +1060 -0
  773. mypyc/codegen/emitfunc.py +846 -0
  774. mypyc/codegen/emitmodule.py +1131 -0
  775. mypyc/codegen/emitwrapper.py +979 -0
  776. mypyc/codegen/literals.py +302 -0
  777. mypyc/common.py +136 -0
  778. mypyc/crash.py +31 -0
  779. mypyc/doc/Makefile +20 -0
  780. mypyc/doc/bool_operations.rst +27 -0
  781. mypyc/doc/compilation_units.rst +20 -0
  782. mypyc/doc/conf.py +59 -0
  783. mypyc/doc/cpython-timings.md +25 -0
  784. mypyc/doc/dev-intro.md +548 -0
  785. mypyc/doc/dict_operations.rst +59 -0
  786. mypyc/doc/differences_from_python.rst +332 -0
  787. mypyc/doc/float_operations.rst +50 -0
  788. mypyc/doc/future.md +42 -0
  789. mypyc/doc/getting_started.rst +240 -0
  790. mypyc/doc/index.rst +61 -0
  791. mypyc/doc/int_operations.rst +162 -0
  792. mypyc/doc/introduction.rst +150 -0
  793. mypyc/doc/list_operations.rst +65 -0
  794. mypyc/doc/make.bat +35 -0
  795. mypyc/doc/native_classes.rst +206 -0
  796. mypyc/doc/native_operations.rst +55 -0
  797. mypyc/doc/performance_tips_and_tricks.rst +244 -0
  798. mypyc/doc/set_operations.rst +47 -0
  799. mypyc/doc/str_operations.rst +35 -0
  800. mypyc/doc/tuple_operations.rst +33 -0
  801. mypyc/doc/using_type_annotations.rst +398 -0
  802. mypyc/errors.py +29 -0
  803. mypyc/external/googletest/LICENSE +28 -0
  804. mypyc/external/googletest/README.md +280 -0
  805. mypyc/external/googletest/include/gtest/gtest-death-test.h +294 -0
  806. mypyc/external/googletest/include/gtest/gtest-message.h +250 -0
  807. mypyc/external/googletest/include/gtest/gtest-param-test.h +1444 -0
  808. mypyc/external/googletest/include/gtest/gtest-param-test.h.pump +510 -0
  809. mypyc/external/googletest/include/gtest/gtest-printers.h +993 -0
  810. mypyc/external/googletest/include/gtest/gtest-spi.h +232 -0
  811. mypyc/external/googletest/include/gtest/gtest-test-part.h +179 -0
  812. mypyc/external/googletest/include/gtest/gtest-typed-test.h +263 -0
  813. mypyc/external/googletest/include/gtest/gtest.h +2236 -0
  814. mypyc/external/googletest/include/gtest/gtest_pred_impl.h +358 -0
  815. mypyc/external/googletest/include/gtest/gtest_prod.h +58 -0
  816. mypyc/external/googletest/include/gtest/internal/custom/gtest-port.h +69 -0
  817. mypyc/external/googletest/include/gtest/internal/custom/gtest-printers.h +42 -0
  818. mypyc/external/googletest/include/gtest/internal/custom/gtest.h +41 -0
  819. mypyc/external/googletest/include/gtest/internal/gtest-death-test-internal.h +319 -0
  820. mypyc/external/googletest/include/gtest/internal/gtest-filepath.h +206 -0
  821. mypyc/external/googletest/include/gtest/internal/gtest-internal.h +1238 -0
  822. mypyc/external/googletest/include/gtest/internal/gtest-linked_ptr.h +243 -0
  823. mypyc/external/googletest/include/gtest/internal/gtest-param-util-generated.h +5146 -0
  824. mypyc/external/googletest/include/gtest/internal/gtest-param-util-generated.h.pump +286 -0
  825. mypyc/external/googletest/include/gtest/internal/gtest-param-util.h +731 -0
  826. mypyc/external/googletest/include/gtest/internal/gtest-port-arch.h +93 -0
  827. mypyc/external/googletest/include/gtest/internal/gtest-port.h +2560 -0
  828. mypyc/external/googletest/include/gtest/internal/gtest-string.h +167 -0
  829. mypyc/external/googletest/include/gtest/internal/gtest-tuple.h +1020 -0
  830. mypyc/external/googletest/include/gtest/internal/gtest-tuple.h.pump +347 -0
  831. mypyc/external/googletest/include/gtest/internal/gtest-type-util.h +3331 -0
  832. mypyc/external/googletest/include/gtest/internal/gtest-type-util.h.pump +297 -0
  833. mypyc/external/googletest/make/Makefile +61 -0
  834. mypyc/external/googletest/src/gtest-all.cc +48 -0
  835. mypyc/external/googletest/src/gtest-death-test.cc +1342 -0
  836. mypyc/external/googletest/src/gtest-filepath.cc +387 -0
  837. mypyc/external/googletest/src/gtest-internal-inl.h +1183 -0
  838. mypyc/external/googletest/src/gtest-port.cc +1259 -0
  839. mypyc/external/googletest/src/gtest-printers.cc +373 -0
  840. mypyc/external/googletest/src/gtest-test-part.cc +110 -0
  841. mypyc/external/googletest/src/gtest-typed-test.cc +118 -0
  842. mypyc/external/googletest/src/gtest.cc +5388 -0
  843. mypyc/external/googletest/src/gtest_main.cc +38 -0
  844. mypyc/ir/__init__.py +0 -0
  845. mypyc/ir/class_ir.py +499 -0
  846. mypyc/ir/func_ir.py +370 -0
  847. mypyc/ir/module_ir.py +88 -0
  848. mypyc/ir/ops.py +1642 -0
  849. mypyc/ir/pprint.py +496 -0
  850. mypyc/ir/rtypes.py +1038 -0
  851. mypyc/irbuild/__init__.py +0 -0
  852. mypyc/irbuild/ast_helpers.py +120 -0
  853. mypyc/irbuild/builder.py +1398 -0
  854. mypyc/irbuild/callable_class.py +173 -0
  855. mypyc/irbuild/classdef.py +850 -0
  856. mypyc/irbuild/constant_fold.py +95 -0
  857. mypyc/irbuild/context.py +186 -0
  858. mypyc/irbuild/env_class.py +223 -0
  859. mypyc/irbuild/expression.py +1067 -0
  860. mypyc/irbuild/for_helpers.py +1046 -0
  861. mypyc/irbuild/format_str_tokenizer.py +250 -0
  862. mypyc/irbuild/function.py +1089 -0
  863. mypyc/irbuild/generator.py +346 -0
  864. mypyc/irbuild/ll_builder.py +2407 -0
  865. mypyc/irbuild/main.py +153 -0
  866. mypyc/irbuild/mapper.py +221 -0
  867. mypyc/irbuild/match.py +355 -0
  868. mypyc/irbuild/nonlocalcontrol.py +197 -0
  869. mypyc/irbuild/prebuildvisitor.py +203 -0
  870. mypyc/irbuild/prepare.py +609 -0
  871. mypyc/irbuild/specialize.py +822 -0
  872. mypyc/irbuild/statement.py +1017 -0
  873. mypyc/irbuild/targets.py +57 -0
  874. mypyc/irbuild/util.py +189 -0
  875. mypyc/irbuild/visitor.py +401 -0
  876. mypyc/irbuild/vtable.py +82 -0
  877. mypyc/lib-rt/CPy.h +643 -0
  878. mypyc/lib-rt/bytes_ops.c +143 -0
  879. mypyc/lib-rt/dict_ops.c +446 -0
  880. mypyc/lib-rt/exc_ops.c +259 -0
  881. mypyc/lib-rt/float_ops.c +192 -0
  882. mypyc/lib-rt/generic_ops.c +64 -0
  883. mypyc/lib-rt/getargs.c +450 -0
  884. mypyc/lib-rt/getargsfast.c +569 -0
  885. mypyc/lib-rt/init.c +13 -0
  886. mypyc/lib-rt/int_ops.c +803 -0
  887. mypyc/lib-rt/list_ops.c +335 -0
  888. mypyc/lib-rt/misc_ops.c +942 -0
  889. mypyc/lib-rt/module_shim.tmpl +18 -0
  890. mypyc/lib-rt/mypyc_util.h +118 -0
  891. mypyc/lib-rt/pythoncapi_compat.h +497 -0
  892. mypyc/lib-rt/pythonsupport.h +548 -0
  893. mypyc/lib-rt/set_ops.c +17 -0
  894. mypyc/lib-rt/setup.py +70 -0
  895. mypyc/lib-rt/str_ops.c +241 -0
  896. mypyc/lib-rt/test_capi.cc +585 -0
  897. mypyc/lib-rt/tuple_ops.c +61 -0
  898. mypyc/namegen.py +115 -0
  899. mypyc/options.py +32 -0
  900. mypyc/primitives/__init__.py +0 -0
  901. mypyc/primitives/bytes_ops.py +101 -0
  902. mypyc/primitives/dict_ops.py +325 -0
  903. mypyc/primitives/exc_ops.py +101 -0
  904. mypyc/primitives/float_ops.py +168 -0
  905. mypyc/primitives/generic_ops.py +384 -0
  906. mypyc/primitives/int_ops.py +304 -0
  907. mypyc/primitives/list_ops.py +300 -0
  908. mypyc/primitives/misc_ops.py +241 -0
  909. mypyc/primitives/registry.py +323 -0
  910. mypyc/primitives/set_ops.py +121 -0
  911. mypyc/primitives/str_ops.py +229 -0
  912. mypyc/primitives/tuple_ops.py +83 -0
  913. mypyc/rt_subtype.py +77 -0
  914. mypyc/sametype.py +83 -0
  915. mypyc/subtype.py +88 -0
  916. mypyc/test/__init__.py +0 -0
  917. mypyc/test/config.py +13 -0
  918. mypyc/test/test_alwaysdefined.py +46 -0
  919. mypyc/test/test_analysis.py +77 -0
  920. mypyc/test/test_cheader.py +45 -0
  921. mypyc/test/test_commandline.py +82 -0
  922. mypyc/test/test_emit.py +69 -0
  923. mypyc/test/test_emitclass.py +35 -0
  924. mypyc/test/test_emitfunc.py +926 -0
  925. mypyc/test/test_emitwrapper.py +60 -0
  926. mypyc/test/test_exceptions.py +56 -0
  927. mypyc/test/test_external.py +49 -0
  928. mypyc/test/test_irbuild.py +87 -0
  929. mypyc/test/test_ircheck.py +199 -0
  930. mypyc/test/test_literals.py +90 -0
  931. mypyc/test/test_namegen.py +48 -0
  932. mypyc/test/test_pprint.py +42 -0
  933. mypyc/test/test_rarray.py +48 -0
  934. mypyc/test/test_refcount.py +59 -0
  935. mypyc/test/test_run.py +426 -0
  936. mypyc/test/test_serialization.py +108 -0
  937. mypyc/test/test_struct.py +112 -0
  938. mypyc/test/test_tuplename.py +33 -0
  939. mypyc/test/test_typeops.py +97 -0
  940. mypyc/test/testutil.py +283 -0
  941. mypyc/test-data/alwaysdefined.test +732 -0
  942. mypyc/test-data/analysis.test +603 -0
  943. mypyc/test-data/commandline.test +245 -0
  944. mypyc/test-data/driver/driver.py +48 -0
  945. mypyc/test-data/exceptions-freq.test +125 -0
  946. mypyc/test-data/exceptions.test +713 -0
  947. mypyc/test-data/fixtures/ir.py +373 -0
  948. mypyc/test-data/fixtures/testutil.py +103 -0
  949. mypyc/test-data/fixtures/typing-full.pyi +169 -0
  950. mypyc/test-data/irbuild-any.test +238 -0
  951. mypyc/test-data/irbuild-basic.test +3690 -0
  952. mypyc/test-data/irbuild-bool.test +463 -0
  953. mypyc/test-data/irbuild-bytes.test +184 -0
  954. mypyc/test-data/irbuild-classes.test +1303 -0
  955. mypyc/test-data/irbuild-constant-fold.test +480 -0
  956. mypyc/test-data/irbuild-dict.test +585 -0
  957. mypyc/test-data/irbuild-dunders.test +223 -0
  958. mypyc/test-data/irbuild-float.test +497 -0
  959. mypyc/test-data/irbuild-generics.test +151 -0
  960. mypyc/test-data/irbuild-glue-methods.test +437 -0
  961. mypyc/test-data/irbuild-i16.test +526 -0
  962. mypyc/test-data/irbuild-i32.test +598 -0
  963. mypyc/test-data/irbuild-i64.test +2164 -0
  964. mypyc/test-data/irbuild-int.test +235 -0
  965. mypyc/test-data/irbuild-isinstance.test +109 -0
  966. mypyc/test-data/irbuild-lists.test +547 -0
  967. mypyc/test-data/irbuild-match.test +1708 -0
  968. mypyc/test-data/irbuild-math.test +64 -0
  969. mypyc/test-data/irbuild-nested.test +807 -0
  970. mypyc/test-data/irbuild-optional.test +536 -0
  971. mypyc/test-data/irbuild-set.test +838 -0
  972. mypyc/test-data/irbuild-singledispatch.test +257 -0
  973. mypyc/test-data/irbuild-statements.test +1149 -0
  974. mypyc/test-data/irbuild-str.test +314 -0
  975. mypyc/test-data/irbuild-strip-asserts.test +12 -0
  976. mypyc/test-data/irbuild-try.test +523 -0
  977. mypyc/test-data/irbuild-tuple.test +462 -0
  978. mypyc/test-data/irbuild-u8.test +543 -0
  979. mypyc/test-data/irbuild-unreachable.test +241 -0
  980. mypyc/test-data/irbuild-vectorcall.test +153 -0
  981. mypyc/test-data/refcount.test +1588 -0
  982. mypyc/test-data/run-async.test +145 -0
  983. mypyc/test-data/run-attrs.test +318 -0
  984. mypyc/test-data/run-bench.test +196 -0
  985. mypyc/test-data/run-bools.test +229 -0
  986. mypyc/test-data/run-bytes.test +302 -0
  987. mypyc/test-data/run-classes.test +2505 -0
  988. mypyc/test-data/run-dicts.test +334 -0
  989. mypyc/test-data/run-dunders.test +945 -0
  990. mypyc/test-data/run-exceptions.test +448 -0
  991. mypyc/test-data/run-floats.test +516 -0
  992. mypyc/test-data/run-functions.test +1310 -0
  993. mypyc/test-data/run-generators.test +681 -0
  994. mypyc/test-data/run-i16.test +338 -0
  995. mypyc/test-data/run-i32.test +336 -0
  996. mypyc/test-data/run-i64.test +1519 -0
  997. mypyc/test-data/run-imports.test +265 -0
  998. mypyc/test-data/run-integers.test +540 -0
  999. mypyc/test-data/run-lists.test +411 -0
  1000. mypyc/test-data/run-loops.test +485 -0
  1001. mypyc/test-data/run-match.test +283 -0
  1002. mypyc/test-data/run-math.test +106 -0
  1003. mypyc/test-data/run-misc.test +1168 -0
  1004. mypyc/test-data/run-multimodule.test +887 -0
  1005. mypyc/test-data/run-mypy-sim.test +138 -0
  1006. mypyc/test-data/run-primitives.test +375 -0
  1007. mypyc/test-data/run-python37.test +159 -0
  1008. mypyc/test-data/run-python38.test +88 -0
  1009. mypyc/test-data/run-sets.test +150 -0
  1010. mypyc/test-data/run-singledispatch.test +698 -0
  1011. mypyc/test-data/run-strings.test +641 -0
  1012. mypyc/test-data/run-traits.test +411 -0
  1013. mypyc/test-data/run-tuples.test +258 -0
  1014. mypyc/test-data/run-u8.test +303 -0
  1015. mypyc/transform/__init__.py +0 -0
  1016. mypyc/transform/exceptions.py +182 -0
  1017. mypyc/transform/refcount.py +294 -0
  1018. mypyc/transform/uninit.py +190 -0
mypy/checkmember.py ADDED
@@ -0,0 +1,1356 @@
1
+ """Type checking of attribute access"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Callable, Sequence, cast
6
+
7
+ from mypy import meet, message_registry, subtypes
8
+ from mypy.erasetype import erase_typevars
9
+ from mypy.expandtype import (
10
+ expand_self_type,
11
+ expand_type_by_instance,
12
+ freshen_all_functions_type_vars,
13
+ )
14
+ from mypy.maptype import map_instance_to_supertype
15
+ from mypy.messages import MessageBuilder
16
+ from mypy.nodes import (
17
+ ARG_POS,
18
+ ARG_STAR,
19
+ ARG_STAR2,
20
+ SYMBOL_FUNCBASE_TYPES,
21
+ Context,
22
+ Decorator,
23
+ FuncBase,
24
+ FuncDef,
25
+ IndexExpr,
26
+ MypyFile,
27
+ NameExpr,
28
+ OverloadedFuncDef,
29
+ SymbolNode,
30
+ SymbolTable,
31
+ TempNode,
32
+ TypeAlias,
33
+ TypeInfo,
34
+ TypeVarExpr,
35
+ Var,
36
+ is_final_node,
37
+ )
38
+ from mypy.plugin import AttributeContext
39
+ from mypy.typeops import (
40
+ bind_self,
41
+ class_callable,
42
+ erase_to_bound,
43
+ function_type,
44
+ get_type_vars,
45
+ make_simplified_union,
46
+ supported_self_type,
47
+ tuple_fallback,
48
+ type_object_type_from_function,
49
+ )
50
+ from mypy.types import (
51
+ ENUM_REMOVED_PROPS,
52
+ AnyType,
53
+ CallableType,
54
+ DeletedType,
55
+ FunctionLike,
56
+ Instance,
57
+ LiteralType,
58
+ NoneType,
59
+ Overloaded,
60
+ ParamSpecType,
61
+ PartialType,
62
+ ProperType,
63
+ TupleType,
64
+ Type,
65
+ TypedDictType,
66
+ TypeOfAny,
67
+ TypeType,
68
+ TypeVarLikeType,
69
+ TypeVarTupleType,
70
+ TypeVarType,
71
+ UnionType,
72
+ get_proper_type,
73
+ )
74
+ from mypy.typetraverser import TypeTraverserVisitor
75
+
76
+ if TYPE_CHECKING: # import for forward declaration only
77
+ import mypy.checker
78
+
79
+ from mypy import state
80
+
81
+
82
+ class MemberContext:
83
+ """Information and objects needed to type check attribute access.
84
+
85
+ Look at the docstring of analyze_member_access for more information.
86
+ """
87
+
88
+ def __init__(
89
+ self,
90
+ is_lvalue: bool,
91
+ is_super: bool,
92
+ is_operator: bool,
93
+ original_type: Type,
94
+ context: Context,
95
+ msg: MessageBuilder,
96
+ chk: mypy.checker.TypeChecker,
97
+ self_type: Type | None,
98
+ module_symbol_table: SymbolTable | None = None,
99
+ no_deferral: bool = False,
100
+ is_self: bool = False,
101
+ ) -> None:
102
+ self.is_lvalue = is_lvalue
103
+ self.is_super = is_super
104
+ self.is_operator = is_operator
105
+ self.original_type = original_type
106
+ self.self_type = self_type or original_type
107
+ self.context = context # Error context
108
+ self.msg = msg
109
+ self.chk = chk
110
+ self.module_symbol_table = module_symbol_table
111
+ self.no_deferral = no_deferral
112
+ self.is_self = is_self
113
+
114
+ def named_type(self, name: str) -> Instance:
115
+ return self.chk.named_type(name)
116
+
117
+ def not_ready_callback(self, name: str, context: Context) -> None:
118
+ self.chk.handle_cannot_determine_type(name, context)
119
+
120
+ def copy_modified(
121
+ self,
122
+ *,
123
+ messages: MessageBuilder | None = None,
124
+ self_type: Type | None = None,
125
+ is_lvalue: bool | None = None,
126
+ ) -> MemberContext:
127
+ mx = MemberContext(
128
+ self.is_lvalue,
129
+ self.is_super,
130
+ self.is_operator,
131
+ self.original_type,
132
+ self.context,
133
+ self.msg,
134
+ self.chk,
135
+ self.self_type,
136
+ self.module_symbol_table,
137
+ self.no_deferral,
138
+ )
139
+ if messages is not None:
140
+ mx.msg = messages
141
+ if self_type is not None:
142
+ mx.self_type = self_type
143
+ if is_lvalue is not None:
144
+ mx.is_lvalue = is_lvalue
145
+ return mx
146
+
147
+
148
+ def analyze_member_access(
149
+ name: str,
150
+ typ: Type,
151
+ context: Context,
152
+ is_lvalue: bool,
153
+ is_super: bool,
154
+ is_operator: bool,
155
+ msg: MessageBuilder,
156
+ *,
157
+ original_type: Type,
158
+ chk: mypy.checker.TypeChecker,
159
+ override_info: TypeInfo | None = None,
160
+ in_literal_context: bool = False,
161
+ self_type: Type | None = None,
162
+ module_symbol_table: SymbolTable | None = None,
163
+ no_deferral: bool = False,
164
+ is_self: bool = False,
165
+ ) -> Type:
166
+ """Return the type of attribute 'name' of 'typ'.
167
+
168
+ The actual implementation is in '_analyze_member_access' and this docstring
169
+ also applies to it.
170
+
171
+ This is a general operation that supports various different variations:
172
+
173
+ 1. lvalue or non-lvalue access (setter or getter access)
174
+ 2. supertype access when using super() (is_super == True and
175
+ 'override_info' should refer to the supertype)
176
+
177
+ 'original_type' is the most precise inferred or declared type of the base object
178
+ that we have available. When looking for an attribute of 'typ', we may perform
179
+ recursive calls targeting the fallback type, and 'typ' may become some supertype
180
+ of 'original_type'. 'original_type' is always preserved as the 'typ' type used in
181
+ the initial, non-recursive call. The 'self_type' is a component of 'original_type'
182
+ to which generic self should be bound (a narrower type that has a fallback to instance).
183
+ Currently this is used only for union types.
184
+
185
+ 'module_symbol_table' is passed to this function if 'typ' is actually a module
186
+ and we want to keep track of the available attributes of the module (since they
187
+ are not available via the type object directly)
188
+ """
189
+ mx = MemberContext(
190
+ is_lvalue,
191
+ is_super,
192
+ is_operator,
193
+ original_type,
194
+ context,
195
+ msg,
196
+ chk=chk,
197
+ self_type=self_type,
198
+ module_symbol_table=module_symbol_table,
199
+ no_deferral=no_deferral,
200
+ is_self=is_self,
201
+ )
202
+ result = _analyze_member_access(name, typ, mx, override_info)
203
+ possible_literal = get_proper_type(result)
204
+ if (
205
+ in_literal_context
206
+ and isinstance(possible_literal, Instance)
207
+ and possible_literal.last_known_value is not None
208
+ ):
209
+ return possible_literal.last_known_value
210
+ else:
211
+ return result
212
+
213
+
214
+ def _analyze_member_access(
215
+ name: str, typ: Type, mx: MemberContext, override_info: TypeInfo | None = None
216
+ ) -> Type:
217
+ # TODO: This and following functions share some logic with subtypes.find_member;
218
+ # consider refactoring.
219
+ typ = get_proper_type(typ)
220
+ if isinstance(typ, Instance):
221
+ return analyze_instance_member_access(name, typ, mx, override_info)
222
+ elif isinstance(typ, AnyType):
223
+ # The base object has dynamic type.
224
+ return AnyType(TypeOfAny.from_another_any, source_any=typ)
225
+ elif isinstance(typ, UnionType):
226
+ return analyze_union_member_access(name, typ, mx)
227
+ elif isinstance(typ, FunctionLike) and typ.is_type_obj():
228
+ return analyze_type_callable_member_access(name, typ, mx)
229
+ elif isinstance(typ, TypeType):
230
+ return analyze_type_type_member_access(name, typ, mx, override_info)
231
+ elif isinstance(typ, TupleType):
232
+ # Actually look up from the fallback instance type.
233
+ return _analyze_member_access(name, tuple_fallback(typ), mx, override_info)
234
+ elif isinstance(typ, (LiteralType, FunctionLike)):
235
+ # Actually look up from the fallback instance type.
236
+ return _analyze_member_access(name, typ.fallback, mx, override_info)
237
+ elif isinstance(typ, TypedDictType):
238
+ return analyze_typeddict_access(name, typ, mx, override_info)
239
+ elif isinstance(typ, NoneType):
240
+ return analyze_none_member_access(name, typ, mx)
241
+ elif isinstance(typ, TypeVarLikeType):
242
+ if isinstance(typ, TypeVarType) and typ.values:
243
+ return _analyze_member_access(
244
+ name, make_simplified_union(typ.values), mx, override_info
245
+ )
246
+ return _analyze_member_access(name, typ.upper_bound, mx, override_info)
247
+ elif isinstance(typ, DeletedType):
248
+ mx.msg.deleted_as_rvalue(typ, mx.context)
249
+ return AnyType(TypeOfAny.from_error)
250
+ return report_missing_attribute(mx.original_type, typ, name, mx)
251
+
252
+
253
+ def may_be_awaitable_attribute(
254
+ name: str, typ: Type, mx: MemberContext, override_info: TypeInfo | None = None
255
+ ) -> bool:
256
+ """Check if the given type has the attribute when awaited."""
257
+ if mx.chk.checking_missing_await:
258
+ # Avoid infinite recursion.
259
+ return False
260
+ with mx.chk.checking_await_set(), mx.msg.filter_errors() as local_errors:
261
+ aw_type = mx.chk.get_precise_awaitable_type(typ, local_errors)
262
+ if aw_type is None:
263
+ return False
264
+ _ = _analyze_member_access(name, aw_type, mx, override_info)
265
+ return not local_errors.has_new_errors()
266
+
267
+
268
+ def report_missing_attribute(
269
+ original_type: Type,
270
+ typ: Type,
271
+ name: str,
272
+ mx: MemberContext,
273
+ override_info: TypeInfo | None = None,
274
+ ) -> Type:
275
+ error_code = mx.msg.has_no_attr(original_type, typ, name, mx.context, mx.module_symbol_table)
276
+ if not mx.msg.prefer_simple_messages():
277
+ if may_be_awaitable_attribute(name, typ, mx, override_info):
278
+ mx.msg.possible_missing_await(mx.context, error_code)
279
+ return AnyType(TypeOfAny.from_error)
280
+
281
+
282
+ # The several functions that follow implement analyze_member_access for various
283
+ # types and aren't documented individually.
284
+
285
+
286
+ def analyze_instance_member_access(
287
+ name: str, typ: Instance, mx: MemberContext, override_info: TypeInfo | None
288
+ ) -> Type:
289
+ if name == "__init__" and not mx.is_super:
290
+ # Accessing __init__ in statically typed code would compromise
291
+ # type safety unless used via super().
292
+ mx.msg.fail(message_registry.CANNOT_ACCESS_INIT, mx.context)
293
+ return AnyType(TypeOfAny.from_error)
294
+
295
+ # The base object has an instance type.
296
+
297
+ info = typ.type
298
+ if override_info:
299
+ info = override_info
300
+
301
+ if (
302
+ state.find_occurrences
303
+ and info.name == state.find_occurrences[0]
304
+ and name == state.find_occurrences[1]
305
+ ):
306
+ mx.msg.note("Occurrence of '{}.{}'".format(*state.find_occurrences), mx.context)
307
+
308
+ # Look up the member. First look up the method dictionary.
309
+ method = info.get_method(name)
310
+ if method and not isinstance(method, Decorator):
311
+ if mx.is_super:
312
+ validate_super_call(method, mx)
313
+
314
+ if method.is_property:
315
+ assert isinstance(method, OverloadedFuncDef)
316
+ first_item = method.items[0]
317
+ assert isinstance(first_item, Decorator)
318
+ return analyze_var(name, first_item.var, typ, info, mx)
319
+ if mx.is_lvalue:
320
+ mx.msg.cant_assign_to_method(mx.context)
321
+ if not isinstance(method, OverloadedFuncDef):
322
+ signature = function_type(method, mx.named_type("builtins.function"))
323
+ else:
324
+ if method.type is None:
325
+ # Overloads may be not ready if they are decorated. Handle this in same
326
+ # manner as we would handle a regular decorated function: defer if possible.
327
+ if not mx.no_deferral and method.items:
328
+ mx.not_ready_callback(method.name, mx.context)
329
+ return AnyType(TypeOfAny.special_form)
330
+ assert isinstance(method.type, Overloaded)
331
+ signature = method.type
332
+ signature = freshen_all_functions_type_vars(signature)
333
+ if not method.is_static:
334
+ # TODO: use proper treatment of special methods on unions instead
335
+ # of this hack here and below (i.e. mx.self_type).
336
+ dispatched_type = meet.meet_types(mx.original_type, typ)
337
+ signature = check_self_arg(
338
+ signature, dispatched_type, method.is_class, mx.context, name, mx.msg
339
+ )
340
+ signature = bind_self(signature, mx.self_type, is_classmethod=method.is_class)
341
+ # TODO: should we skip these steps for static methods as well?
342
+ # Since generic static methods should not be allowed.
343
+ typ = map_instance_to_supertype(typ, method.info)
344
+ member_type = expand_type_by_instance(signature, typ)
345
+ freeze_all_type_vars(member_type)
346
+ return member_type
347
+ else:
348
+ # Not a method.
349
+ return analyze_member_var_access(name, typ, info, mx)
350
+
351
+
352
+ def validate_super_call(node: FuncBase, mx: MemberContext) -> None:
353
+ unsafe_super = False
354
+ if isinstance(node, FuncDef) and node.is_trivial_body:
355
+ unsafe_super = True
356
+ impl = node
357
+ elif isinstance(node, OverloadedFuncDef):
358
+ if node.impl:
359
+ impl = node.impl if isinstance(node.impl, FuncDef) else node.impl.func
360
+ unsafe_super = impl.is_trivial_body
361
+ if unsafe_super:
362
+ ret_type = (
363
+ impl.type.ret_type
364
+ if isinstance(impl.type, CallableType)
365
+ else AnyType(TypeOfAny.unannotated)
366
+ )
367
+ if not subtypes.is_subtype(NoneType(), ret_type):
368
+ mx.msg.unsafe_super(node.name, node.info.name, mx.context)
369
+
370
+
371
+ def analyze_type_callable_member_access(name: str, typ: FunctionLike, mx: MemberContext) -> Type:
372
+ # Class attribute.
373
+ # TODO super?
374
+ ret_type = typ.items[0].ret_type
375
+ assert isinstance(ret_type, ProperType)
376
+ if isinstance(ret_type, TupleType):
377
+ ret_type = tuple_fallback(ret_type)
378
+ if isinstance(ret_type, TypedDictType):
379
+ ret_type = ret_type.fallback
380
+ if isinstance(ret_type, Instance):
381
+ if not mx.is_operator:
382
+ # When Python sees an operator (eg `3 == 4`), it automatically translates that
383
+ # into something like `int.__eq__(3, 4)` instead of `(3).__eq__(4)` as an
384
+ # optimization.
385
+ #
386
+ # While it normally it doesn't matter which of the two versions are used, it
387
+ # does cause inconsistencies when working with classes. For example, translating
388
+ # `int == int` to `int.__eq__(int)` would not work since `int.__eq__` is meant to
389
+ # compare two int _instances_. What we really want is `type(int).__eq__`, which
390
+ # is meant to compare two types or classes.
391
+ #
392
+ # This check makes sure that when we encounter an operator, we skip looking up
393
+ # the corresponding method in the current instance to avoid this edge case.
394
+ # See https://github.com/python/mypy/pull/1787 for more info.
395
+ # TODO: do not rely on same type variables being present in all constructor overloads.
396
+ result = analyze_class_attribute_access(
397
+ ret_type, name, mx, original_vars=typ.items[0].variables, mcs_fallback=typ.fallback
398
+ )
399
+ if result:
400
+ return result
401
+ # Look up from the 'type' type.
402
+ return _analyze_member_access(name, typ.fallback, mx)
403
+ else:
404
+ assert False, f"Unexpected type {ret_type!r}"
405
+
406
+
407
+ def analyze_type_type_member_access(
408
+ name: str, typ: TypeType, mx: MemberContext, override_info: TypeInfo | None
409
+ ) -> Type:
410
+ # Similar to analyze_type_callable_attribute_access.
411
+ item = None
412
+ fallback = mx.named_type("builtins.type")
413
+ if isinstance(typ.item, Instance):
414
+ item = typ.item
415
+ elif isinstance(typ.item, AnyType):
416
+ with mx.msg.filter_errors():
417
+ return _analyze_member_access(name, fallback, mx, override_info)
418
+ elif isinstance(typ.item, TypeVarType):
419
+ upper_bound = get_proper_type(typ.item.upper_bound)
420
+ if isinstance(upper_bound, Instance):
421
+ item = upper_bound
422
+ elif isinstance(upper_bound, UnionType):
423
+ return _analyze_member_access(
424
+ name,
425
+ TypeType.make_normalized(upper_bound, line=typ.line, column=typ.column),
426
+ mx,
427
+ override_info,
428
+ )
429
+ elif isinstance(upper_bound, TupleType):
430
+ item = tuple_fallback(upper_bound)
431
+ elif isinstance(upper_bound, AnyType):
432
+ with mx.msg.filter_errors():
433
+ return _analyze_member_access(name, fallback, mx, override_info)
434
+ elif isinstance(typ.item, TupleType):
435
+ item = tuple_fallback(typ.item)
436
+ elif isinstance(typ.item, FunctionLike) and typ.item.is_type_obj():
437
+ item = typ.item.fallback
438
+ elif isinstance(typ.item, TypeType):
439
+ # Access member on metaclass object via Type[Type[C]]
440
+ if isinstance(typ.item.item, Instance):
441
+ item = typ.item.item.type.metaclass_type
442
+ ignore_messages = False
443
+
444
+ if item is not None:
445
+ fallback = item.type.metaclass_type or fallback
446
+
447
+ if item and not mx.is_operator:
448
+ # See comment above for why operators are skipped
449
+ result = analyze_class_attribute_access(
450
+ item, name, mx, mcs_fallback=fallback, override_info=override_info
451
+ )
452
+ if result:
453
+ if not (isinstance(get_proper_type(result), AnyType) and item.type.fallback_to_any):
454
+ return result
455
+ else:
456
+ # We don't want errors on metaclass lookup for classes with Any fallback
457
+ ignore_messages = True
458
+
459
+ with mx.msg.filter_errors(filter_errors=ignore_messages):
460
+ return _analyze_member_access(name, fallback, mx, override_info)
461
+
462
+
463
+ def analyze_union_member_access(name: str, typ: UnionType, mx: MemberContext) -> Type:
464
+ with mx.msg.disable_type_names():
465
+ results = []
466
+ for subtype in typ.relevant_items():
467
+ # Self types should be bound to every individual item of a union.
468
+ item_mx = mx.copy_modified(self_type=subtype)
469
+ results.append(_analyze_member_access(name, subtype, item_mx))
470
+ return make_simplified_union(results)
471
+
472
+
473
+ def analyze_none_member_access(name: str, typ: NoneType, mx: MemberContext) -> Type:
474
+ if name == "__bool__":
475
+ literal_false = LiteralType(False, fallback=mx.named_type("builtins.bool"))
476
+ return CallableType(
477
+ arg_types=[],
478
+ arg_kinds=[],
479
+ arg_names=[],
480
+ ret_type=literal_false,
481
+ fallback=mx.named_type("builtins.function"),
482
+ )
483
+ else:
484
+ return _analyze_member_access(name, mx.named_type("builtins.object"), mx)
485
+
486
+
487
+ def analyze_member_var_access(
488
+ name: str, itype: Instance, info: TypeInfo, mx: MemberContext
489
+ ) -> Type:
490
+ """Analyse attribute access that does not target a method.
491
+
492
+ This is logically part of analyze_member_access and the arguments are similar.
493
+
494
+ original_type is the type of E in the expression E.var
495
+ """
496
+ # It was not a method. Try looking up a variable.
497
+ v = lookup_member_var_or_accessor(info, name, mx.is_lvalue)
498
+
499
+ vv = v
500
+ if isinstance(vv, Decorator):
501
+ # The associated Var node of a decorator contains the type.
502
+ v = vv.var
503
+ if mx.is_super:
504
+ validate_super_call(vv.func, mx)
505
+
506
+ if isinstance(vv, TypeInfo):
507
+ # If the associated variable is a TypeInfo synthesize a Var node for
508
+ # the purposes of type checking. This enables us to type check things
509
+ # like accessing class attributes on an inner class.
510
+ v = Var(name, type=type_object_type(vv, mx.named_type))
511
+ v.info = info
512
+
513
+ if isinstance(vv, TypeAlias):
514
+ # Similar to the above TypeInfo case, we allow using
515
+ # qualified type aliases in runtime context if it refers to an
516
+ # instance type. For example:
517
+ # class C:
518
+ # A = List[int]
519
+ # x = C.A() <- this is OK
520
+ typ = mx.chk.expr_checker.alias_type_in_runtime_context(
521
+ vv, ctx=mx.context, alias_definition=mx.is_lvalue
522
+ )
523
+ v = Var(name, type=typ)
524
+ v.info = info
525
+
526
+ if isinstance(v, Var):
527
+ implicit = info[name].implicit
528
+
529
+ # An assignment to final attribute is always an error,
530
+ # independently of types.
531
+ if mx.is_lvalue and not mx.chk.get_final_context():
532
+ check_final_member(name, info, mx.msg, mx.context)
533
+
534
+ return analyze_var(name, v, itype, info, mx, implicit=implicit)
535
+ elif isinstance(v, FuncDef):
536
+ assert False, "Did not expect a function"
537
+ elif isinstance(v, MypyFile):
538
+ mx.chk.module_refs.add(v.fullname)
539
+ return mx.chk.expr_checker.module_type(v)
540
+ elif (
541
+ not v
542
+ and name not in ["__getattr__", "__setattr__", "__getattribute__"]
543
+ and not mx.is_operator
544
+ and mx.module_symbol_table is None
545
+ ):
546
+ # Above we skip ModuleType.__getattr__ etc. if we have a
547
+ # module symbol table, since the symbol table allows precise
548
+ # checking.
549
+ if not mx.is_lvalue:
550
+ for method_name in ("__getattribute__", "__getattr__"):
551
+ method = info.get_method(method_name)
552
+
553
+ # __getattribute__ is defined on builtins.object and returns Any, so without
554
+ # the guard this search will always find object.__getattribute__ and conclude
555
+ # that the attribute exists
556
+ if method and method.info.fullname != "builtins.object":
557
+ bound_method = analyze_decorator_or_funcbase_access(
558
+ defn=method,
559
+ itype=itype,
560
+ info=info,
561
+ self_type=mx.self_type,
562
+ name=method_name,
563
+ mx=mx,
564
+ )
565
+ typ = map_instance_to_supertype(itype, method.info)
566
+ getattr_type = get_proper_type(expand_type_by_instance(bound_method, typ))
567
+ if isinstance(getattr_type, CallableType):
568
+ result = getattr_type.ret_type
569
+ else:
570
+ result = getattr_type
571
+
572
+ # Call the attribute hook before returning.
573
+ fullname = f"{method.info.fullname}.{name}"
574
+ hook = mx.chk.plugin.get_attribute_hook(fullname)
575
+ if hook:
576
+ result = hook(
577
+ AttributeContext(
578
+ get_proper_type(mx.original_type), result, mx.context, mx.chk
579
+ )
580
+ )
581
+ return result
582
+ else:
583
+ setattr_meth = info.get_method("__setattr__")
584
+ if setattr_meth and setattr_meth.info.fullname != "builtins.object":
585
+ bound_type = analyze_decorator_or_funcbase_access(
586
+ defn=setattr_meth,
587
+ itype=itype,
588
+ info=info,
589
+ self_type=mx.self_type,
590
+ name=name,
591
+ mx=mx.copy_modified(is_lvalue=False),
592
+ )
593
+ typ = map_instance_to_supertype(itype, setattr_meth.info)
594
+ setattr_type = get_proper_type(expand_type_by_instance(bound_type, typ))
595
+ if isinstance(setattr_type, CallableType) and len(setattr_type.arg_types) > 0:
596
+ return setattr_type.arg_types[-1]
597
+
598
+ if itype.type.fallback_to_any:
599
+ return AnyType(TypeOfAny.special_form)
600
+
601
+ # Could not find the member.
602
+ if itype.extra_attrs and name in itype.extra_attrs.attrs:
603
+ # For modules use direct symbol table lookup.
604
+ if not itype.extra_attrs.mod_name:
605
+ return itype.extra_attrs.attrs[name]
606
+
607
+ if mx.is_super:
608
+ mx.msg.undefined_in_superclass(name, mx.context)
609
+ return AnyType(TypeOfAny.from_error)
610
+ else:
611
+ ret = report_missing_attribute(mx.original_type, itype, name, mx)
612
+ # Avoid paying double jeopardy if we can't find the member due to --no-implicit-reexport
613
+ if (
614
+ mx.module_symbol_table is not None
615
+ and name in mx.module_symbol_table
616
+ and not mx.module_symbol_table[name].module_public
617
+ ):
618
+ v = mx.module_symbol_table[name].node
619
+ e = NameExpr(name)
620
+ e.set_line(mx.context)
621
+ e.node = v
622
+ return mx.chk.expr_checker.analyze_ref_expr(e, lvalue=mx.is_lvalue)
623
+ return ret
624
+
625
+
626
+ def check_final_member(name: str, info: TypeInfo, msg: MessageBuilder, ctx: Context) -> None:
627
+ """Give an error if the name being assigned was declared as final."""
628
+ for base in info.mro:
629
+ sym = base.names.get(name)
630
+ if sym and is_final_node(sym.node):
631
+ msg.cant_assign_to_final(name, attr_assign=True, ctx=ctx)
632
+
633
+
634
+ def analyze_descriptor_access(descriptor_type: Type, mx: MemberContext) -> Type:
635
+ """Type check descriptor access.
636
+
637
+ Arguments:
638
+ descriptor_type: The type of the descriptor attribute being accessed
639
+ (the type of ``f`` in ``a.f`` when ``f`` is a descriptor).
640
+ mx: The current member access context.
641
+ Return:
642
+ The return type of the appropriate ``__get__`` overload for the descriptor.
643
+ """
644
+ instance_type = get_proper_type(mx.original_type)
645
+ orig_descriptor_type = descriptor_type
646
+ descriptor_type = get_proper_type(descriptor_type)
647
+
648
+ if isinstance(descriptor_type, UnionType):
649
+ # Map the access over union types
650
+ return make_simplified_union(
651
+ [analyze_descriptor_access(typ, mx) for typ in descriptor_type.items]
652
+ )
653
+ elif not isinstance(descriptor_type, Instance):
654
+ return orig_descriptor_type
655
+
656
+ if not descriptor_type.type.has_readable_member("__get__"):
657
+ return orig_descriptor_type
658
+
659
+ dunder_get = descriptor_type.type.get_method("__get__")
660
+ if dunder_get is None:
661
+ mx.msg.fail(
662
+ message_registry.DESCRIPTOR_GET_NOT_CALLABLE.format(
663
+ descriptor_type.str_with_options(mx.msg.options)
664
+ ),
665
+ mx.context,
666
+ )
667
+ return AnyType(TypeOfAny.from_error)
668
+
669
+ bound_method = analyze_decorator_or_funcbase_access(
670
+ defn=dunder_get,
671
+ itype=descriptor_type,
672
+ info=descriptor_type.type,
673
+ self_type=descriptor_type,
674
+ name="__get__",
675
+ mx=mx,
676
+ )
677
+
678
+ typ = map_instance_to_supertype(descriptor_type, dunder_get.info)
679
+ dunder_get_type = expand_type_by_instance(bound_method, typ)
680
+
681
+ if isinstance(instance_type, FunctionLike) and instance_type.is_type_obj():
682
+ owner_type = instance_type.items[0].ret_type
683
+ instance_type = NoneType()
684
+ elif isinstance(instance_type, TypeType):
685
+ owner_type = instance_type.item
686
+ instance_type = NoneType()
687
+ else:
688
+ owner_type = instance_type
689
+
690
+ callable_name = mx.chk.expr_checker.method_fullname(descriptor_type, "__get__")
691
+ dunder_get_type = mx.chk.expr_checker.transform_callee_type(
692
+ callable_name,
693
+ dunder_get_type,
694
+ [
695
+ TempNode(instance_type, context=mx.context),
696
+ TempNode(TypeType.make_normalized(owner_type), context=mx.context),
697
+ ],
698
+ [ARG_POS, ARG_POS],
699
+ mx.context,
700
+ object_type=descriptor_type,
701
+ )
702
+
703
+ _, inferred_dunder_get_type = mx.chk.expr_checker.check_call(
704
+ dunder_get_type,
705
+ [
706
+ TempNode(instance_type, context=mx.context),
707
+ TempNode(TypeType.make_normalized(owner_type), context=mx.context),
708
+ ],
709
+ [ARG_POS, ARG_POS],
710
+ mx.context,
711
+ object_type=descriptor_type,
712
+ callable_name=callable_name,
713
+ )
714
+
715
+ inferred_dunder_get_type = get_proper_type(inferred_dunder_get_type)
716
+ if isinstance(inferred_dunder_get_type, AnyType):
717
+ # check_call failed, and will have reported an error
718
+ return inferred_dunder_get_type
719
+
720
+ if not isinstance(inferred_dunder_get_type, CallableType):
721
+ mx.msg.fail(
722
+ message_registry.DESCRIPTOR_GET_NOT_CALLABLE.format(
723
+ descriptor_type.str_with_options(mx.msg.options)
724
+ ),
725
+ mx.context,
726
+ )
727
+ return AnyType(TypeOfAny.from_error)
728
+
729
+ return inferred_dunder_get_type.ret_type
730
+
731
+
732
+ def is_instance_var(var: Var) -> bool:
733
+ """Return if var is an instance variable according to PEP 526."""
734
+ return (
735
+ # check the type_info node is the var (not a decorated function, etc.)
736
+ var.name in var.info.names
737
+ and var.info.names[var.name].node is var
738
+ and not var.is_classvar
739
+ # variables without annotations are treated as classvar
740
+ and not var.is_inferred
741
+ )
742
+
743
+
744
+ def analyze_var(
745
+ name: str,
746
+ var: Var,
747
+ itype: Instance,
748
+ info: TypeInfo,
749
+ mx: MemberContext,
750
+ *,
751
+ implicit: bool = False,
752
+ ) -> Type:
753
+ """Analyze access to an attribute via a Var node.
754
+
755
+ This is conceptually part of analyze_member_access and the arguments are similar.
756
+ itype is the instance type in which attribute should be looked up
757
+ original_type is the type of E in the expression E.var
758
+ if implicit is True, the original Var was created as an assignment to self
759
+ """
760
+ # Found a member variable.
761
+ original_itype = itype
762
+ itype = map_instance_to_supertype(itype, var.info)
763
+ typ = var.type
764
+ if typ:
765
+ if isinstance(typ, PartialType):
766
+ return mx.chk.handle_partial_var_type(typ, mx.is_lvalue, var, mx.context)
767
+ if mx.is_lvalue and var.is_property and not var.is_settable_property:
768
+ # TODO allow setting attributes in subclass (although it is probably an error)
769
+ mx.msg.read_only_property(name, itype.type, mx.context)
770
+ if mx.is_lvalue and var.is_classvar:
771
+ mx.msg.cant_assign_to_classvar(name, mx.context)
772
+ t = freshen_all_functions_type_vars(typ)
773
+ if not (mx.is_self or mx.is_super) or supported_self_type(
774
+ get_proper_type(mx.original_type)
775
+ ):
776
+ t = expand_self_type(var, t, mx.original_type)
777
+ elif (
778
+ mx.is_self
779
+ and original_itype.type != var.info
780
+ # If an attribute with Self-type was defined in a supertype, we need to
781
+ # rebind the Self type variable to Self type variable of current class...
782
+ and original_itype.type.self_type is not None
783
+ # ...unless `self` has an explicit non-trivial annotation.
784
+ and original_itype == mx.chk.scope.active_self_type()
785
+ ):
786
+ t = expand_self_type(var, t, original_itype.type.self_type)
787
+ t = get_proper_type(expand_type_by_instance(t, itype))
788
+ freeze_all_type_vars(t)
789
+ result: Type = t
790
+ typ = get_proper_type(typ)
791
+
792
+ call_type: ProperType | None = None
793
+ if var.is_initialized_in_class and (not is_instance_var(var) or mx.is_operator):
794
+ if isinstance(typ, FunctionLike) and not typ.is_type_obj():
795
+ call_type = typ
796
+ elif var.is_property:
797
+ call_type = get_proper_type(_analyze_member_access("__call__", typ, mx))
798
+ else:
799
+ call_type = typ
800
+
801
+ if isinstance(call_type, FunctionLike) and not call_type.is_type_obj():
802
+ if mx.is_lvalue:
803
+ if var.is_property:
804
+ if not var.is_settable_property:
805
+ mx.msg.read_only_property(name, itype.type, mx.context)
806
+ else:
807
+ mx.msg.cant_assign_to_method(mx.context)
808
+
809
+ if not var.is_staticmethod:
810
+ # Class-level function objects and classmethods become bound methods:
811
+ # the former to the instance, the latter to the class.
812
+ functype: FunctionLike = call_type
813
+ # Use meet to narrow original_type to the dispatched type.
814
+ # For example, assume
815
+ # * A.f: Callable[[A1], None] where A1 <: A (maybe A1 == A)
816
+ # * B.f: Callable[[B1], None] where B1 <: B (maybe B1 == B)
817
+ # * x: Union[A1, B1]
818
+ # In `x.f`, when checking `x` against A1 we assume x is compatible with A
819
+ # and similarly for B1 when checking against B
820
+ dispatched_type = meet.meet_types(mx.original_type, itype)
821
+ signature = freshen_all_functions_type_vars(functype)
822
+ bound = get_proper_type(expand_self_type(var, signature, mx.original_type))
823
+ assert isinstance(bound, FunctionLike)
824
+ signature = bound
825
+ signature = check_self_arg(
826
+ signature, dispatched_type, var.is_classmethod, mx.context, name, mx.msg
827
+ )
828
+ signature = bind_self(signature, mx.self_type, var.is_classmethod)
829
+ expanded_signature = expand_type_by_instance(signature, itype)
830
+ freeze_all_type_vars(expanded_signature)
831
+ if var.is_property:
832
+ # A property cannot have an overloaded type => the cast is fine.
833
+ assert isinstance(expanded_signature, CallableType)
834
+ result = expanded_signature.ret_type
835
+ else:
836
+ result = expanded_signature
837
+ else:
838
+ if not var.is_ready and not mx.no_deferral:
839
+ mx.not_ready_callback(var.name, mx.context)
840
+ # Implicit 'Any' type.
841
+ result = AnyType(TypeOfAny.special_form)
842
+ fullname = f"{var.info.fullname}.{name}"
843
+ hook = mx.chk.plugin.get_attribute_hook(fullname)
844
+ if result and not mx.is_lvalue and not implicit:
845
+ result = analyze_descriptor_access(result, mx)
846
+ if hook:
847
+ result = hook(
848
+ AttributeContext(get_proper_type(mx.original_type), result, mx.context, mx.chk)
849
+ )
850
+ return result
851
+
852
+
853
+ def freeze_all_type_vars(member_type: Type) -> None:
854
+ member_type.accept(FreezeTypeVarsVisitor())
855
+
856
+
857
+ class FreezeTypeVarsVisitor(TypeTraverserVisitor):
858
+ def visit_callable_type(self, t: CallableType) -> None:
859
+ for v in t.variables:
860
+ v.id.meta_level = 0
861
+ super().visit_callable_type(t)
862
+
863
+
864
+ def lookup_member_var_or_accessor(info: TypeInfo, name: str, is_lvalue: bool) -> SymbolNode | None:
865
+ """Find the attribute/accessor node that refers to a member of a type."""
866
+ # TODO handle lvalues
867
+ node = info.get(name)
868
+ if node:
869
+ return node.node
870
+ else:
871
+ return None
872
+
873
+
874
+ def check_self_arg(
875
+ functype: FunctionLike,
876
+ dispatched_arg_type: Type,
877
+ is_classmethod: bool,
878
+ context: Context,
879
+ name: str,
880
+ msg: MessageBuilder,
881
+ ) -> FunctionLike:
882
+ """Check that an instance has a valid type for a method with annotated 'self'.
883
+
884
+ For example if the method is defined as:
885
+ class A:
886
+ def f(self: S) -> T: ...
887
+ then for 'x.f' we check that meet(type(x), A) <: S. If the method is overloaded, we
888
+ select only overloads items that satisfy this requirement. If there are no matching
889
+ overloads, an error is generated.
890
+
891
+ Note: dispatched_arg_type uses a meet to select a relevant item in case if the
892
+ original type of 'x' is a union. This is done because several special methods
893
+ treat union types in ad-hoc manner, so we can't use MemberContext.self_type yet.
894
+ """
895
+ items = functype.items
896
+ if not items:
897
+ return functype
898
+ new_items = []
899
+ if is_classmethod:
900
+ dispatched_arg_type = TypeType.make_normalized(dispatched_arg_type)
901
+
902
+ for item in items:
903
+ if not item.arg_types or item.arg_kinds[0] not in (ARG_POS, ARG_STAR):
904
+ # No positional first (self) argument (*args is okay).
905
+ msg.no_formal_self(name, item, context)
906
+ # This is pretty bad, so just return the original signature if
907
+ # there is at least one such error.
908
+ return functype
909
+ else:
910
+ selfarg = get_proper_type(item.arg_types[0])
911
+ # This level of erasure matches the one in checker.check_func_def(),
912
+ # better keep these two checks consistent.
913
+ if subtypes.is_subtype(dispatched_arg_type, erase_typevars(erase_to_bound(selfarg))):
914
+ new_items.append(item)
915
+ elif isinstance(selfarg, ParamSpecType):
916
+ # TODO: This is not always right. What's the most reasonable thing to do here?
917
+ new_items.append(item)
918
+ elif isinstance(selfarg, TypeVarTupleType):
919
+ raise NotImplementedError
920
+ if not new_items:
921
+ # Choose first item for the message (it may be not very helpful for overloads).
922
+ msg.incompatible_self_argument(
923
+ name, dispatched_arg_type, items[0], is_classmethod, context
924
+ )
925
+ return functype
926
+ if len(new_items) == 1:
927
+ return new_items[0]
928
+ return Overloaded(new_items)
929
+
930
+
931
+ def analyze_class_attribute_access(
932
+ itype: Instance,
933
+ name: str,
934
+ mx: MemberContext,
935
+ *,
936
+ mcs_fallback: Instance,
937
+ override_info: TypeInfo | None = None,
938
+ original_vars: Sequence[TypeVarLikeType] | None = None,
939
+ ) -> Type | None:
940
+ """Analyze access to an attribute on a class object.
941
+
942
+ itype is the return type of the class object callable, original_type is the type
943
+ of E in the expression E.var, original_vars are type variables of the class callable
944
+ (for generic classes).
945
+ """
946
+ info = itype.type
947
+ if override_info:
948
+ info = override_info
949
+
950
+ fullname = f"{info.fullname}.{name}"
951
+ hook = mx.chk.plugin.get_class_attribute_hook(fullname)
952
+
953
+ node = info.get(name)
954
+ if not node:
955
+ if itype.extra_attrs and name in itype.extra_attrs.attrs:
956
+ # For modules use direct symbol table lookup.
957
+ if not itype.extra_attrs.mod_name:
958
+ return itype.extra_attrs.attrs[name]
959
+ if info.fallback_to_any or info.meta_fallback_to_any:
960
+ return apply_class_attr_hook(mx, hook, AnyType(TypeOfAny.special_form))
961
+ return None
962
+
963
+ if (
964
+ isinstance(node.node, Var)
965
+ and not node.node.is_classvar
966
+ and not hook
967
+ and mcs_fallback.type.get(name)
968
+ ):
969
+ # If the same attribute is declared on the metaclass and the class but with different types,
970
+ # and the attribute on the class is not a ClassVar,
971
+ # the type of the attribute on the metaclass should take priority
972
+ # over the type of the attribute on the class,
973
+ # when the attribute is being accessed from the class object itself.
974
+ #
975
+ # Return `None` here to signify that the name should be looked up
976
+ # on the class object itself rather than the instance.
977
+ return None
978
+
979
+ is_decorated = isinstance(node.node, Decorator)
980
+ is_method = is_decorated or isinstance(node.node, FuncBase)
981
+ if mx.is_lvalue:
982
+ if is_method:
983
+ mx.msg.cant_assign_to_method(mx.context)
984
+ if isinstance(node.node, TypeInfo):
985
+ mx.msg.fail(message_registry.CANNOT_ASSIGN_TO_TYPE, mx.context)
986
+
987
+ # Refuse class attribute access if slot defined
988
+ if info.slots and name in info.slots:
989
+ mx.msg.fail(message_registry.CLASS_VAR_CONFLICTS_SLOTS.format(name), mx.context)
990
+
991
+ # If a final attribute was declared on `self` in `__init__`, then it
992
+ # can't be accessed on the class object.
993
+ if node.implicit and isinstance(node.node, Var) and node.node.is_final:
994
+ mx.msg.fail(
995
+ message_registry.CANNOT_ACCESS_FINAL_INSTANCE_ATTR.format(node.node.name), mx.context
996
+ )
997
+
998
+ # An assignment to final attribute on class object is also always an error,
999
+ # independently of types.
1000
+ if mx.is_lvalue and not mx.chk.get_final_context():
1001
+ check_final_member(name, info, mx.msg, mx.context)
1002
+
1003
+ if info.is_enum and not (mx.is_lvalue or is_decorated or is_method):
1004
+ enum_class_attribute_type = analyze_enum_class_attribute_access(itype, name, mx)
1005
+ if enum_class_attribute_type:
1006
+ return apply_class_attr_hook(mx, hook, enum_class_attribute_type)
1007
+
1008
+ t = node.type
1009
+ if t:
1010
+ if isinstance(t, PartialType):
1011
+ symnode = node.node
1012
+ assert isinstance(symnode, Var)
1013
+ return apply_class_attr_hook(
1014
+ mx, hook, mx.chk.handle_partial_var_type(t, mx.is_lvalue, symnode, mx.context)
1015
+ )
1016
+
1017
+ # Find the class where method/variable was defined.
1018
+ if isinstance(node.node, Decorator):
1019
+ super_info: TypeInfo | None = node.node.var.info
1020
+ elif isinstance(node.node, (Var, SYMBOL_FUNCBASE_TYPES)):
1021
+ super_info = node.node.info
1022
+ else:
1023
+ super_info = None
1024
+
1025
+ # Map the type to how it would look as a defining class. For example:
1026
+ # class C(Generic[T]): ...
1027
+ # class D(C[Tuple[T, S]]): ...
1028
+ # D[int, str].method()
1029
+ # Here itype is D[int, str], isuper is C[Tuple[int, str]].
1030
+ if not super_info:
1031
+ isuper = None
1032
+ else:
1033
+ isuper = map_instance_to_supertype(itype, super_info)
1034
+
1035
+ if isinstance(node.node, Var):
1036
+ assert isuper is not None
1037
+ # Check if original variable type has type variables. For example:
1038
+ # class C(Generic[T]):
1039
+ # x: T
1040
+ # C.x # Error, ambiguous access
1041
+ # C[int].x # Also an error, since C[int] is same as C at runtime
1042
+ # Exception is Self type wrapped in ClassVar, that is safe.
1043
+ def_vars = set(node.node.info.defn.type_vars)
1044
+ if not node.node.is_classvar and node.node.info.self_type:
1045
+ def_vars.add(node.node.info.self_type)
1046
+ typ_vars = set(get_type_vars(t))
1047
+ if def_vars & typ_vars:
1048
+ # Exception: access on Type[...], including first argument of class methods is OK.
1049
+ if not isinstance(get_proper_type(mx.original_type), TypeType) or node.implicit:
1050
+ if node.node.is_classvar:
1051
+ message = message_registry.GENERIC_CLASS_VAR_ACCESS
1052
+ else:
1053
+ message = message_registry.GENERIC_INSTANCE_VAR_CLASS_ACCESS
1054
+ mx.msg.fail(message, mx.context)
1055
+
1056
+ # Erase non-mapped variables, but keep mapped ones, even if there is an error.
1057
+ # In the above example this means that we infer following types:
1058
+ # C.x -> Any
1059
+ # C[int].x -> int
1060
+ t = get_proper_type(expand_self_type(node.node, t, itype))
1061
+ t = erase_typevars(expand_type_by_instance(t, isuper), {tv.id for tv in def_vars})
1062
+
1063
+ is_classmethod = (is_decorated and cast(Decorator, node.node).func.is_class) or (
1064
+ isinstance(node.node, FuncBase) and node.node.is_class
1065
+ )
1066
+ is_staticmethod = (is_decorated and cast(Decorator, node.node).func.is_static) or (
1067
+ isinstance(node.node, FuncBase) and node.node.is_static
1068
+ )
1069
+ t = get_proper_type(t)
1070
+ if isinstance(t, FunctionLike) and is_classmethod:
1071
+ t = check_self_arg(t, mx.self_type, False, mx.context, name, mx.msg)
1072
+ result = add_class_tvars(
1073
+ t, isuper, is_classmethod, is_staticmethod, mx.self_type, original_vars=original_vars
1074
+ )
1075
+ if not mx.is_lvalue:
1076
+ result = analyze_descriptor_access(result, mx)
1077
+
1078
+ return apply_class_attr_hook(mx, hook, result)
1079
+ elif isinstance(node.node, Var):
1080
+ mx.not_ready_callback(name, mx.context)
1081
+ return AnyType(TypeOfAny.special_form)
1082
+
1083
+ if isinstance(node.node, TypeVarExpr):
1084
+ mx.msg.fail(
1085
+ message_registry.CANNOT_USE_TYPEVAR_AS_EXPRESSION.format(info.name, name), mx.context
1086
+ )
1087
+ return AnyType(TypeOfAny.from_error)
1088
+
1089
+ if isinstance(node.node, TypeInfo):
1090
+ return type_object_type(node.node, mx.named_type)
1091
+
1092
+ if isinstance(node.node, MypyFile):
1093
+ # Reference to a module object.
1094
+ return mx.named_type("types.ModuleType")
1095
+
1096
+ if isinstance(node.node, TypeAlias):
1097
+ return mx.chk.expr_checker.alias_type_in_runtime_context(
1098
+ node.node, ctx=mx.context, alias_definition=mx.is_lvalue
1099
+ )
1100
+
1101
+ if is_decorated:
1102
+ assert isinstance(node.node, Decorator)
1103
+ if node.node.type:
1104
+ return apply_class_attr_hook(mx, hook, node.node.type)
1105
+ else:
1106
+ mx.not_ready_callback(name, mx.context)
1107
+ return AnyType(TypeOfAny.from_error)
1108
+ else:
1109
+ assert isinstance(node.node, FuncBase)
1110
+ typ = function_type(node.node, mx.named_type("builtins.function"))
1111
+ # Note: if we are accessing class method on class object, the cls argument is bound.
1112
+ # Annotated and/or explicit class methods go through other code paths above, for
1113
+ # unannotated implicit class methods we do this here.
1114
+ if node.node.is_class:
1115
+ typ = bind_self(typ, is_classmethod=True)
1116
+ return apply_class_attr_hook(mx, hook, typ)
1117
+
1118
+
1119
+ def apply_class_attr_hook(
1120
+ mx: MemberContext, hook: Callable[[AttributeContext], Type] | None, result: Type
1121
+ ) -> Type | None:
1122
+ if hook:
1123
+ result = hook(
1124
+ AttributeContext(get_proper_type(mx.original_type), result, mx.context, mx.chk)
1125
+ )
1126
+ return result
1127
+
1128
+
1129
+ def analyze_enum_class_attribute_access(
1130
+ itype: Instance, name: str, mx: MemberContext
1131
+ ) -> Type | None:
1132
+ # Skip these since Enum will remove it
1133
+ if name in ENUM_REMOVED_PROPS:
1134
+ return report_missing_attribute(mx.original_type, itype, name, mx)
1135
+ # For other names surrendered by underscores, we don't make them Enum members
1136
+ if name.startswith("__") and name.endswith("__") and name.replace("_", "") != "":
1137
+ return None
1138
+
1139
+ enum_literal = LiteralType(name, fallback=itype)
1140
+ return itype.copy_modified(last_known_value=enum_literal)
1141
+
1142
+
1143
+ def analyze_typeddict_access(
1144
+ name: str, typ: TypedDictType, mx: MemberContext, override_info: TypeInfo | None
1145
+ ) -> Type:
1146
+ if name == "__setitem__":
1147
+ if isinstance(mx.context, IndexExpr):
1148
+ # Since we can get this during `a['key'] = ...`
1149
+ # it is safe to assume that the context is `IndexExpr`.
1150
+ item_type = mx.chk.expr_checker.visit_typeddict_index_expr(
1151
+ typ, mx.context.index, setitem=True
1152
+ )
1153
+ else:
1154
+ # It can also be `a.__setitem__(...)` direct call.
1155
+ # In this case `item_type` can be `Any`,
1156
+ # because we don't have args available yet.
1157
+ # TODO: check in `default` plugin that `__setitem__` is correct.
1158
+ item_type = AnyType(TypeOfAny.implementation_artifact)
1159
+ return CallableType(
1160
+ arg_types=[mx.chk.named_type("builtins.str"), item_type],
1161
+ arg_kinds=[ARG_POS, ARG_POS],
1162
+ arg_names=[None, None],
1163
+ ret_type=NoneType(),
1164
+ fallback=mx.chk.named_type("builtins.function"),
1165
+ name=name,
1166
+ )
1167
+ elif name == "__delitem__":
1168
+ return CallableType(
1169
+ arg_types=[mx.chk.named_type("builtins.str")],
1170
+ arg_kinds=[ARG_POS],
1171
+ arg_names=[None],
1172
+ ret_type=NoneType(),
1173
+ fallback=mx.chk.named_type("builtins.function"),
1174
+ name=name,
1175
+ )
1176
+ return _analyze_member_access(name, typ.fallback, mx, override_info)
1177
+
1178
+
1179
+ def add_class_tvars(
1180
+ t: ProperType,
1181
+ isuper: Instance | None,
1182
+ is_classmethod: bool,
1183
+ is_staticmethod: bool,
1184
+ original_type: Type,
1185
+ original_vars: Sequence[TypeVarLikeType] | None = None,
1186
+ ) -> Type:
1187
+ """Instantiate type variables during analyze_class_attribute_access,
1188
+ e.g T and Q in the following:
1189
+
1190
+ class A(Generic[T]):
1191
+ @classmethod
1192
+ def foo(cls: Type[Q]) -> Tuple[T, Q]: ...
1193
+
1194
+ class B(A[str]): pass
1195
+ B.foo()
1196
+
1197
+ Args:
1198
+ t: Declared type of the method (or property)
1199
+ isuper: Current instance mapped to the superclass where method was defined, this
1200
+ is usually done by map_instance_to_supertype()
1201
+ is_classmethod: True if this method is decorated with @classmethod
1202
+ is_staticmethod: True if this method is decorated with @staticmethod
1203
+ original_type: The value of the type B in the expression B.foo() or the corresponding
1204
+ component in case of a union (this is used to bind the self-types)
1205
+ original_vars: Type variables of the class callable on which the method was accessed
1206
+ Returns:
1207
+ Expanded method type with added type variables (when needed).
1208
+ """
1209
+ # TODO: verify consistency between Q and T
1210
+
1211
+ # We add class type variables if the class method is accessed on class object
1212
+ # without applied type arguments, this matches the behavior of __init__().
1213
+ # For example (continuing the example in docstring):
1214
+ # A # The type of callable is def [T] () -> A[T], _not_ def () -> A[Any]
1215
+ # A[int] # The type of callable is def () -> A[int]
1216
+ # and
1217
+ # A.foo # The type is generic def [T] () -> Tuple[T, A[T]]
1218
+ # A[int].foo # The type is non-generic def () -> Tuple[int, A[int]]
1219
+ #
1220
+ # This behaviour is useful for defining alternative constructors for generic classes.
1221
+ # To achieve such behaviour, we add the class type variables that are still free
1222
+ # (i.e. appear in the return type of the class object on which the method was accessed).
1223
+ if isinstance(t, CallableType):
1224
+ tvars = original_vars if original_vars is not None else []
1225
+ t = freshen_all_functions_type_vars(t)
1226
+ if is_classmethod:
1227
+ t = bind_self(t, original_type, is_classmethod=True)
1228
+ if is_classmethod or is_staticmethod:
1229
+ assert isuper is not None
1230
+ t = expand_type_by_instance(t, isuper)
1231
+ freeze_all_type_vars(t)
1232
+ return t.copy_modified(variables=list(tvars) + list(t.variables))
1233
+ elif isinstance(t, Overloaded):
1234
+ return Overloaded(
1235
+ [
1236
+ cast(
1237
+ CallableType,
1238
+ add_class_tvars(
1239
+ item,
1240
+ isuper,
1241
+ is_classmethod,
1242
+ is_staticmethod,
1243
+ original_type,
1244
+ original_vars=original_vars,
1245
+ ),
1246
+ )
1247
+ for item in t.items
1248
+ ]
1249
+ )
1250
+ if isuper is not None:
1251
+ t = expand_type_by_instance(t, isuper)
1252
+ return t
1253
+
1254
+
1255
+ def type_object_type(info: TypeInfo, named_type: Callable[[str], Instance]) -> ProperType:
1256
+ """Return the type of a type object.
1257
+
1258
+ For a generic type G with type variables T and S the type is generally of form
1259
+
1260
+ Callable[..., G[T, S]]
1261
+
1262
+ where ... are argument types for the __init__/__new__ method (without the self
1263
+ argument). Also, the fallback type will be 'type' instead of 'function'.
1264
+ """
1265
+
1266
+ # We take the type from whichever of __init__ and __new__ is first
1267
+ # in the MRO, preferring __init__ if there is a tie.
1268
+ init_method = info.get("__init__")
1269
+ new_method = info.get("__new__")
1270
+ if not init_method or not is_valid_constructor(init_method.node):
1271
+ # Must be an invalid class definition.
1272
+ return AnyType(TypeOfAny.from_error)
1273
+ # There *should* always be a __new__ method except the test stubs
1274
+ # lack it, so just copy init_method in that situation
1275
+ new_method = new_method or init_method
1276
+ if not is_valid_constructor(new_method.node):
1277
+ # Must be an invalid class definition.
1278
+ return AnyType(TypeOfAny.from_error)
1279
+
1280
+ # The two is_valid_constructor() checks ensure this.
1281
+ assert isinstance(new_method.node, (SYMBOL_FUNCBASE_TYPES, Decorator))
1282
+ assert isinstance(init_method.node, (SYMBOL_FUNCBASE_TYPES, Decorator))
1283
+
1284
+ init_index = info.mro.index(init_method.node.info)
1285
+ new_index = info.mro.index(new_method.node.info)
1286
+
1287
+ fallback = info.metaclass_type or named_type("builtins.type")
1288
+ if init_index < new_index:
1289
+ method: FuncBase | Decorator = init_method.node
1290
+ is_new = False
1291
+ elif init_index > new_index:
1292
+ method = new_method.node
1293
+ is_new = True
1294
+ else:
1295
+ if init_method.node.info.fullname == "builtins.object":
1296
+ # Both are defined by object. But if we've got a bogus
1297
+ # base class, we can't know for sure, so check for that.
1298
+ if info.fallback_to_any:
1299
+ # Construct a universal callable as the prototype.
1300
+ any_type = AnyType(TypeOfAny.special_form)
1301
+ sig = CallableType(
1302
+ arg_types=[any_type, any_type],
1303
+ arg_kinds=[ARG_STAR, ARG_STAR2],
1304
+ arg_names=["_args", "_kwds"],
1305
+ ret_type=any_type,
1306
+ fallback=named_type("builtins.function"),
1307
+ )
1308
+ return class_callable(sig, info, fallback, None, is_new=False)
1309
+
1310
+ # Otherwise prefer __init__ in a tie. It isn't clear that this
1311
+ # is the right thing, but __new__ caused problems with
1312
+ # typeshed (#5647).
1313
+ method = init_method.node
1314
+ is_new = False
1315
+ # Construct callable type based on signature of __init__. Adjust
1316
+ # return type and insert type arguments.
1317
+ if isinstance(method, FuncBase):
1318
+ t = function_type(method, fallback)
1319
+ else:
1320
+ assert isinstance(method.type, ProperType)
1321
+ assert isinstance(method.type, FunctionLike) # is_valid_constructor() ensures this
1322
+ t = method.type
1323
+ return type_object_type_from_function(t, info, method.info, fallback, is_new)
1324
+
1325
+
1326
+ def analyze_decorator_or_funcbase_access(
1327
+ defn: Decorator | FuncBase,
1328
+ itype: Instance,
1329
+ info: TypeInfo,
1330
+ self_type: Type | None,
1331
+ name: str,
1332
+ mx: MemberContext,
1333
+ ) -> Type:
1334
+ """Analyzes the type behind method access.
1335
+
1336
+ The function itself can possibly be decorated.
1337
+ See: https://github.com/python/mypy/issues/10409
1338
+ """
1339
+ if isinstance(defn, Decorator):
1340
+ return analyze_var(name, defn.var, itype, info, mx)
1341
+ return bind_self(
1342
+ function_type(defn, mx.chk.named_type("builtins.function")), original_type=self_type
1343
+ )
1344
+
1345
+
1346
+ def is_valid_constructor(n: SymbolNode | None) -> bool:
1347
+ """Does this node represents a valid constructor method?
1348
+
1349
+ This includes normal functions, overloaded functions, and decorators
1350
+ that return a callable type.
1351
+ """
1352
+ if isinstance(n, FuncBase):
1353
+ return True
1354
+ if isinstance(n, Decorator):
1355
+ return isinstance(get_proper_type(n.type), FunctionLike)
1356
+ return False