@gnost-cli/darwin-arm64 0.0.1 → 0.5.1-rc.1
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.
- package/README.md +1 -1
- package/bundle/_internal/6ec57f84c680d3a3778b__mypyc.cpython-312-darwin.so +4 -0
- package/bundle/_internal/Python +0 -0
- package/bundle/_internal/Python.framework/Python +0 -0
- package/bundle/_internal/Python.framework/Resources/Info.plist +30 -0
- package/bundle/_internal/Python.framework/Versions/3.12/Python +0 -0
- package/bundle/_internal/Python.framework/Versions/3.12/Resources/Info.plist +30 -0
- package/bundle/_internal/Python.framework/Versions/Current/Python +0 -0
- package/bundle/_internal/Python.framework/Versions/Current/Resources/Info.plist +30 -0
- package/bundle/_internal/ast_serialize/ast_serialize.abi3.so +0 -0
- package/bundle/_internal/bandit/__init__.py +20 -0
- package/bundle/_internal/bandit/__main__.py +17 -0
- package/bundle/_internal/bandit/blacklists/__init__.py +0 -0
- package/bundle/_internal/bandit/blacklists/calls.py +670 -0
- package/bundle/_internal/bandit/blacklists/imports.py +425 -0
- package/bundle/_internal/bandit/blacklists/utils.py +17 -0
- package/bundle/_internal/bandit/cli/__init__.py +0 -0
- package/bundle/_internal/bandit/cli/baseline.py +252 -0
- package/bundle/_internal/bandit/cli/config_generator.py +207 -0
- package/bundle/_internal/bandit/cli/main.py +701 -0
- package/bundle/_internal/bandit/core/__init__.py +15 -0
- package/bundle/_internal/bandit/core/blacklisting.py +72 -0
- package/bundle/_internal/bandit/core/config.py +271 -0
- package/bundle/_internal/bandit/core/constants.py +40 -0
- package/bundle/_internal/bandit/core/context.py +316 -0
- package/bundle/_internal/bandit/core/docs_utils.py +54 -0
- package/bundle/_internal/bandit/core/extension_loader.py +114 -0
- package/bundle/_internal/bandit/core/issue.py +245 -0
- package/bundle/_internal/bandit/core/manager.py +499 -0
- package/bundle/_internal/bandit/core/meta_ast.py +44 -0
- package/bundle/_internal/bandit/core/metrics.py +106 -0
- package/bundle/_internal/bandit/core/node_visitor.py +297 -0
- package/bundle/_internal/bandit/core/test_properties.py +83 -0
- package/bundle/_internal/bandit/core/test_set.py +114 -0
- package/bundle/_internal/bandit/core/tester.py +168 -0
- package/bundle/_internal/bandit/core/utils.py +398 -0
- package/bundle/_internal/bandit/formatters/__init__.py +0 -0
- package/bundle/_internal/bandit/formatters/csv.py +82 -0
- package/bundle/_internal/bandit/formatters/custom.py +161 -0
- package/bundle/_internal/bandit/formatters/html.py +394 -0
- package/bundle/_internal/bandit/formatters/json.py +155 -0
- package/bundle/_internal/bandit/formatters/sarif.py +374 -0
- package/bundle/_internal/bandit/formatters/screen.py +244 -0
- package/bundle/_internal/bandit/formatters/text.py +200 -0
- package/bundle/_internal/bandit/formatters/utils.py +14 -0
- package/bundle/_internal/bandit/formatters/xml.py +97 -0
- package/bundle/_internal/bandit/formatters/yaml.py +126 -0
- package/bundle/_internal/bandit/plugins/__init__.py +0 -0
- package/bundle/_internal/bandit/plugins/app_debug.py +63 -0
- package/bundle/_internal/bandit/plugins/asserts.py +83 -0
- package/bundle/_internal/bandit/plugins/crypto_request_no_cert_validation.py +75 -0
- package/bundle/_internal/bandit/plugins/django_sql_injection.py +155 -0
- package/bundle/_internal/bandit/plugins/django_xss.py +287 -0
- package/bundle/_internal/bandit/plugins/exec.py +55 -0
- package/bundle/_internal/bandit/plugins/general_bad_file_permissions.py +99 -0
- package/bundle/_internal/bandit/plugins/general_bind_all_interfaces.py +52 -0
- package/bundle/_internal/bandit/plugins/general_hardcoded_password.py +282 -0
- package/bundle/_internal/bandit/plugins/general_hardcoded_tmp.py +79 -0
- package/bundle/_internal/bandit/plugins/hashlib_insecure_functions.py +121 -0
- package/bundle/_internal/bandit/plugins/huggingface_unsafe_download.py +166 -0
- package/bundle/_internal/bandit/plugins/injection_paramiko.py +63 -0
- package/bundle/_internal/bandit/plugins/injection_shell.py +706 -0
- package/bundle/_internal/bandit/plugins/injection_sql.py +143 -0
- package/bundle/_internal/bandit/plugins/injection_wildcard.py +144 -0
- package/bundle/_internal/bandit/plugins/insecure_ssl_tls.py +285 -0
- package/bundle/_internal/bandit/plugins/jinja2_templates.py +134 -0
- package/bundle/_internal/bandit/plugins/logging_config_insecure_listen.py +58 -0
- package/bundle/_internal/bandit/plugins/mako_templates.py +69 -0
- package/bundle/_internal/bandit/plugins/markupsafe_markup_xss.py +118 -0
- package/bundle/_internal/bandit/plugins/pytorch_load.py +77 -0
- package/bundle/_internal/bandit/plugins/request_without_timeout.py +84 -0
- package/bundle/_internal/bandit/plugins/snmp_security_check.py +110 -0
- package/bundle/_internal/bandit/plugins/ssh_no_host_key_verification.py +76 -0
- package/bundle/_internal/bandit/plugins/tarfile_unsafe_members.py +121 -0
- package/bundle/_internal/bandit/plugins/trojansource.py +82 -0
- package/bundle/_internal/bandit/plugins/try_except_continue.py +108 -0
- package/bundle/_internal/bandit/plugins/try_except_pass.py +106 -0
- package/bundle/_internal/bandit/plugins/weak_cryptographic_key.py +165 -0
- package/bundle/_internal/bandit/plugins/yaml_load.py +76 -0
- package/bundle/_internal/bandit-1.9.4.dist-info/INSTALLER +1 -0
- package/bundle/_internal/bandit-1.9.4.dist-info/METADATA +212 -0
- package/bundle/_internal/bandit-1.9.4.dist-info/RECORD +150 -0
- package/bundle/_internal/bandit-1.9.4.dist-info/WHEEL +5 -0
- package/bundle/_internal/bandit-1.9.4.dist-info/entry_points.txt +63 -0
- package/bundle/_internal/bandit-1.9.4.dist-info/licenses/LICENSE +175 -0
- package/bundle/_internal/bandit-1.9.4.dist-info/pbr.json +1 -0
- package/bundle/_internal/bandit-1.9.4.dist-info/top_level.txt +1 -0
- package/bundle/_internal/base_library.zip +0 -0
- package/bundle/_internal/bin/ruff +0 -0
- package/bundle/_internal/gnost/__init__.py +1 -0
- package/bundle/_internal/gnost/analysis/__init__.py +0 -0
- package/bundle/_internal/gnost/analysis/analyzers/__init__.py +11 -0
- package/bundle/_internal/gnost/analysis/analyzers/maintainability_analyzer.py +901 -0
- package/bundle/_internal/gnost/analysis/analyzers/observability_analyzer.py +592 -0
- package/bundle/_internal/gnost/analysis/analyzers/readability_analyzer.py +968 -0
- package/bundle/_internal/gnost/analysis/analyzers/robustness_analyzer.py +944 -0
- package/bundle/_internal/gnost/analysis/config/mypy.ini +4 -0
- package/bundle/_internal/gnost/analysis/core/__init__.py +0 -0
- package/bundle/_internal/gnost/analysis/core/aggregator.py +584 -0
- package/bundle/_internal/gnost/analysis/core/engine.py +430 -0
- package/bundle/_internal/gnost/analysis/core/file_utils.py +209 -0
- package/bundle/_internal/gnost/analysis/core/interfaces.py +304 -0
- package/bundle/_internal/gnost/analysis/core/models.py +479 -0
- package/bundle/_internal/gnost/analysis/core/tool_runner.py +153 -0
- package/bundle/_internal/gnost/analysis/core/transformers.py +779 -0
- package/bundle/_internal/gnost/analysis/utils/__init__.py +0 -0
- package/bundle/_internal/gnost/analysis/utils/analyze.py +132 -0
- package/bundle/_internal/gnost/analysis/utils/df_handling.py +215 -0
- package/bundle/_internal/gnost/analysis/utils/duplicate_code.py +42 -0
- package/bundle/_internal/gnost/analysis/utils/extract.py +172 -0
- package/bundle/_internal/gnost/analysis/utils/mi.py +130 -0
- package/bundle/_internal/gnost/analysis/utils/tool_command.py +63 -0
- package/bundle/_internal/gnost/cli/__init__.py +3 -0
- package/bundle/_internal/gnost/cli/app.py +696 -0
- package/bundle/_internal/gnost/cli/commands/__init__.py +3 -0
- package/bundle/_internal/gnost/cli/commands/analysis.py +190 -0
- package/bundle/_internal/gnost/cli/commands/onboard.py +507 -0
- package/bundle/_internal/gnost/cli/commands/show.py +70 -0
- package/bundle/_internal/gnost/config/__init__.py +0 -0
- package/bundle/_internal/gnost/config/languages.py +10 -0
- package/bundle/_internal/gnost/config/settings.py +240 -0
- package/bundle/_internal/gnost/core/__init__.py +0 -0
- package/bundle/_internal/gnost/core/callgraph.py +399 -0
- package/bundle/_internal/gnost/core/caution.py +315 -0
- package/bundle/_internal/gnost/core/cycles.py +148 -0
- package/bundle/_internal/gnost/core/flow.py +204 -0
- package/bundle/_internal/gnost/core/graph.py +108 -0
- package/bundle/_internal/gnost/core/insight_builder.py +164 -0
- package/bundle/_internal/gnost/core/ranker.py +119 -0
- package/bundle/_internal/gnost/core/resolver.py +304 -0
- package/bundle/_internal/gnost/languages/base.py +108 -0
- package/bundle/_internal/gnost/languages/java.py +104 -0
- package/bundle/_internal/gnost/languages/javascript.py +153 -0
- package/bundle/_internal/gnost/languages/manifests.py +45 -0
- package/bundle/_internal/gnost/languages/python.py +318 -0
- package/bundle/_internal/gnost/languages/typescript.py +6 -0
- package/bundle/_internal/gnost/models/__init__.py +0 -0
- package/bundle/_internal/gnost/models/insights.py +68 -0
- package/bundle/_internal/gnost/reporters/__init__.py +3 -0
- package/bundle/_internal/gnost/reporters/analysis_html.py +1292 -0
- package/bundle/_internal/gnost/reporters/diagram_viewer.py +153 -0
- package/bundle/_internal/gnost/reporters/files.py +18 -0
- package/bundle/_internal/gnost/reporters/folders.py +18 -0
- package/bundle/_internal/gnost/reporters/insights_json.py +189 -0
- package/bundle/_internal/gnost/reporters/loc_summary.py +19 -0
- package/bundle/_internal/gnost/reporters/markdown.py +372 -0
- package/bundle/_internal/gnost/reporters/mermaid.py +543 -0
- package/bundle/_internal/gnost/reporters/mermaid_graph.py +309 -0
- package/bundle/_internal/gnost/reporters/readme.py +81 -0
- package/bundle/_internal/gnost/reporters/stats.py +13 -0
- package/bundle/_internal/gnost/reporters/summary.py +223 -0
- package/bundle/_internal/gnost/reporters/templates/analyzer_guides.json +247 -0
- package/bundle/_internal/gnost/reporters/templates/analyzer_guides_layout.html +9 -0
- package/bundle/_internal/gnost/reporters/templates/graph_viewer.html +427 -0
- package/bundle/_internal/gnost/reporters/vendor/THIRD_PARTY_NOTICES.md +205 -0
- package/bundle/_internal/gnost/reporters/vendor/cose-base.js +3214 -0
- package/bundle/_internal/gnost/reporters/vendor/cytoscape-fcose.js +1549 -0
- package/bundle/_internal/gnost/reporters/vendor/cytoscape.min.js +32 -0
- package/bundle/_internal/gnost/reporters/vendor/layout-base.js +5230 -0
- package/bundle/_internal/gnost/reporters/vendor/marked.min.js +6 -0
- package/bundle/_internal/gnost/reporters/vendor/mermaid.min.js +2314 -0
- package/bundle/_internal/gnost/reporters/vendor/svg-pan-zoom.min.js +3 -0
- package/bundle/_internal/gnost/reporters/vendor/vendor.json +44 -0
- package/bundle/_internal/gnost/routes/__init__.py +45 -0
- package/bundle/_internal/gnost/routes/java.py +72 -0
- package/bundle/_internal/gnost/routes/javascript.py +275 -0
- package/bundle/_internal/gnost/routes/models.py +58 -0
- package/bundle/_internal/gnost/routes/python.py +429 -0
- package/bundle/_internal/gnost/scanner/__init__.py +4 -0
- package/bundle/_internal/gnost/scanner/classify.py +13 -0
- package/bundle/_internal/gnost/scanner/engine.py +169 -0
- package/bundle/_internal/gnost/scanner/filters.py +196 -0
- package/bundle/_internal/gnost/scanner/loc.py +93 -0
- package/bundle/_internal/gnost/scanner/models.py +27 -0
- package/bundle/_internal/gnost/schemas/insights.schema.json +517 -0
- package/bundle/_internal/gnost/utils/__init__.py +0 -0
- package/bundle/_internal/gnost/utils/logger.py +85 -0
- package/bundle/_internal/gnost/utils/paths.py +29 -0
- package/bundle/_internal/gnost/utils/printer.py +46 -0
- package/bundle/_internal/gnost/utils/progress.py +20 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/INSTALLER +1 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/METADATA +130 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/RECORD +178 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/REQUESTED +0 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/WHEEL +5 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/direct_url.json +1 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/entry_points.txt +2 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/licenses/LICENSE +21 -0
- package/bundle/_internal/gnost-0.5.1rc1.dist-info/top_level.txt +1 -0
- package/bundle/_internal/libcrypto.3.dylib +0 -0
- package/bundle/_internal/libncurses.6.dylib +0 -0
- package/bundle/_internal/librt/base64.cpython-312-darwin.so +0 -0
- package/bundle/_internal/librt/internal.cpython-312-darwin.so +0 -0
- package/bundle/_internal/libssl.3.dylib +0 -0
- package/bundle/_internal/mypy/__init__.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/__init__.py +1 -0
- package/bundle/_internal/mypy/__main__.py +52 -0
- package/bundle/_internal/mypy/api.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/api.py +95 -0
- package/bundle/_internal/mypy/applytype.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/applytype.py +317 -0
- package/bundle/_internal/mypy/argmap.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/argmap.py +269 -0
- package/bundle/_internal/mypy/binder.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/binder.py +710 -0
- package/bundle/_internal/mypy/bogus_type.py +27 -0
- package/bundle/_internal/mypy/build.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/build.py +5533 -0
- package/bundle/_internal/mypy/build_worker/__init__.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/build_worker/__init__.py +0 -0
- package/bundle/_internal/mypy/build_worker/__main__.py +6 -0
- package/bundle/_internal/mypy/build_worker/worker.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/build_worker/worker.py +379 -0
- package/bundle/_internal/mypy/cache.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/cache.py +626 -0
- package/bundle/_internal/mypy/checker.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/checker.py +10110 -0
- package/bundle/_internal/mypy/checker_shared.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/checker_shared.py +377 -0
- package/bundle/_internal/mypy/checker_state.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/checker_state.py +30 -0
- package/bundle/_internal/mypy/checkexpr.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/checkexpr.py +7018 -0
- package/bundle/_internal/mypy/checkmember.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/checkmember.py +1593 -0
- package/bundle/_internal/mypy/checkpattern.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/checkpattern.py +883 -0
- package/bundle/_internal/mypy/checkstrformat.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/checkstrformat.py +1103 -0
- package/bundle/_internal/mypy/config_parser.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/config_parser.py +749 -0
- package/bundle/_internal/mypy/constant_fold.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/constant_fold.py +187 -0
- package/bundle/_internal/mypy/constraints.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/constraints.py +1748 -0
- package/bundle/_internal/mypy/copytype.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/copytype.py +137 -0
- package/bundle/_internal/mypy/defaults.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/defaults.py +67 -0
- package/bundle/_internal/mypy/dmypy/__init__.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/dmypy/__init__.py +0 -0
- package/bundle/_internal/mypy/dmypy/__main__.py +6 -0
- package/bundle/_internal/mypy/dmypy/client.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/dmypy/client.py +732 -0
- package/bundle/_internal/mypy/dmypy_os.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/dmypy_os.py +43 -0
- package/bundle/_internal/mypy/dmypy_server.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/dmypy_server.py +1132 -0
- package/bundle/_internal/mypy/dmypy_util.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/dmypy_util.py +117 -0
- package/bundle/_internal/mypy/erasetype.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/erasetype.py +301 -0
- package/bundle/_internal/mypy/error_formatter.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/error_formatter.py +39 -0
- package/bundle/_internal/mypy/errorcodes.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/errorcodes.py +340 -0
- package/bundle/_internal/mypy/errors.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/errors.py +1468 -0
- package/bundle/_internal/mypy/evalexpr.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/evalexpr.py +211 -0
- package/bundle/_internal/mypy/expandtype.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/expandtype.py +662 -0
- package/bundle/_internal/mypy/exportjson.py +616 -0
- package/bundle/_internal/mypy/exprtotype.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/exprtotype.py +285 -0
- package/bundle/_internal/mypy/fastparse.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/fastparse.py +2267 -0
- package/bundle/_internal/mypy/find_sources.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/find_sources.py +257 -0
- package/bundle/_internal/mypy/fixup.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/fixup.py +438 -0
- package/bundle/_internal/mypy/freetree.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/freetree.py +23 -0
- package/bundle/_internal/mypy/fscache.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/fscache.py +312 -0
- package/bundle/_internal/mypy/fswatcher.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/fswatcher.py +106 -0
- package/bundle/_internal/mypy/gclogger.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/gclogger.py +48 -0
- package/bundle/_internal/mypy/git.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/git.py +69 -0
- package/bundle/_internal/mypy/graph_utils.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/graph_utils.py +161 -0
- package/bundle/_internal/mypy/indirection.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/indirection.py +176 -0
- package/bundle/_internal/mypy/infer.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/infer.py +80 -0
- package/bundle/_internal/mypy/inspections.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/inspections.py +626 -0
- package/bundle/_internal/mypy/ipc.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/ipc.py +508 -0
- package/bundle/_internal/mypy/join.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/join.py +962 -0
- package/bundle/_internal/mypy/known_modules.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/known_modules.py +174 -0
- package/bundle/_internal/mypy/literals.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/literals.py +327 -0
- package/bundle/_internal/mypy/lookup.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/lookup.py +80 -0
- package/bundle/_internal/mypy/main.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/main.py +1793 -0
- package/bundle/_internal/mypy/maptype.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/maptype.py +109 -0
- package/bundle/_internal/mypy/meet.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/meet.py +1371 -0
- package/bundle/_internal/mypy/memprofile.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/memprofile.py +122 -0
- package/bundle/_internal/mypy/message_registry.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/message_registry.py +378 -0
- package/bundle/_internal/mypy/messages.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/messages.py +3535 -0
- package/bundle/_internal/mypy/metastore.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/metastore.py +278 -0
- package/bundle/_internal/mypy/mixedtraverser.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/mixedtraverser.py +147 -0
- package/bundle/_internal/mypy/modulefinder.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/modulefinder.py +1008 -0
- package/bundle/_internal/mypy/moduleinspect.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/moduleinspect.py +184 -0
- package/bundle/_internal/mypy/modules_state.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/modules_state.py +20 -0
- package/bundle/_internal/mypy/mro.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/mro.py +62 -0
- package/bundle/_internal/mypy/nativeparse.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/nativeparse.py +2199 -0
- package/bundle/_internal/mypy/nodes.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/nodes.py +5608 -0
- package/bundle/_internal/mypy/operators.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/operators.py +126 -0
- package/bundle/_internal/mypy/options.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/options.py +678 -0
- package/bundle/_internal/mypy/parse.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/parse.py +135 -0
- package/bundle/_internal/mypy/partially_defined.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/partially_defined.py +703 -0
- package/bundle/_internal/mypy/patterns.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/patterns.py +162 -0
- package/bundle/_internal/mypy/plugin.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugin.py +945 -0
- package/bundle/_internal/mypy/plugins/__init__.py +0 -0
- package/bundle/_internal/mypy/plugins/attrs.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/attrs.py +1179 -0
- package/bundle/_internal/mypy/plugins/common.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/common.py +441 -0
- package/bundle/_internal/mypy/plugins/constants.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/constants.py +20 -0
- package/bundle/_internal/mypy/plugins/ctypes.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/ctypes.py +245 -0
- package/bundle/_internal/mypy/plugins/dataclasses.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/dataclasses.py +1135 -0
- package/bundle/_internal/mypy/plugins/default.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/default.py +612 -0
- package/bundle/_internal/mypy/plugins/enums.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/enums.py +299 -0
- package/bundle/_internal/mypy/plugins/functools.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/functools.py +399 -0
- package/bundle/_internal/mypy/plugins/proper_plugin.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/proper_plugin.py +178 -0
- package/bundle/_internal/mypy/plugins/singledispatch.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/plugins/singledispatch.py +212 -0
- package/bundle/_internal/mypy/py.typed +1 -0
- package/bundle/_internal/mypy/pyinfo.py +79 -0
- package/bundle/_internal/mypy/reachability.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/reachability.py +388 -0
- package/bundle/_internal/mypy/refinfo.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/refinfo.py +92 -0
- package/bundle/_internal/mypy/renaming.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/renaming.py +583 -0
- package/bundle/_internal/mypy/report.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/report.py +930 -0
- package/bundle/_internal/mypy/scope.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/scope.py +125 -0
- package/bundle/_internal/mypy/semanal.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal.py +8674 -0
- package/bundle/_internal/mypy/semanal_classprop.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_classprop.py +188 -0
- package/bundle/_internal/mypy/semanal_enum.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_enum.py +259 -0
- package/bundle/_internal/mypy/semanal_infer.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_infer.py +135 -0
- package/bundle/_internal/mypy/semanal_main.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_main.py +542 -0
- package/bundle/_internal/mypy/semanal_namedtuple.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_namedtuple.py +679 -0
- package/bundle/_internal/mypy/semanal_newtype.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_newtype.py +272 -0
- package/bundle/_internal/mypy/semanal_pass1.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_pass1.py +159 -0
- package/bundle/_internal/mypy/semanal_shared.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_shared.py +499 -0
- package/bundle/_internal/mypy/semanal_typeargs.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_typeargs.py +309 -0
- package/bundle/_internal/mypy/semanal_typeddict.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/semanal_typeddict.py +826 -0
- package/bundle/_internal/mypy/server/__init__.py +0 -0
- package/bundle/_internal/mypy/server/astdiff.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/astdiff.py +552 -0
- package/bundle/_internal/mypy/server/astmerge.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/astmerge.py +583 -0
- package/bundle/_internal/mypy/server/aststrip.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/aststrip.py +255 -0
- package/bundle/_internal/mypy/server/deps.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/deps.py +1153 -0
- package/bundle/_internal/mypy/server/mergecheck.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/mergecheck.py +84 -0
- package/bundle/_internal/mypy/server/objgraph.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/objgraph.py +101 -0
- package/bundle/_internal/mypy/server/subexpr.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/subexpr.py +208 -0
- package/bundle/_internal/mypy/server/target.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/target.py +11 -0
- package/bundle/_internal/mypy/server/trigger.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/trigger.py +26 -0
- package/bundle/_internal/mypy/server/update.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/server/update.py +1372 -0
- package/bundle/_internal/mypy/sharedparse.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/sharedparse.py +114 -0
- package/bundle/_internal/mypy/solve.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/solve.py +602 -0
- package/bundle/_internal/mypy/split_namespace.py +35 -0
- package/bundle/_internal/mypy/state.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/state.py +29 -0
- package/bundle/_internal/mypy/stats.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/stats.py +494 -0
- package/bundle/_internal/mypy/strconv.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/strconv.py +707 -0
- package/bundle/_internal/mypy/stubdoc.py +545 -0
- package/bundle/_internal/mypy/stubgen.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/stubgen.py +2064 -0
- package/bundle/_internal/mypy/stubgenc.py +1046 -0
- package/bundle/_internal/mypy/stubinfo.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/stubinfo.py +321 -0
- package/bundle/_internal/mypy/stubtest.py +2676 -0
- package/bundle/_internal/mypy/stubutil.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/stubutil.py +895 -0
- package/bundle/_internal/mypy/subtypes.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/subtypes.py +2572 -0
- package/bundle/_internal/mypy/suggestions.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/suggestions.py +1068 -0
- package/bundle/_internal/mypy/test/__init__.py +0 -0
- package/bundle/_internal/mypy/test/config.py +31 -0
- package/bundle/_internal/mypy/test/data.py +864 -0
- package/bundle/_internal/mypy/test/helpers.py +546 -0
- package/bundle/_internal/mypy/test/meta/__init__.py +0 -0
- package/bundle/_internal/mypy/test/meta/_pytest.py +72 -0
- package/bundle/_internal/mypy/test/meta/test_diff_helper.py +47 -0
- package/bundle/_internal/mypy/test/meta/test_parse_data.py +69 -0
- package/bundle/_internal/mypy/test/meta/test_update_data.py +131 -0
- package/bundle/_internal/mypy/test/test_config_parser.py +130 -0
- package/bundle/_internal/mypy/test/test_diff_cache.py +209 -0
- package/bundle/_internal/mypy/test/test_find_sources.py +376 -0
- package/bundle/_internal/mypy/test/test_nativeparse.py +306 -0
- package/bundle/_internal/mypy/test/test_ref_info.py +46 -0
- package/bundle/_internal/mypy/test/testapi.py +45 -0
- package/bundle/_internal/mypy/test/testargs.py +202 -0
- package/bundle/_internal/mypy/test/testcheck.py +360 -0
- package/bundle/_internal/mypy/test/testcmdline.py +162 -0
- package/bundle/_internal/mypy/test/testconstraints.py +134 -0
- package/bundle/_internal/mypy/test/testdaemon.py +132 -0
- package/bundle/_internal/mypy/test/testdeps.py +85 -0
- package/bundle/_internal/mypy/test/testdiff.py +70 -0
- package/bundle/_internal/mypy/test/testerrorstream.py +46 -0
- package/bundle/_internal/mypy/test/testexportjson.py +104 -0
- package/bundle/_internal/mypy/test/testfinegrained.py +453 -0
- package/bundle/_internal/mypy/test/testfinegrainedcache.py +18 -0
- package/bundle/_internal/mypy/test/testformatter.py +85 -0
- package/bundle/_internal/mypy/test/testfscache.py +100 -0
- package/bundle/_internal/mypy/test/testgraph.py +138 -0
- package/bundle/_internal/mypy/test/testinfer.py +373 -0
- package/bundle/_internal/mypy/test/testipc.py +154 -0
- package/bundle/_internal/mypy/test/testmerge.py +235 -0
- package/bundle/_internal/mypy/test/testmodulefinder.py +284 -0
- package/bundle/_internal/mypy/test/testmypyc.py +26 -0
- package/bundle/_internal/mypy/test/testoutput.py +64 -0
- package/bundle/_internal/mypy/test/testparse.py +131 -0
- package/bundle/_internal/mypy/test/testpep561.py +174 -0
- package/bundle/_internal/mypy/test/testpythoneval.py +116 -0
- package/bundle/_internal/mypy/test/testreports.py +59 -0
- package/bundle/_internal/mypy/test/testsemanal.py +219 -0
- package/bundle/_internal/mypy/test/testsolve.py +287 -0
- package/bundle/_internal/mypy/test/teststubgen.py +1650 -0
- package/bundle/_internal/mypy/test/teststubinfo.py +24 -0
- package/bundle/_internal/mypy/test/teststubtest.py +3417 -0
- package/bundle/_internal/mypy/test/testsubtypes.py +306 -0
- package/bundle/_internal/mypy/test/testtransform.py +64 -0
- package/bundle/_internal/mypy/test/testtypegen.py +83 -0
- package/bundle/_internal/mypy/test/testtypes.py +1666 -0
- package/bundle/_internal/mypy/test/testutil.py +111 -0
- package/bundle/_internal/mypy/test/typefixture.py +419 -0
- package/bundle/_internal/mypy/test/update_data.py +87 -0
- package/bundle/_internal/mypy/test/visitors.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/test/visitors.py +77 -0
- package/bundle/_internal/mypy/traverser.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/traverser.py +1106 -0
- package/bundle/_internal/mypy/treetransform.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/treetransform.py +820 -0
- package/bundle/_internal/mypy/tvar_scope.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/tvar_scope.py +154 -0
- package/bundle/_internal/mypy/type_visitor.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/type_visitor.py +630 -0
- package/bundle/_internal/mypy/typeanal.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/typeanal.py +2961 -0
- package/bundle/_internal/mypy/typeops.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/typeops.py +1355 -0
- package/bundle/_internal/mypy/types.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/types.py +4639 -0
- package/bundle/_internal/mypy/types_utils.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/types_utils.py +183 -0
- package/bundle/_internal/mypy/typeshed/LICENSE +237 -0
- package/bundle/_internal/mypy/typeshed/stdlib/VERSIONS +349 -0
- package/bundle/_internal/mypy/typeshed/stdlib/__future__.pyi +36 -0
- package/bundle/_internal/mypy/typeshed/stdlib/__main__.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_ast.pyi +141 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_asyncio.pyi +114 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_bisect.pyi +103 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_blake2.pyi +119 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_bz2.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_codecs.pyi +125 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_collections_abc.pyi +105 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_compat_pickle.pyi +10 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_compression.pyi +39 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_contextvars.pyi +69 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_csv.pyi +116 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_ctypes.pyi +375 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_curses.pyi +583 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_curses_panel.pyi +27 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_dbm.pyi +46 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_decimal.pyi +73 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_frozen_importlib.pyi +121 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_frozen_importlib_external.pyi +218 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_gdbm.pyi +50 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_hashlib.pyi +127 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_heapq.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_imp.pyi +30 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_interpchannels.pyi +86 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_interpqueues.pyi +31 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_interpreters.pyi +68 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_io.pyi +330 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_json.pyi +59 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_locale.pyi +121 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_lsprof.pyi +34 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_lzma.pyi +71 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_markupbase.pyi +10 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_msi.pyi +97 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_multibytecodec.pyi +49 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_operator.pyi +130 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_osx_support.pyi +34 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_pickle.pyi +114 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_posixsubprocess.pyi +59 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_py_abc.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_pydecimal.pyi +50 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_queue.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_random.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_remote_debugging.pyi +186 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_sitebuiltins.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_socket.pyi +966 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_sqlite3.pyi +311 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_ssl.pyi +303 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_stat.pyi +119 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_struct.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_thread.pyi +125 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_threading_local.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_tkinter.pyi +156 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_tracemalloc.pyi +13 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_typeshed/README.md +34 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_typeshed/__init__.pyi +415 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_typeshed/_type_checker_internals.pyi +102 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_typeshed/dbapi.pyi +36 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_typeshed/importlib.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_typeshed/wsgi.pyi +43 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_typeshed/xml.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_warnings.pyi +54 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_weakref.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_weakrefset.pyi +49 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_winapi.pyi +319 -0
- package/bundle/_internal/mypy/typeshed/stdlib/_zstd.pyi +102 -0
- package/bundle/_internal/mypy/typeshed/stdlib/abc.pyi +50 -0
- package/bundle/_internal/mypy/typeshed/stdlib/aifc.pyi +79 -0
- package/bundle/_internal/mypy/typeshed/stdlib/annotationlib.pyi +156 -0
- package/bundle/_internal/mypy/typeshed/stdlib/antigravity.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/argparse.pyi +866 -0
- package/bundle/_internal/mypy/typeshed/stdlib/array.pyi +113 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ast.pyi +2199 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asynchat.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/__init__.pyi +1022 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/base_events.pyi +607 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/base_futures.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/base_subprocess.pyi +62 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/base_tasks.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/constants.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/coroutines.pyi +45 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/events.pyi +803 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/exceptions.pyi +44 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/format_helpers.pyi +31 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/futures.pyi +19 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/graph.pyi +29 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/locks.pyi +83 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/log.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/mixins.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/proactor_events.pyi +53 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/protocols.pyi +39 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/queues.pyi +45 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/runners.pyi +41 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/selector_events.pyi +10 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/sslproto.pyi +164 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/staggered.pyi +10 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/streams.pyi +124 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/subprocess.pyi +166 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/taskgroups.pyi +41 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/tasks.pyi +315 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/threads.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/timeouts.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/tools.pyi +51 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/transports.pyi +57 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/trsock.pyi +137 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/unix_events.pyi +277 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/windows_events.pyi +122 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncio/windows_utils.pyi +49 -0
- package/bundle/_internal/mypy/typeshed/stdlib/asyncore.pyi +91 -0
- package/bundle/_internal/mypy/typeshed/stdlib/atexit.pyi +11 -0
- package/bundle/_internal/mypy/typeshed/stdlib/audioop.pyi +44 -0
- package/bundle/_internal/mypy/typeshed/stdlib/base64.pyi +124 -0
- package/bundle/_internal/mypy/typeshed/stdlib/bdb.pyi +139 -0
- package/bundle/_internal/mypy/typeshed/stdlib/binascii.pyi +102 -0
- package/bundle/_internal/mypy/typeshed/stdlib/binhex.pyi +44 -0
- package/bundle/_internal/mypy/typeshed/stdlib/bisect.pyi +4 -0
- package/bundle/_internal/mypy/typeshed/stdlib/builtins.pyi +2470 -0
- package/bundle/_internal/mypy/typeshed/stdlib/bz2.pyi +121 -0
- package/bundle/_internal/mypy/typeshed/stdlib/cProfile.pyi +33 -0
- package/bundle/_internal/mypy/typeshed/stdlib/calendar.pyi +249 -0
- package/bundle/_internal/mypy/typeshed/stdlib/cgi.pyi +120 -0
- package/bundle/_internal/mypy/typeshed/stdlib/cgitb.pyi +32 -0
- package/bundle/_internal/mypy/typeshed/stdlib/chunk.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/cmath.pyi +36 -0
- package/bundle/_internal/mypy/typeshed/stdlib/cmd.pyi +46 -0
- package/bundle/_internal/mypy/typeshed/stdlib/code.pyi +55 -0
- package/bundle/_internal/mypy/typeshed/stdlib/codecs.pyi +357 -0
- package/bundle/_internal/mypy/typeshed/stdlib/codeop.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/collections/__init__.pyi +565 -0
- package/bundle/_internal/mypy/typeshed/stdlib/collections/abc.pyi +2 -0
- package/bundle/_internal/mypy/typeshed/stdlib/colorsys.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compileall.pyi +51 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/_common/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/_common/_streams.pyi +37 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/bz2.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/gzip.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/lzma.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/zlib.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/zstd/__init__.pyi +94 -0
- package/bundle/_internal/mypy/typeshed/stdlib/compression/zstd/_zstdfile.pyi +117 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/futures/__init__.pyi +71 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/futures/_base.pyi +119 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/futures/interpreter.pyi +82 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/futures/process.pyi +248 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/futures/thread.pyi +143 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/interpreters/__init__.pyi +68 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/interpreters/_crossinterp.pyi +30 -0
- package/bundle/_internal/mypy/typeshed/stdlib/concurrent/interpreters/_queues.pyi +74 -0
- package/bundle/_internal/mypy/typeshed/stdlib/configparser.pyi +509 -0
- package/bundle/_internal/mypy/typeshed/stdlib/contextlib.pyi +211 -0
- package/bundle/_internal/mypy/typeshed/stdlib/contextvars.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/copy.pyi +37 -0
- package/bundle/_internal/mypy/typeshed/stdlib/copyreg.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/crypt.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/csv.pyi +153 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ctypes/__init__.pyi +394 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ctypes/_endian.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ctypes/macholib/__init__.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ctypes/macholib/dyld.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ctypes/macholib/dylib.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ctypes/macholib/framework.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ctypes/util.pyi +11 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ctypes/wintypes.pyi +321 -0
- package/bundle/_internal/mypy/typeshed/stdlib/curses/__init__.pyi +38 -0
- package/bundle/_internal/mypy/typeshed/stdlib/curses/ascii.pyi +62 -0
- package/bundle/_internal/mypy/typeshed/stdlib/curses/has_key.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/curses/panel.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/curses/textpad.pyi +11 -0
- package/bundle/_internal/mypy/typeshed/stdlib/dataclasses.pyi +401 -0
- package/bundle/_internal/mypy/typeshed/stdlib/datetime.pyi +381 -0
- package/bundle/_internal/mypy/typeshed/stdlib/dbm/__init__.pyi +105 -0
- package/bundle/_internal/mypy/typeshed/stdlib/dbm/dumb.pyi +41 -0
- package/bundle/_internal/mypy/typeshed/stdlib/dbm/gnu.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/dbm/ndbm.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/dbm/sqlite3.pyi +34 -0
- package/bundle/_internal/mypy/typeshed/stdlib/decimal.pyi +278 -0
- package/bundle/_internal/mypy/typeshed/stdlib/difflib.pyi +157 -0
- package/bundle/_internal/mypy/typeshed/stdlib/dis.pyi +302 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/__init__.pyi +5 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/_msvccompiler.pyi +13 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/archive_util.pyi +36 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/bcppcompiler.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/ccompiler.pyi +182 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/cmd.pyi +238 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/__init__.pyi +41 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/bdist.pyi +27 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/bdist_dumb.pyi +22 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/bdist_msi.pyi +45 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/bdist_packager.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/bdist_rpm.pyi +53 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/build.pyi +34 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/build_clib.pyi +29 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/build_ext.pyi +52 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/build_py.pyi +45 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/build_scripts.pyi +25 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/check.pyi +39 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/clean.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/config.pyi +84 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/install.pyi +67 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/install_data.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/install_egg_info.pyi +19 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/install_headers.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/install_lib.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/install_scripts.pyi +19 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/register.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/sdist.pyi +45 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/command/upload.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/config.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/core.pyi +58 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/cygwinccompiler.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/debug.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/dep_util.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/dir_util.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/dist.pyi +318 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/errors.pyi +19 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/extension.pyi +36 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/fancy_getopt.pyi +45 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/file_util.pyi +40 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/filelist.pyi +61 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/log.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/msvccompiler.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/spawn.pyi +10 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/sysconfig.pyi +32 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/text_file.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/unixccompiler.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/util.pyi +53 -0
- package/bundle/_internal/mypy/typeshed/stdlib/distutils/version.pyi +36 -0
- package/bundle/_internal/mypy/typeshed/stdlib/doctest.pyi +265 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/__init__.pyi +68 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/_header_value_parser.pyi +415 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/_policybase.pyi +80 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/base64mime.pyi +13 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/charset.pyi +44 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/contentmanager.pyi +11 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/encoders.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/errors.pyi +38 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/feedparser.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/generator.pyi +79 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/header.pyi +32 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/headerregistry.pyi +196 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/iterators.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/message.pyi +191 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/application.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/audio.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/base.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/image.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/message.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/multipart.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/nonmultipart.pyi +5 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/mime/text.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/parser.pyi +42 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/policy.pyi +78 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/quoprimime.pyi +28 -0
- package/bundle/_internal/mypy/typeshed/stdlib/email/utils.pyi +72 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/__init__.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/aliases.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/ascii.pyi +30 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/base64_codec.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/big5.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/big5hkscs.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/bz2_codec.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/charmap.pyi +33 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp037.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1006.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1026.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1125.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1140.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1250.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1251.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1252.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1253.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1254.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1255.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1256.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1257.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp1258.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp273.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp424.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp437.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp500.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp720.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp737.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp775.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp850.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp852.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp855.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp856.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp857.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp858.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp860.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp861.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp862.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp863.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp864.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp865.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp866.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp869.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp874.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp875.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp932.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp949.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/cp950.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/euc_jis_2004.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/euc_jisx0213.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/euc_jp.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/euc_kr.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/gb18030.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/gb2312.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/gbk.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/hex_codec.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/hp_roman8.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/hz.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/idna.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso2022_jp.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso2022_jp_1.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso2022_jp_2.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso2022_jp_2004.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso2022_jp_3.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso2022_jp_ext.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso2022_kr.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_1.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_10.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_11.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_13.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_14.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_15.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_16.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_2.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_3.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_4.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_5.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_6.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_7.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_8.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/iso8859_9.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/johab.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/koi8_r.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/koi8_t.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/koi8_u.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/kz1048.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/latin_1.pyi +30 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_arabic.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_croatian.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_cyrillic.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_farsi.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_greek.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_iceland.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_latin2.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_roman.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_romanian.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mac_turkish.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/mbcs.pyi +28 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/oem.pyi +28 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/palmos.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/ptcp154.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/punycode.pyi +33 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/quopri_codec.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/raw_unicode_escape.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/rot_13.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/shift_jis.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/shift_jis_2004.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/shift_jisx0213.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/tis_620.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/undefined.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/unicode_escape.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_16.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_16_be.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_16_le.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_32.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_32_be.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_32_le.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_7.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_8.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/utf_8_sig.pyi +22 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/uu_codec.pyi +28 -0
- package/bundle/_internal/mypy/typeshed/stdlib/encodings/zlib_codec.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ensurepip/__init__.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/enum.pyi +374 -0
- package/bundle/_internal/mypy/typeshed/stdlib/errno.pyi +227 -0
- package/bundle/_internal/mypy/typeshed/stdlib/faulthandler.pyi +61 -0
- package/bundle/_internal/mypy/typeshed/stdlib/fcntl.pyi +157 -0
- package/bundle/_internal/mypy/typeshed/stdlib/filecmp.pyi +65 -0
- package/bundle/_internal/mypy/typeshed/stdlib/fileinput.pyi +141 -0
- package/bundle/_internal/mypy/typeshed/stdlib/fnmatch.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/fractions.pyi +185 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ftplib.pyi +174 -0
- package/bundle/_internal/mypy/typeshed/stdlib/functools.pyi +287 -0
- package/bundle/_internal/mypy/typeshed/stdlib/gc.pyi +32 -0
- package/bundle/_internal/mypy/typeshed/stdlib/genericpath.pyi +98 -0
- package/bundle/_internal/mypy/typeshed/stdlib/getopt.pyi +27 -0
- package/bundle/_internal/mypy/typeshed/stdlib/getpass.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/gettext.pyi +190 -0
- package/bundle/_internal/mypy/typeshed/stdlib/glob.pyi +50 -0
- package/bundle/_internal/mypy/typeshed/stdlib/graphlib.pyi +29 -0
- package/bundle/_internal/mypy/typeshed/stdlib/grp.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/gzip.pyi +181 -0
- package/bundle/_internal/mypy/typeshed/stdlib/hashlib.pyi +112 -0
- package/bundle/_internal/mypy/typeshed/stdlib/heapq.pyi +32 -0
- package/bundle/_internal/mypy/typeshed/stdlib/hmac.pyi +33 -0
- package/bundle/_internal/mypy/typeshed/stdlib/html/__init__.pyi +7 -0
- package/bundle/_internal/mypy/typeshed/stdlib/html/entities.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/html/parser.pyi +40 -0
- package/bundle/_internal/mypy/typeshed/stdlib/http/__init__.pyi +118 -0
- package/bundle/_internal/mypy/typeshed/stdlib/http/client.pyi +318 -0
- package/bundle/_internal/mypy/typeshed/stdlib/http/cookiejar.pyi +158 -0
- package/bundle/_internal/mypy/typeshed/stdlib/http/cookies.pyi +57 -0
- package/bundle/_internal/mypy/typeshed/stdlib/http/server.pyi +139 -0
- package/bundle/_internal/mypy/typeshed/stdlib/imaplib.pyi +212 -0
- package/bundle/_internal/mypy/typeshed/stdlib/imghdr.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/imp.pyi +63 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/__init__.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/_abc.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/_bootstrap.pyi +2 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/_bootstrap_external.pyi +2 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/abc.pyi +165 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/machinery.pyi +43 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi +310 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/metadata/_meta.pyi +65 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/metadata/diagnose.pyi +2 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/readers.pyi +69 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/resources/__init__.pyi +81 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/resources/_common.pyi +48 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/resources/_functional.pyi +35 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/resources/abc.pyi +64 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/resources/readers.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/resources/simple.pyi +59 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/simple.pyi +11 -0
- package/bundle/_internal/mypy/typeshed/stdlib/importlib/util.pyi +75 -0
- package/bundle/_internal/mypy/typeshed/stdlib/inspect.pyi +749 -0
- package/bundle/_internal/mypy/typeshed/stdlib/io.pyi +75 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ipaddress.pyi +249 -0
- package/bundle/_internal/mypy/typeshed/stdlib/itertools.pyi +376 -0
- package/bundle/_internal/mypy/typeshed/stdlib/json/__init__.pyi +93 -0
- package/bundle/_internal/mypy/typeshed/stdlib/json/decoder.pyi +50 -0
- package/bundle/_internal/mypy/typeshed/stdlib/json/encoder.pyi +40 -0
- package/bundle/_internal/mypy/typeshed/stdlib/json/scanner.pyi +7 -0
- package/bundle/_internal/mypy/typeshed/stdlib/json/tool.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/keyword.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/btm_matcher.pyi +28 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixer_base.pyi +42 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_apply.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_asserts.pyi +10 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_basestring.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_buffer.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_dict.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_except.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_exec.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_execfile.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_exitfunc.pyi +13 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_filter.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_funcattrs.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_future.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_getcwdu.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_has_key.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_idioms.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_import.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_imports.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_imports2.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_input.pyi +11 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_intern.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_isinstance.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_itertools.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_itertools_imports.pyi +7 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_long.pyi +7 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_map.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_metaclass.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_methodattrs.pyi +10 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_ne.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_next.pyi +19 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_nonzero.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_numliterals.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_operator.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_paren.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_print.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_raise.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_raw_input.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_reduce.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_reload.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_renames.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_repr.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_set_literal.pyi +7 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_standarderror.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_sys_exc.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_throw.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_tuple_params.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_types.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_unicode.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_urllib.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_ws_comma.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_xrange.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_xreadlines.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/fixes/fix_zip.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/main.pyi +42 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pgen2/__init__.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pgen2/driver.pyi +27 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pgen2/grammar.pyi +25 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pgen2/literals.pyi +7 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pgen2/parse.pyi +30 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi +53 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pgen2/token.pyi +69 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pgen2/tokenize.pyi +96 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pygram.pyi +114 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/pytree.pyi +118 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lib2to3/refactor.pyi +86 -0
- package/bundle/_internal/mypy/typeshed/stdlib/linecache.pyi +18 -0
- package/bundle/_internal/mypy/typeshed/stdlib/locale.pyi +160 -0
- package/bundle/_internal/mypy/typeshed/stdlib/logging/__init__.pyi +674 -0
- package/bundle/_internal/mypy/typeshed/stdlib/logging/config.pyi +141 -0
- package/bundle/_internal/mypy/typeshed/stdlib/logging/handlers.pyi +258 -0
- package/bundle/_internal/mypy/typeshed/stdlib/lzma.pyi +181 -0
- package/bundle/_internal/mypy/typeshed/stdlib/mailbox.pyi +307 -0
- package/bundle/_internal/mypy/typeshed/stdlib/mailcap.pyi +11 -0
- package/bundle/_internal/mypy/typeshed/stdlib/marshal.pyi +51 -0
- package/bundle/_internal/mypy/typeshed/stdlib/math/__init__.pyi +157 -0
- package/bundle/_internal/mypy/typeshed/stdlib/math/integer.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/mimetypes.pyi +56 -0
- package/bundle/_internal/mypy/typeshed/stdlib/mmap.pyi +191 -0
- package/bundle/_internal/mypy/typeshed/stdlib/modulefinder.pyi +68 -0
- package/bundle/_internal/mypy/typeshed/stdlib/msilib/__init__.pyi +177 -0
- package/bundle/_internal/mypy/typeshed/stdlib/msilib/schema.pyi +95 -0
- package/bundle/_internal/mypy/typeshed/stdlib/msilib/sequence.pyi +13 -0
- package/bundle/_internal/mypy/typeshed/stdlib/msilib/text.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/msvcrt.pyi +31 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/__init__.pyi +90 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/connection.pyi +97 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/context.pyi +220 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/dummy/__init__.pyi +89 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/dummy/connection.pyi +39 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/forkserver.pyi +78 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/heap.pyi +41 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/managers.pyi +390 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/pool.pyi +101 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/popen_fork.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/popen_forkserver.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/popen_spawn_posix.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/popen_spawn_win32.pyi +30 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/process.pyi +57 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/queues.pyi +46 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/reduction.pyi +95 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/resource_sharer.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/resource_tracker.pyi +21 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/shared_memory.pyi +43 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/sharedctypes.pyi +140 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/spawn.pyi +32 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/synchronize.pyi +63 -0
- package/bundle/_internal/mypy/typeshed/stdlib/multiprocessing/util.pyi +109 -0
- package/bundle/_internal/mypy/typeshed/stdlib/netrc.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/nis.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/nntplib.pyi +120 -0
- package/bundle/_internal/mypy/typeshed/stdlib/nt.pyi +116 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ntpath.pyi +134 -0
- package/bundle/_internal/mypy/typeshed/stdlib/nturl2path.pyi +6 -0
- package/bundle/_internal/mypy/typeshed/stdlib/numbers.pyi +220 -0
- package/bundle/_internal/mypy/typeshed/stdlib/opcode.pyi +53 -0
- package/bundle/_internal/mypy/typeshed/stdlib/operator.pyi +219 -0
- package/bundle/_internal/mypy/typeshed/stdlib/optparse.pyi +312 -0
- package/bundle/_internal/mypy/typeshed/stdlib/os/__init__.pyi +1878 -0
- package/bundle/_internal/mypy/typeshed/stdlib/os/path.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ossaudiodev.pyi +132 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pathlib/__init__.pyi +358 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pathlib/types.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pdb.pyi +275 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pickle.pyi +240 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pickletools.pyi +176 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pipes.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pkgutil.pyi +60 -0
- package/bundle/_internal/mypy/typeshed/stdlib/platform.pyi +100 -0
- package/bundle/_internal/mypy/typeshed/stdlib/plistlib.pyi +84 -0
- package/bundle/_internal/mypy/typeshed/stdlib/poplib.pyi +93 -0
- package/bundle/_internal/mypy/typeshed/stdlib/posix.pyi +427 -0
- package/bundle/_internal/mypy/typeshed/stdlib/posixpath.pyi +230 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pprint.pyi +170 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profile.pyi +31 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/__init__.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/sampling/__init__.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/sampling/collector.pyi +25 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/sampling/gecko_collector.pyi +111 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/sampling/heatmap_collector.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/sampling/jsonl_collector.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/sampling/pstats_collector.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/sampling/stack_collector.pyi +40 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/sampling/string_table.pyi +5 -0
- package/bundle/_internal/mypy/typeshed/stdlib/profiling/tracing.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pstats.pyi +96 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pty.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pwd.pyi +27 -0
- package/bundle/_internal/mypy/typeshed/stdlib/py_compile.pyi +28 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pyclbr.pyi +57 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pydoc.pyi +348 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pydoc_data/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pydoc_data/module_docs.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pydoc_data/topics.pyi +3 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pyexpat/__init__.pyi +88 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pyexpat/errors.pyi +53 -0
- package/bundle/_internal/mypy/typeshed/stdlib/pyexpat/model.pyi +13 -0
- package/bundle/_internal/mypy/typeshed/stdlib/queue.pyi +55 -0
- package/bundle/_internal/mypy/typeshed/stdlib/quopri.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/random.pyi +135 -0
- package/bundle/_internal/mypy/typeshed/stdlib/re.pyi +347 -0
- package/bundle/_internal/mypy/typeshed/stdlib/readline.pyi +39 -0
- package/bundle/_internal/mypy/typeshed/stdlib/reprlib.pyi +64 -0
- package/bundle/_internal/mypy/typeshed/stdlib/resource.pyi +102 -0
- package/bundle/_internal/mypy/typeshed/stdlib/rlcompleter.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/runpy.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sched.pyi +34 -0
- package/bundle/_internal/mypy/typeshed/stdlib/secrets.pyi +17 -0
- package/bundle/_internal/mypy/typeshed/stdlib/select.pyi +171 -0
- package/bundle/_internal/mypy/typeshed/stdlib/selectors.pyi +67 -0
- package/bundle/_internal/mypy/typeshed/stdlib/shelve.pyi +110 -0
- package/bundle/_internal/mypy/typeshed/stdlib/shlex.pyi +63 -0
- package/bundle/_internal/mypy/typeshed/stdlib/shutil.pyi +243 -0
- package/bundle/_internal/mypy/typeshed/stdlib/signal.pyi +174 -0
- package/bundle/_internal/mypy/typeshed/stdlib/site.pyi +46 -0
- package/bundle/_internal/mypy/typeshed/stdlib/smtpd.pyi +92 -0
- package/bundle/_internal/mypy/typeshed/stdlib/smtplib.pyi +223 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sndhdr.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/socket.pyi +1587 -0
- package/bundle/_internal/mypy/typeshed/stdlib/socketserver.pyi +170 -0
- package/bundle/_internal/mypy/typeshed/stdlib/spwd.pyi +45 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sqlite3/__init__.pyi +510 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi +244 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sqlite3/dump.pyi +2 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sre_compile.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sre_constants.pyi +135 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sre_parse.pyi +102 -0
- package/bundle/_internal/mypy/typeshed/stdlib/ssl.pyi +540 -0
- package/bundle/_internal/mypy/typeshed/stdlib/stat.pyi +126 -0
- package/bundle/_internal/mypy/typeshed/stdlib/statistics.pyi +161 -0
- package/bundle/_internal/mypy/typeshed/stdlib/string/__init__.pyi +81 -0
- package/bundle/_internal/mypy/typeshed/stdlib/string/templatelib.pyi +36 -0
- package/bundle/_internal/mypy/typeshed/stdlib/stringprep.pyi +29 -0
- package/bundle/_internal/mypy/typeshed/stdlib/struct.pyi +5 -0
- package/bundle/_internal/mypy/typeshed/stdlib/subprocess.pyi +1484 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sunau.pyi +82 -0
- package/bundle/_internal/mypy/typeshed/stdlib/symtable.pyi +95 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sys/__init__.pyi +538 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sys/__jit.pyi +11 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sys/_monitoring.pyi +69 -0
- package/bundle/_internal/mypy/typeshed/stdlib/sysconfig.pyi +59 -0
- package/bundle/_internal/mypy/typeshed/stdlib/syslog.pyi +58 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tabnanny.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tarfile.pyi +868 -0
- package/bundle/_internal/mypy/typeshed/stdlib/telnetlib.pyi +123 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tempfile.pyi +474 -0
- package/bundle/_internal/mypy/typeshed/stdlib/termios.pyi +303 -0
- package/bundle/_internal/mypy/typeshed/stdlib/textwrap.pyi +103 -0
- package/bundle/_internal/mypy/typeshed/stdlib/this.pyi +2 -0
- package/bundle/_internal/mypy/typeshed/stdlib/threading.pyi +221 -0
- package/bundle/_internal/mypy/typeshed/stdlib/time.pyi +117 -0
- package/bundle/_internal/mypy/typeshed/stdlib/timeit.pyi +46 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/__init__.pyi +4376 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/colorchooser.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/commondialog.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/constants.pyi +80 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/dialog.pyi +13 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/dnd.pyi +19 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/filedialog.pyi +149 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/font.pyi +123 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/messagebox.pyi +98 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/scrolledtext.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/simpledialog.pyi +58 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/tix.pyi +299 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tkinter/ttk.pyi +1434 -0
- package/bundle/_internal/mypy/typeshed/stdlib/token.pyi +166 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tokenize.pyi +201 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tomllib.pyi +27 -0
- package/bundle/_internal/mypy/typeshed/stdlib/trace.pyi +85 -0
- package/bundle/_internal/mypy/typeshed/stdlib/traceback.pyi +293 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tracemalloc.pyi +123 -0
- package/bundle/_internal/mypy/typeshed/stdlib/tty.pyi +29 -0
- package/bundle/_internal/mypy/typeshed/stdlib/turtle.pyi +856 -0
- package/bundle/_internal/mypy/typeshed/stdlib/types.pyi +744 -0
- package/bundle/_internal/mypy/typeshed/stdlib/typing.pyi +1250 -0
- package/bundle/_internal/mypy/typeshed/stdlib/typing_extensions.pyi +749 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unicodedata.pyi +94 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/__init__.pyi +63 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/_log.pyi +29 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/async_case.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/case.pyi +352 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/loader.pyi +55 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/main.pyi +74 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/mock.pyi +555 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/result.pyi +46 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/runner.pyi +93 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/signals.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/suite.pyi +23 -0
- package/bundle/_internal/mypy/typeshed/stdlib/unittest/util.pyi +39 -0
- package/bundle/_internal/mypy/typeshed/stdlib/urllib/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/urllib/error.pyi +29 -0
- package/bundle/_internal/mypy/typeshed/stdlib/urllib/parse.pyi +354 -0
- package/bundle/_internal/mypy/typeshed/stdlib/urllib/request.pyi +447 -0
- package/bundle/_internal/mypy/typeshed/stdlib/urllib/response.pyi +45 -0
- package/bundle/_internal/mypy/typeshed/stdlib/urllib/robotparser.pyi +20 -0
- package/bundle/_internal/mypy/typeshed/stdlib/uu.pyi +12 -0
- package/bundle/_internal/mypy/typeshed/stdlib/uuid.pyi +106 -0
- package/bundle/_internal/mypy/typeshed/stdlib/venv/__init__.pyi +86 -0
- package/bundle/_internal/mypy/typeshed/stdlib/warnings.pyi +146 -0
- package/bundle/_internal/mypy/typeshed/stdlib/wave.pyi +105 -0
- package/bundle/_internal/mypy/typeshed/stdlib/weakref.pyi +217 -0
- package/bundle/_internal/mypy/typeshed/stdlib/webbrowser.pyi +93 -0
- package/bundle/_internal/mypy/typeshed/stdlib/winreg.pyi +137 -0
- package/bundle/_internal/mypy/typeshed/stdlib/winsound.pyi +40 -0
- package/bundle/_internal/mypy/typeshed/stdlib/wsgiref/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/wsgiref/handlers.pyi +91 -0
- package/bundle/_internal/mypy/typeshed/stdlib/wsgiref/headers.pyi +27 -0
- package/bundle/_internal/mypy/typeshed/stdlib/wsgiref/simple_server.pyi +37 -0
- package/bundle/_internal/mypy/typeshed/stdlib/wsgiref/types.pyi +31 -0
- package/bundle/_internal/mypy/typeshed/stdlib/wsgiref/util.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/wsgiref/validate.pyi +50 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xdrlib.pyi +57 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/__init__.pyi +9 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/dom/NodeFilter.pyi +22 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/dom/__init__.pyi +101 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/dom/domreg.pyi +8 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/dom/expatbuilder.pyi +126 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/dom/minicompat.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/dom/minidom.pyi +693 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/dom/pulldom.pyi +109 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/dom/xmlbuilder.pyi +82 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/etree/ElementInclude.pyi +28 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/etree/ElementPath.pyi +42 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi +402 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/etree/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/etree/cElementTree.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/parsers/__init__.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/parsers/expat/__init__.pyi +7 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/parsers/expat/errors.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/parsers/expat/model.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/sax/__init__.pyi +42 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/sax/_exceptions.pyi +19 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/sax/expatreader.pyi +72 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/sax/handler.pyi +85 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/sax/saxutils.pyi +69 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/sax/xmlreader.pyi +94 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xml/utils.pyi +2 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xmlrpc/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xmlrpc/client.pyi +300 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xmlrpc/server.pyi +149 -0
- package/bundle/_internal/mypy/typeshed/stdlib/xxlimited.pyi +15 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zipapp.pyi +19 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zipfile/__init__.pyi +411 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zipfile/_path/__init__.pyi +87 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zipfile/_path/glob.pyi +26 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zipimport.pyi +44 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zlib.pyi +81 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zoneinfo/__init__.pyi +36 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zoneinfo/_common.pyi +14 -0
- package/bundle/_internal/mypy/typeshed/stdlib/zoneinfo/_tzpath.pyi +13 -0
- package/bundle/_internal/mypy/typeshed/stubs/librt/librt/__init__.pyi +0 -0
- package/bundle/_internal/mypy/typeshed/stubs/librt/librt/base64.pyi +4 -0
- package/bundle/_internal/mypy/typeshed/stubs/librt/librt/internal.pyi +22 -0
- package/bundle/_internal/mypy/typeshed/stubs/librt/librt/random.pyi +22 -0
- package/bundle/_internal/mypy/typeshed/stubs/librt/librt/strings.pyi +61 -0
- package/bundle/_internal/mypy/typeshed/stubs/librt/librt/threading.pyi +16 -0
- package/bundle/_internal/mypy/typeshed/stubs/librt/librt/time.pyi +1 -0
- package/bundle/_internal/mypy/typeshed/stubs/librt/librt/vecs.pyi +24 -0
- package/bundle/_internal/mypy/typeshed/stubs/mypy-extensions/mypy_extensions.pyi +226 -0
- package/bundle/_internal/mypy/typestate.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/typestate.py +334 -0
- package/bundle/_internal/mypy/typetraverser.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/typetraverser.py +166 -0
- package/bundle/_internal/mypy/typevars.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/typevars.py +84 -0
- package/bundle/_internal/mypy/typevartuples.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/typevartuples.py +36 -0
- package/bundle/_internal/mypy/util.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/util.py +1055 -0
- package/bundle/_internal/mypy/version.py +1 -0
- package/bundle/_internal/mypy/visitor.cpython-312-darwin.so +0 -0
- package/bundle/_internal/mypy/visitor.py +639 -0
- package/bundle/_internal/mypy/xml/mypy-html.css +104 -0
- package/bundle/_internal/mypy/xml/mypy-html.xslt +81 -0
- package/bundle/_internal/mypy/xml/mypy-txt.xslt +100 -0
- package/bundle/_internal/mypy/xml/mypy.xsd +50 -0
- package/bundle/_internal/mypy-2.4.1.dist-info/INSTALLER +1 -0
- package/bundle/_internal/mypy-2.4.1.dist-info/METADATA +56 -0
- package/bundle/_internal/mypy-2.4.1.dist-info/RECORD +1814 -0
- package/bundle/_internal/mypy-2.4.1.dist-info/WHEEL +6 -0
- package/bundle/_internal/mypy-2.4.1.dist-info/entry_points.txt +6 -0
- package/bundle/_internal/mypy-2.4.1.dist-info/licenses/LICENSE +264 -0
- package/bundle/_internal/mypy-2.4.1.dist-info/licenses/mypy/typeshed/LICENSE +237 -0
- package/bundle/_internal/mypy-2.4.1.dist-info/top_level.txt +3 -0
- package/bundle/_internal/mypyc/__init__.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_asyncio.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_bisect.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_blake2.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_bz2.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_codecs_cn.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_codecs_hk.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_codecs_iso2022.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_codecs_jp.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_codecs_kr.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_codecs_tw.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_contextvars.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_csv.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_ctypes.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_curses.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_datetime.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_decimal.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_elementtree.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_hashlib.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_heapq.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_json.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_lzma.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_md5.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_multibytecodec.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_multiprocessing.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_opcode.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_pickle.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_posixshmem.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_posixsubprocess.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_queue.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_random.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_scproxy.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_sha1.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_sha2.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_sha3.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_socket.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_sqlite3.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_ssl.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_statistics.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_struct.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/_uuid.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/array.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/binascii.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/fcntl.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/grp.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/math.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/mmap.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/pyexpat.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/readline.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/resource.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/select.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/syslog.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/termios.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/unicodedata.cpython-312-darwin.so +0 -0
- package/bundle/_internal/python3.12/lib-dynload/zlib.cpython-312-darwin.so +0 -0
- package/bundle/_internal/radon/__init__.py +21 -0
- package/bundle/_internal/radon/__main__.py +4 -0
- package/bundle/_internal/radon/cli/__init__.py +433 -0
- package/bundle/_internal/radon/cli/colors.py +49 -0
- package/bundle/_internal/radon/cli/harvest.py +449 -0
- package/bundle/_internal/radon/cli/tools.py +597 -0
- package/bundle/_internal/radon/complexity.py +108 -0
- package/bundle/_internal/radon/contrib/__init__.py +0 -0
- package/bundle/_internal/radon/contrib/flake8.py +72 -0
- package/bundle/_internal/radon/metrics.py +157 -0
- package/bundle/_internal/radon/raw.py +245 -0
- package/bundle/_internal/radon/tests/__init__.py +0 -0
- package/bundle/_internal/radon/tests/conftest.py +31 -0
- package/bundle/_internal/radon/tests/data/__init__.py +5 -0
- package/bundle/_internal/radon/tests/data/no_encoding.py +2 -0
- package/bundle/_internal/radon/tests/data/py3unicode.py +5 -0
- package/bundle/_internal/radon/tests/run.py +14 -0
- package/bundle/_internal/radon/tests/test_cli.py +282 -0
- package/bundle/_internal/radon/tests/test_cli_colors.py +22 -0
- package/bundle/_internal/radon/tests/test_cli_harvest.py +392 -0
- package/bundle/_internal/radon/tests/test_cli_tools.py +616 -0
- package/bundle/_internal/radon/tests/test_complexity_utils.py +118 -0
- package/bundle/_internal/radon/tests/test_complexity_visitor.py +754 -0
- package/bundle/_internal/radon/tests/test_halstead.py +113 -0
- package/bundle/_internal/radon/tests/test_ipynb.py +141 -0
- package/bundle/_internal/radon/tests/test_other_metrics.py +169 -0
- package/bundle/_internal/radon/tests/test_raw.py +467 -0
- package/bundle/_internal/radon/visitors.py +460 -0
- package/bundle/_internal/radon-6.0.1.dist-info/INSTALLER +1 -0
- package/bundle/_internal/radon-6.0.1.dist-info/LICENSE +22 -0
- package/bundle/_internal/radon-6.0.1.dist-info/METADATA +263 -0
- package/bundle/_internal/radon-6.0.1.dist-info/RECORD +64 -0
- package/bundle/_internal/radon-6.0.1.dist-info/WHEEL +6 -0
- package/bundle/_internal/radon-6.0.1.dist-info/entry_points.txt +8 -0
- package/bundle/_internal/radon-6.0.1.dist-info/top_level.txt +1 -0
- package/bundle/_internal/setuptools/_vendor/jaraco/text/Lorem ipsum.txt +2 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/INSTALLER +1 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/METADATA +56 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/RECORD +84 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/WHEEL +5 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/entry_points.txt +10 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/licenses/AUTHORS +76 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/licenses/LICENSE +202 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/pbr.json +1 -0
- package/bundle/_internal/stevedore-5.10.0.dist-info/top_level.txt +1 -0
- package/bundle/_internal/tqdm-4.70.1.dist-info/INSTALLER +1 -0
- package/bundle/_internal/tqdm-4.70.1.dist-info/METADATA +1600 -0
- package/bundle/_internal/tqdm-4.70.1.dist-info/RECORD +72 -0
- package/bundle/_internal/tqdm-4.70.1.dist-info/WHEEL +5 -0
- package/bundle/_internal/tqdm-4.70.1.dist-info/entry_points.txt +2 -0
- package/bundle/_internal/tqdm-4.70.1.dist-info/licenses/LICENCE +49 -0
- package/bundle/_internal/tqdm-4.70.1.dist-info/top_level.txt +1 -0
- package/bundle/_internal/yaml/_yaml.cpython-312-darwin.so +0 -0
- package/bundle/gnost +0 -0
- package/package.json +10 -7
|
@@ -0,0 +1,4639 @@
|
|
|
1
|
+
"""Classes for representing mypy types."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from abc import abstractmethod
|
|
7
|
+
from collections.abc import Iterable, Sequence
|
|
8
|
+
from typing import (
|
|
9
|
+
Any,
|
|
10
|
+
ClassVar,
|
|
11
|
+
Final,
|
|
12
|
+
NamedTuple,
|
|
13
|
+
NewType,
|
|
14
|
+
TypeAlias as _TypeAlias,
|
|
15
|
+
TypeGuard,
|
|
16
|
+
TypeVar,
|
|
17
|
+
cast,
|
|
18
|
+
overload,
|
|
19
|
+
)
|
|
20
|
+
from typing_extensions import Self
|
|
21
|
+
|
|
22
|
+
from librt.internal import (
|
|
23
|
+
read_int as read_int_bare,
|
|
24
|
+
read_str as read_str_bare,
|
|
25
|
+
write_int as write_int_bare,
|
|
26
|
+
write_str as write_str_bare,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
import mypy.nodes
|
|
30
|
+
from mypy.bogus_type import Bogus
|
|
31
|
+
from mypy.cache import (
|
|
32
|
+
DICT_STR_GEN,
|
|
33
|
+
END_TAG,
|
|
34
|
+
EXTRA_ATTRS,
|
|
35
|
+
LIST_GEN,
|
|
36
|
+
LITERAL_NONE,
|
|
37
|
+
ReadBuffer,
|
|
38
|
+
Tag,
|
|
39
|
+
WriteBuffer,
|
|
40
|
+
read_bool,
|
|
41
|
+
read_flags,
|
|
42
|
+
read_int,
|
|
43
|
+
read_int_list,
|
|
44
|
+
read_literal,
|
|
45
|
+
read_str,
|
|
46
|
+
read_str_list,
|
|
47
|
+
read_str_opt,
|
|
48
|
+
read_str_opt_list,
|
|
49
|
+
read_tag,
|
|
50
|
+
write_bool,
|
|
51
|
+
write_flags,
|
|
52
|
+
write_int,
|
|
53
|
+
write_int_list,
|
|
54
|
+
write_literal,
|
|
55
|
+
write_str,
|
|
56
|
+
write_str_list,
|
|
57
|
+
write_str_opt,
|
|
58
|
+
write_str_opt_list,
|
|
59
|
+
write_tag,
|
|
60
|
+
)
|
|
61
|
+
from mypy.nodes import ARG_KINDS, ARG_POS, ARG_STAR, ARG_STAR2, INVARIANT, ArgKind, SymbolNode
|
|
62
|
+
from mypy.options import Options
|
|
63
|
+
from mypy.state import state
|
|
64
|
+
from mypy.util import IdMapper
|
|
65
|
+
|
|
66
|
+
T = TypeVar("T")
|
|
67
|
+
|
|
68
|
+
JsonDict: _TypeAlias = dict[str, Any]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# The set of all valid expressions that can currently be contained
|
|
72
|
+
# inside of a Literal[...].
|
|
73
|
+
#
|
|
74
|
+
# Literals can contain bytes and enum-values: we special-case both of these
|
|
75
|
+
# and store the value as a string. We rely on the fallback type that's also
|
|
76
|
+
# stored with the Literal to determine how a string is being used.
|
|
77
|
+
#
|
|
78
|
+
# TODO: confirm that we're happy with representing enums (and the
|
|
79
|
+
# other types) in the manner described above.
|
|
80
|
+
#
|
|
81
|
+
# Note: if we change the set of types included below, we must also
|
|
82
|
+
# make sure to audit the following methods:
|
|
83
|
+
#
|
|
84
|
+
# 1. types.LiteralType's serialize and deserialize methods: this method
|
|
85
|
+
# needs to make sure it can convert the below types into JSON and back.
|
|
86
|
+
#
|
|
87
|
+
# 2. types.LiteralType's 'value_repr` method: this method is ultimately used
|
|
88
|
+
# by TypeStrVisitor's visit_literal_type to generate a reasonable
|
|
89
|
+
# repr-able output.
|
|
90
|
+
#
|
|
91
|
+
# 3. server.astdiff.SnapshotTypeVisitor's visit_literal_type_method: this
|
|
92
|
+
# method assumes that the following types supports equality checks and
|
|
93
|
+
# hashability.
|
|
94
|
+
#
|
|
95
|
+
# Note: Although "Literal[None]" is a valid type, we internally always convert
|
|
96
|
+
# such a type directly into "None". So, "None" is not a valid parameter of
|
|
97
|
+
# LiteralType and is omitted from this list.
|
|
98
|
+
#
|
|
99
|
+
# Note: Float values are only used internally. They are not accepted within
|
|
100
|
+
# Literal[...].
|
|
101
|
+
class SentinelValue(NamedTuple):
|
|
102
|
+
fullname: str
|
|
103
|
+
name: str
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
LiteralValue: _TypeAlias = int | str | bool | float | SentinelValue
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
TUPLE_NAMES: Final = ("builtins.tuple", "typing.Tuple")
|
|
110
|
+
TYPE_NAMES: Final = ("builtins.type", "typing.Type")
|
|
111
|
+
|
|
112
|
+
TYPE_VAR_LIKE_NAMES: Final = (
|
|
113
|
+
"typing.TypeVar",
|
|
114
|
+
"typing_extensions.TypeVar",
|
|
115
|
+
"typing.ParamSpec",
|
|
116
|
+
"typing_extensions.ParamSpec",
|
|
117
|
+
"typing.TypeVarTuple",
|
|
118
|
+
"typing_extensions.TypeVarTuple",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
SENTINEL_TYPE_NAMES: Final = (
|
|
122
|
+
"builtins.sentinel",
|
|
123
|
+
"typing_extensions.sentinel",
|
|
124
|
+
"typing_extensions.Sentinel",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
TYPED_NAMEDTUPLE_NAMES: Final = ("typing.NamedTuple", "typing_extensions.NamedTuple")
|
|
128
|
+
|
|
129
|
+
# Supported names of TypedDict type constructors.
|
|
130
|
+
TPDICT_NAMES: Final = (
|
|
131
|
+
"typing.TypedDict",
|
|
132
|
+
"typing_extensions.TypedDict",
|
|
133
|
+
"mypy_extensions.TypedDict",
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Supported fallback instance type names for TypedDict types.
|
|
137
|
+
TPDICT_FB_NAMES: Final = (
|
|
138
|
+
"typing._TypedDict",
|
|
139
|
+
"typing_extensions._TypedDict",
|
|
140
|
+
"mypy_extensions._TypedDict",
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
# Supported names of Protocol base class.
|
|
144
|
+
PROTOCOL_NAMES: Final = ("typing.Protocol", "typing_extensions.Protocol")
|
|
145
|
+
|
|
146
|
+
# Supported TypeAlias names.
|
|
147
|
+
TYPE_ALIAS_NAMES: Final = ("typing.TypeAlias", "typing_extensions.TypeAlias")
|
|
148
|
+
|
|
149
|
+
# Supported Final type names.
|
|
150
|
+
FINAL_TYPE_NAMES: Final = ("typing.Final", "typing_extensions.Final")
|
|
151
|
+
|
|
152
|
+
# Supported @final decorator names.
|
|
153
|
+
FINAL_DECORATOR_NAMES: Final = ("typing.final", "typing_extensions.final")
|
|
154
|
+
|
|
155
|
+
# Supported @type_check_only names.
|
|
156
|
+
TYPE_CHECK_ONLY_NAMES: Final = ("typing.type_check_only", "typing_extensions.type_check_only")
|
|
157
|
+
|
|
158
|
+
# Supported Literal type names.
|
|
159
|
+
LITERAL_TYPE_NAMES: Final = ("typing.Literal", "typing_extensions.Literal")
|
|
160
|
+
|
|
161
|
+
# Supported Annotated type names.
|
|
162
|
+
ANNOTATED_TYPE_NAMES: Final = ("typing.Annotated", "typing_extensions.Annotated")
|
|
163
|
+
|
|
164
|
+
# Supported Concatenate type names.
|
|
165
|
+
CONCATENATE_TYPE_NAMES: Final = ("typing.Concatenate", "typing_extensions.Concatenate")
|
|
166
|
+
|
|
167
|
+
# Supported Unpack type names.
|
|
168
|
+
UNPACK_TYPE_NAMES: Final = ("typing.Unpack", "typing_extensions.Unpack")
|
|
169
|
+
|
|
170
|
+
# Supported @deprecated decorator names
|
|
171
|
+
DEPRECATED_TYPE_NAMES: Final = ("warnings.deprecated", "typing_extensions.deprecated")
|
|
172
|
+
|
|
173
|
+
# Supported @disjoint_base decorator names
|
|
174
|
+
DISJOINT_BASE_DECORATOR_NAMES: Final = ("typing.disjoint_base", "typing_extensions.disjoint_base")
|
|
175
|
+
|
|
176
|
+
# We use this constant in various places when checking `tuple` subtyping:
|
|
177
|
+
TUPLE_LIKE_INSTANCE_NAMES: Final = (
|
|
178
|
+
"builtins.tuple",
|
|
179
|
+
"typing.Iterable",
|
|
180
|
+
"typing.Container",
|
|
181
|
+
"typing.Sequence",
|
|
182
|
+
"typing.Reversible",
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
IMPORTED_REVEAL_TYPE_NAMES: Final = ("typing.reveal_type", "typing_extensions.reveal_type")
|
|
186
|
+
REVEAL_TYPE_NAMES: Final = ("builtins.reveal_type", *IMPORTED_REVEAL_TYPE_NAMES)
|
|
187
|
+
|
|
188
|
+
ASSERT_TYPE_NAMES: Final = ("typing.assert_type", "typing_extensions.assert_type")
|
|
189
|
+
|
|
190
|
+
OVERLOAD_NAMES: Final = ("typing.overload", "typing_extensions.overload")
|
|
191
|
+
|
|
192
|
+
NEVER_NAMES: Final = (
|
|
193
|
+
"typing.NoReturn",
|
|
194
|
+
"typing_extensions.NoReturn",
|
|
195
|
+
"mypy_extensions.NoReturn",
|
|
196
|
+
"typing.Never",
|
|
197
|
+
"typing_extensions.Never",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
# Mypyc fixed-width native int types (compatible with builtins.int)
|
|
201
|
+
MYPYC_NATIVE_INT_NAMES: Final = (
|
|
202
|
+
"mypy_extensions.i64",
|
|
203
|
+
"mypy_extensions.i32",
|
|
204
|
+
"mypy_extensions.i16",
|
|
205
|
+
"mypy_extensions.u8",
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
DATACLASS_TRANSFORM_NAMES: Final = (
|
|
209
|
+
"typing.dataclass_transform",
|
|
210
|
+
"typing_extensions.dataclass_transform",
|
|
211
|
+
)
|
|
212
|
+
# Supported @override decorator names.
|
|
213
|
+
OVERRIDE_DECORATOR_NAMES: Final = ("typing.override", "typing_extensions.override")
|
|
214
|
+
|
|
215
|
+
ELLIPSIS_TYPE_NAMES: Final = ("builtins.ellipsis", "types.EllipsisType")
|
|
216
|
+
|
|
217
|
+
NOT_IMPLEMENTED_TYPE_NAMES: Final = ("builtins._NotImplementedType", "types.NotImplementedType")
|
|
218
|
+
|
|
219
|
+
# A placeholder used for Bogus[...] parameters
|
|
220
|
+
_dummy: Final[Any] = object()
|
|
221
|
+
|
|
222
|
+
# A placeholder for int parameters
|
|
223
|
+
_dummy_int: Final = -999999
|
|
224
|
+
|
|
225
|
+
# Maximum protocol subtyping assumptions depth. We need this to avoid infinite
|
|
226
|
+
# recursion for protocols that are genuinely undecidable, see testDivergingProtocol.
|
|
227
|
+
# We set a conservative cut-off, since some numerical libraries currently
|
|
228
|
+
# use ~10 assumptions, and we want to avoid false negatives with them.
|
|
229
|
+
MAX_PROTOCOL_DEPTH: Final = 20
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
class TypeOfAny:
|
|
233
|
+
"""
|
|
234
|
+
This class describes different types of Any. Each 'Any' can be of only one type at a time.
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
__slots__ = ()
|
|
238
|
+
|
|
239
|
+
# Was this Any type inferred without a type annotation?
|
|
240
|
+
unannotated: Final = 1
|
|
241
|
+
# Does this Any come from an explicit type annotation?
|
|
242
|
+
explicit: Final = 2
|
|
243
|
+
# Does this come from an unfollowed import? See --disallow-any-unimported option
|
|
244
|
+
from_unimported_type: Final = 3
|
|
245
|
+
# Does this Any type come from omitted generics?
|
|
246
|
+
from_omitted_generics: Final = 4
|
|
247
|
+
# Does this Any come from an error?
|
|
248
|
+
from_error: Final = 5
|
|
249
|
+
# Is this a type that can't be represented in mypy's type system? For instance, type of
|
|
250
|
+
# call to NewType(...). Even though these types aren't real Anys, we treat them as such.
|
|
251
|
+
# Also used for variables named '_'.
|
|
252
|
+
special_form: Final = 6
|
|
253
|
+
# Does this Any come from interaction with another Any?
|
|
254
|
+
from_another_any: Final = 7
|
|
255
|
+
# Does this Any come from an implementation limitation/bug?
|
|
256
|
+
implementation_artifact: Final = 8
|
|
257
|
+
# Does this Any come from use in the suggestion engine? This is
|
|
258
|
+
# used to ignore Anys inserted by the suggestion engine when
|
|
259
|
+
# generating constraints.
|
|
260
|
+
suggestion_engine: Final = 9
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def deserialize_type(data: JsonDict | str) -> Type:
|
|
264
|
+
if isinstance(data, str):
|
|
265
|
+
return Instance.deserialize(data)
|
|
266
|
+
classname = data[".class"]
|
|
267
|
+
method = deserialize_map.get(classname)
|
|
268
|
+
if method is not None:
|
|
269
|
+
return method(data)
|
|
270
|
+
raise NotImplementedError(f"unexpected .class {classname}")
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
class Type(mypy.nodes.Context):
|
|
274
|
+
"""Abstract base class for all types."""
|
|
275
|
+
|
|
276
|
+
__slots__ = ("_can_be_true", "_can_be_false")
|
|
277
|
+
# 'can_be_true' and 'can_be_false' mean whether the value of the
|
|
278
|
+
# expression can be true or false in a boolean context. They are useful
|
|
279
|
+
# when inferring the type of logic expressions like `x and y`.
|
|
280
|
+
#
|
|
281
|
+
# For example:
|
|
282
|
+
# * the literal `False` can't be true while `True` can.
|
|
283
|
+
# * a value with type `bool` can be true or false.
|
|
284
|
+
# * `None` can't be true
|
|
285
|
+
# * ...
|
|
286
|
+
|
|
287
|
+
def __init__(self, line: int = -1, column: int = -1) -> None:
|
|
288
|
+
super().__init__(line, column)
|
|
289
|
+
# Value of these can be -1 (use the default, lazy init), 0 (false) or 1 (true)
|
|
290
|
+
self._can_be_true = -1
|
|
291
|
+
self._can_be_false = -1
|
|
292
|
+
|
|
293
|
+
@property
|
|
294
|
+
def can_be_true(self) -> bool:
|
|
295
|
+
if self._can_be_true == -1: # Lazy init helps mypyc
|
|
296
|
+
self._can_be_true = self.can_be_true_default()
|
|
297
|
+
return bool(self._can_be_true)
|
|
298
|
+
|
|
299
|
+
@can_be_true.setter
|
|
300
|
+
def can_be_true(self, v: bool) -> None:
|
|
301
|
+
self._can_be_true = v
|
|
302
|
+
|
|
303
|
+
@property
|
|
304
|
+
def can_be_false(self) -> bool:
|
|
305
|
+
if self._can_be_false == -1: # Lazy init helps mypyc
|
|
306
|
+
self._can_be_false = self.can_be_false_default()
|
|
307
|
+
return bool(self._can_be_false)
|
|
308
|
+
|
|
309
|
+
@can_be_false.setter
|
|
310
|
+
def can_be_false(self, v: bool) -> None:
|
|
311
|
+
self._can_be_false = v
|
|
312
|
+
|
|
313
|
+
def can_be_true_default(self) -> bool:
|
|
314
|
+
return True
|
|
315
|
+
|
|
316
|
+
def can_be_false_default(self) -> bool:
|
|
317
|
+
return True
|
|
318
|
+
|
|
319
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
320
|
+
raise RuntimeError("Not implemented", type(self))
|
|
321
|
+
|
|
322
|
+
def __repr__(self) -> str:
|
|
323
|
+
return self.accept(TypeStrVisitor(options=Options()))
|
|
324
|
+
|
|
325
|
+
def str_with_options(self, options: Options) -> str:
|
|
326
|
+
return self.accept(TypeStrVisitor(options=options))
|
|
327
|
+
|
|
328
|
+
def serialize(self) -> JsonDict | str:
|
|
329
|
+
raise NotImplementedError(f"Cannot serialize {self.__class__.__name__} instance")
|
|
330
|
+
|
|
331
|
+
@classmethod
|
|
332
|
+
def deserialize(cls, data: JsonDict) -> Type:
|
|
333
|
+
raise NotImplementedError(f"Cannot deserialize {cls.__name__} instance")
|
|
334
|
+
|
|
335
|
+
def write(self, data: WriteBuffer) -> None:
|
|
336
|
+
raise NotImplementedError(f"Cannot serialize {self.__class__.__name__} instance")
|
|
337
|
+
|
|
338
|
+
@classmethod
|
|
339
|
+
def read(cls, data: ReadBuffer) -> Type:
|
|
340
|
+
raise NotImplementedError(f"Cannot deserialize {cls.__name__} instance")
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
class TypeAliasType(Type):
|
|
344
|
+
"""A type alias to another type.
|
|
345
|
+
|
|
346
|
+
To support recursive type aliases we don't immediately expand a type alias
|
|
347
|
+
during semantic analysis, but create an instance of this type that records the target alias
|
|
348
|
+
definition node (mypy.nodes.TypeAlias) and type arguments (for generic aliases).
|
|
349
|
+
|
|
350
|
+
This is very similar to how TypeInfo vs Instance interact, where a recursive class-based
|
|
351
|
+
structure like
|
|
352
|
+
class Node:
|
|
353
|
+
value: int
|
|
354
|
+
children: List[Node]
|
|
355
|
+
can be represented in a tree-like manner.
|
|
356
|
+
"""
|
|
357
|
+
|
|
358
|
+
__slots__ = ("alias", "args", "type_ref")
|
|
359
|
+
|
|
360
|
+
def __init__(
|
|
361
|
+
self,
|
|
362
|
+
alias: mypy.nodes.TypeAlias | None,
|
|
363
|
+
args: list[Type],
|
|
364
|
+
line: int = -1,
|
|
365
|
+
column: int = -1,
|
|
366
|
+
) -> None:
|
|
367
|
+
super().__init__(line, column)
|
|
368
|
+
self.alias = alias
|
|
369
|
+
self.args = args
|
|
370
|
+
self.type_ref: str | None = None
|
|
371
|
+
|
|
372
|
+
def _expand_once(self) -> Type:
|
|
373
|
+
"""Expand to the target type exactly once.
|
|
374
|
+
|
|
375
|
+
This doesn't do full expansion, i.e. the result can contain another
|
|
376
|
+
(or even this same) type alias. Use this internal helper only when really needed,
|
|
377
|
+
its public wrapper mypy.types.get_proper_type() is preferred.
|
|
378
|
+
"""
|
|
379
|
+
assert self.alias is not None
|
|
380
|
+
if self.alias.no_args:
|
|
381
|
+
# We know that no_args=True aliases like L = List must have an instance
|
|
382
|
+
# as their target.
|
|
383
|
+
assert isinstance(self.alias.target, Instance) # type: ignore[misc]
|
|
384
|
+
return self.alias.target.copy_modified(args=self.args)
|
|
385
|
+
|
|
386
|
+
# TODO: this logic duplicates the one in expand_type_by_instance().
|
|
387
|
+
if self.alias.tvar_tuple_index is None:
|
|
388
|
+
mapping: dict[TypeVarId, Type] = {
|
|
389
|
+
v.id: s for (v, s) in zip(self.alias.alias_tvars, self.args)
|
|
390
|
+
}
|
|
391
|
+
else:
|
|
392
|
+
prefix = self.alias.tvar_tuple_index
|
|
393
|
+
suffix = len(self.alias.alias_tvars) - self.alias.tvar_tuple_index - 1
|
|
394
|
+
start, middle, end = split_with_prefix_and_suffix(tuple(self.args), prefix, suffix)
|
|
395
|
+
tvar = self.alias.alias_tvars[prefix]
|
|
396
|
+
assert isinstance(tvar, TypeVarTupleType)
|
|
397
|
+
mapping = {tvar.id: TupleType(list(middle), tvar.tuple_fallback)}
|
|
398
|
+
for tvar, sub in zip(
|
|
399
|
+
self.alias.alias_tvars[:prefix] + self.alias.alias_tvars[prefix + 1 :], start + end
|
|
400
|
+
):
|
|
401
|
+
mapping[tvar.id] = sub
|
|
402
|
+
|
|
403
|
+
return self.alias.target.accept(InstantiateAliasVisitor(mapping))
|
|
404
|
+
|
|
405
|
+
@property
|
|
406
|
+
def is_recursive(self) -> bool:
|
|
407
|
+
"""Whether this type alias is recursive.
|
|
408
|
+
|
|
409
|
+
Note this doesn't check generic alias arguments, but only if this alias
|
|
410
|
+
*definition* is recursive. The property value thus can be cached on the
|
|
411
|
+
underlying TypeAlias node. If you want to include all nested types, use
|
|
412
|
+
has_recursive_types() function.
|
|
413
|
+
"""
|
|
414
|
+
assert self.alias is not None, "Unfixed type alias"
|
|
415
|
+
is_recursive = self.alias._is_recursive
|
|
416
|
+
if is_recursive is None:
|
|
417
|
+
is_recursive = self.alias in self.alias.target.accept(CollectAliasesVisitor())
|
|
418
|
+
# We cache the value on the underlying TypeAlias node as an optimization,
|
|
419
|
+
# since the value is the same for all instances of the same alias.
|
|
420
|
+
self.alias._is_recursive = is_recursive
|
|
421
|
+
return is_recursive
|
|
422
|
+
|
|
423
|
+
def can_be_true_default(self) -> bool:
|
|
424
|
+
if self.alias is not None:
|
|
425
|
+
return self.alias.target.can_be_true
|
|
426
|
+
return super().can_be_true_default()
|
|
427
|
+
|
|
428
|
+
def can_be_false_default(self) -> bool:
|
|
429
|
+
if self.alias is not None:
|
|
430
|
+
return self.alias.target.can_be_false
|
|
431
|
+
return super().can_be_false_default()
|
|
432
|
+
|
|
433
|
+
def copy_modified(self, *, args: list[Type] | None = None) -> TypeAliasType:
|
|
434
|
+
return TypeAliasType(
|
|
435
|
+
self.alias, args if args is not None else self.args.copy(), self.line, self.column
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
439
|
+
return visitor.visit_type_alias_type(self)
|
|
440
|
+
|
|
441
|
+
def __hash__(self) -> int:
|
|
442
|
+
return hash((self.alias, tuple(self.args)))
|
|
443
|
+
|
|
444
|
+
def __eq__(self, other: object) -> bool:
|
|
445
|
+
# Note: never use this to determine subtype relationships, use is_subtype().
|
|
446
|
+
if not isinstance(other, TypeAliasType):
|
|
447
|
+
return NotImplemented
|
|
448
|
+
return self.alias == other.alias and self.args == other.args
|
|
449
|
+
|
|
450
|
+
def serialize(self) -> JsonDict:
|
|
451
|
+
assert self.alias is not None
|
|
452
|
+
data: JsonDict = {
|
|
453
|
+
".class": "TypeAliasType",
|
|
454
|
+
"type_ref": self.alias.fullname,
|
|
455
|
+
"args": [arg.serialize() for arg in self.args],
|
|
456
|
+
}
|
|
457
|
+
return data
|
|
458
|
+
|
|
459
|
+
@classmethod
|
|
460
|
+
def deserialize(cls, data: JsonDict) -> TypeAliasType:
|
|
461
|
+
assert data[".class"] == "TypeAliasType"
|
|
462
|
+
args: list[Type] = []
|
|
463
|
+
if "args" in data:
|
|
464
|
+
args_list = data["args"]
|
|
465
|
+
assert isinstance(args_list, list)
|
|
466
|
+
args = [deserialize_type(arg) for arg in args_list]
|
|
467
|
+
alias = TypeAliasType(None, args)
|
|
468
|
+
alias.type_ref = data["type_ref"]
|
|
469
|
+
return alias
|
|
470
|
+
|
|
471
|
+
def write(self, data: WriteBuffer) -> None:
|
|
472
|
+
write_tag(data, TYPE_ALIAS_TYPE)
|
|
473
|
+
write_type_list(data, self.args)
|
|
474
|
+
assert self.alias is not None
|
|
475
|
+
write_str(data, self.alias.fullname)
|
|
476
|
+
write_tag(data, END_TAG)
|
|
477
|
+
|
|
478
|
+
@classmethod
|
|
479
|
+
def read(cls, data: ReadBuffer) -> TypeAliasType:
|
|
480
|
+
alias = TypeAliasType(None, read_type_list(data))
|
|
481
|
+
alias.type_ref = read_str(data)
|
|
482
|
+
assert read_tag(data) == END_TAG
|
|
483
|
+
return alias
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
class TypeGuardedType(Type):
|
|
487
|
+
"""Only used by find_isinstance_check() etc."""
|
|
488
|
+
|
|
489
|
+
__slots__ = ("type_guard",)
|
|
490
|
+
|
|
491
|
+
def __init__(self, type_guard: Type) -> None:
|
|
492
|
+
super().__init__(line=type_guard.line, column=type_guard.column)
|
|
493
|
+
self.type_guard = type_guard
|
|
494
|
+
|
|
495
|
+
def __repr__(self) -> str:
|
|
496
|
+
return f"TypeGuard({self.type_guard})"
|
|
497
|
+
|
|
498
|
+
# This may hide some real bugs, but it is convenient for various "synthetic"
|
|
499
|
+
# visitors, similar to RequiredType and ReadOnlyType below.
|
|
500
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
501
|
+
return self.type_guard.accept(visitor)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
class RequiredType(Type):
|
|
505
|
+
"""Required[T] or NotRequired[T]. Only usable at top-level of a TypedDict definition."""
|
|
506
|
+
|
|
507
|
+
def __init__(self, item: Type, *, required: bool) -> None:
|
|
508
|
+
super().__init__(line=item.line, column=item.column)
|
|
509
|
+
self.item = item
|
|
510
|
+
self.required = required
|
|
511
|
+
|
|
512
|
+
def __repr__(self) -> str:
|
|
513
|
+
if self.required:
|
|
514
|
+
return f"Required[{self.item}]"
|
|
515
|
+
else:
|
|
516
|
+
return f"NotRequired[{self.item}]"
|
|
517
|
+
|
|
518
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
519
|
+
return self.item.accept(visitor)
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
class ReadOnlyType(Type):
|
|
523
|
+
"""ReadOnly[T] Only usable at top-level of a TypedDict definition."""
|
|
524
|
+
|
|
525
|
+
def __init__(self, item: Type) -> None:
|
|
526
|
+
super().__init__(line=item.line, column=item.column)
|
|
527
|
+
self.item = item
|
|
528
|
+
|
|
529
|
+
def __repr__(self) -> str:
|
|
530
|
+
return f"ReadOnly[{self.item}]"
|
|
531
|
+
|
|
532
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
533
|
+
return self.item.accept(visitor)
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
class ProperType(Type):
|
|
537
|
+
"""Not a type alias.
|
|
538
|
+
|
|
539
|
+
Every type except TypeAliasType must inherit from this type.
|
|
540
|
+
"""
|
|
541
|
+
|
|
542
|
+
__slots__ = ()
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
class TypeVarId:
|
|
546
|
+
# A type variable is uniquely identified by its raw id and meta level.
|
|
547
|
+
|
|
548
|
+
# For plain variables (type parameters of generic classes and
|
|
549
|
+
# functions) raw ids are allocated by semantic analysis, using
|
|
550
|
+
# positive ids 1, 2, ... for generic class parameters and negative
|
|
551
|
+
# ids -1, ... for generic function type arguments. A special value 0
|
|
552
|
+
# is reserved for Self type variable (autogenerated). This convention
|
|
553
|
+
# is only used to keep type variable ids distinct when allocating
|
|
554
|
+
# them; the type checker makes no distinction between class and
|
|
555
|
+
# function type variables.
|
|
556
|
+
|
|
557
|
+
# Metavariables are allocated unique ids starting from 1.
|
|
558
|
+
raw_id: Final[int]
|
|
559
|
+
|
|
560
|
+
# Level of the variable in type inference. Currently either 0 for
|
|
561
|
+
# declared types, or 1 for type inference metavariables.
|
|
562
|
+
meta_level: int = 0
|
|
563
|
+
|
|
564
|
+
# Class variable used for allocating fresh ids for metavariables.
|
|
565
|
+
next_raw_id: ClassVar[int] = 1
|
|
566
|
+
|
|
567
|
+
# Fullname of class or function/method which declares this type
|
|
568
|
+
# variable (not the fullname of the TypeVar definition!), or ''
|
|
569
|
+
namespace: str
|
|
570
|
+
|
|
571
|
+
def __init__(self, raw_id: int, meta_level: int = 0, *, namespace: str = "") -> None:
|
|
572
|
+
self.raw_id = raw_id
|
|
573
|
+
self.meta_level = meta_level
|
|
574
|
+
self.namespace = namespace
|
|
575
|
+
|
|
576
|
+
@staticmethod
|
|
577
|
+
def new(meta_level: int) -> TypeVarId:
|
|
578
|
+
raw_id = TypeVarId.next_raw_id
|
|
579
|
+
TypeVarId.next_raw_id += 1
|
|
580
|
+
return TypeVarId(raw_id, meta_level)
|
|
581
|
+
|
|
582
|
+
def __repr__(self) -> str:
|
|
583
|
+
return self.raw_id.__repr__()
|
|
584
|
+
|
|
585
|
+
def __eq__(self, other: object) -> bool:
|
|
586
|
+
# Although this call is not expensive (like UnionType or TypedDictType),
|
|
587
|
+
# most of the time we get the same object here, so add a fast path.
|
|
588
|
+
if self is other:
|
|
589
|
+
return True
|
|
590
|
+
return (
|
|
591
|
+
isinstance(other, TypeVarId)
|
|
592
|
+
and self.raw_id == other.raw_id
|
|
593
|
+
and self.meta_level == other.meta_level
|
|
594
|
+
and self.namespace == other.namespace
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
def __ne__(self, other: object) -> bool:
|
|
598
|
+
return not (self == other)
|
|
599
|
+
|
|
600
|
+
def __hash__(self) -> int:
|
|
601
|
+
return self.raw_id ^ (self.meta_level << 8) ^ hash(self.namespace)
|
|
602
|
+
|
|
603
|
+
def is_meta_var(self) -> bool:
|
|
604
|
+
return self.meta_level > 0
|
|
605
|
+
|
|
606
|
+
def is_self(self) -> bool:
|
|
607
|
+
# This is a special value indicating typing.Self variable.
|
|
608
|
+
return self.raw_id == 0
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
class TypeVarLikeType(ProperType):
|
|
612
|
+
__slots__ = ("name", "fullname", "id", "upper_bound", "default")
|
|
613
|
+
|
|
614
|
+
name: str # Name (may be qualified)
|
|
615
|
+
fullname: str # Fully qualified name
|
|
616
|
+
id: TypeVarId
|
|
617
|
+
upper_bound: Type
|
|
618
|
+
default: Type
|
|
619
|
+
|
|
620
|
+
def __init__(
|
|
621
|
+
self,
|
|
622
|
+
name: str,
|
|
623
|
+
fullname: str,
|
|
624
|
+
id: TypeVarId,
|
|
625
|
+
upper_bound: Type,
|
|
626
|
+
default: Type,
|
|
627
|
+
line: int = -1,
|
|
628
|
+
column: int = -1,
|
|
629
|
+
) -> None:
|
|
630
|
+
super().__init__(line, column)
|
|
631
|
+
self.name = name
|
|
632
|
+
self.fullname = fullname
|
|
633
|
+
self.id = id
|
|
634
|
+
self.upper_bound = upper_bound
|
|
635
|
+
self.default = default
|
|
636
|
+
|
|
637
|
+
def serialize(self) -> JsonDict:
|
|
638
|
+
raise NotImplementedError
|
|
639
|
+
|
|
640
|
+
@classmethod
|
|
641
|
+
def deserialize(cls, data: JsonDict) -> TypeVarLikeType:
|
|
642
|
+
raise NotImplementedError
|
|
643
|
+
|
|
644
|
+
def copy_modified(self, *, id: TypeVarId, **kwargs: Any) -> Self:
|
|
645
|
+
raise NotImplementedError
|
|
646
|
+
|
|
647
|
+
@classmethod
|
|
648
|
+
def new_unification_variable(cls, old: Self) -> Self:
|
|
649
|
+
new_id = TypeVarId.new(meta_level=1)
|
|
650
|
+
return old.copy_modified(id=new_id)
|
|
651
|
+
|
|
652
|
+
def has_default(self) -> bool:
|
|
653
|
+
t = get_proper_type(self.default)
|
|
654
|
+
return not (isinstance(t, AnyType) and t.type_of_any == TypeOfAny.from_omitted_generics)
|
|
655
|
+
|
|
656
|
+
def values_or_bound(self) -> ProperType:
|
|
657
|
+
if isinstance(self, TypeVarType) and self.values:
|
|
658
|
+
return UnionType(self.values)
|
|
659
|
+
return get_proper_type(self.upper_bound)
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
class TypeVarType(TypeVarLikeType):
|
|
663
|
+
"""Type that refers to a type variable."""
|
|
664
|
+
|
|
665
|
+
__slots__ = ("values", "variance")
|
|
666
|
+
|
|
667
|
+
values: list[Type] # Value restriction, empty list if no restriction
|
|
668
|
+
variance: int
|
|
669
|
+
|
|
670
|
+
def __init__(
|
|
671
|
+
self,
|
|
672
|
+
name: str,
|
|
673
|
+
fullname: str,
|
|
674
|
+
id: TypeVarId,
|
|
675
|
+
values: list[Type],
|
|
676
|
+
upper_bound: Type,
|
|
677
|
+
default: Type,
|
|
678
|
+
variance: int = INVARIANT,
|
|
679
|
+
line: int = -1,
|
|
680
|
+
column: int = -1,
|
|
681
|
+
) -> None:
|
|
682
|
+
super().__init__(name, fullname, id, upper_bound, default, line, column)
|
|
683
|
+
assert values is not None, "No restrictions must be represented by empty list"
|
|
684
|
+
self.values = values
|
|
685
|
+
self.variance = variance
|
|
686
|
+
|
|
687
|
+
def copy_modified(
|
|
688
|
+
self,
|
|
689
|
+
*,
|
|
690
|
+
values: Bogus[list[Type]] = _dummy,
|
|
691
|
+
upper_bound: Bogus[Type] = _dummy,
|
|
692
|
+
default: Bogus[Type] = _dummy,
|
|
693
|
+
id: Bogus[TypeVarId] = _dummy,
|
|
694
|
+
line: int = _dummy_int,
|
|
695
|
+
column: int = _dummy_int,
|
|
696
|
+
**kwargs: Any,
|
|
697
|
+
) -> TypeVarType:
|
|
698
|
+
return TypeVarType(
|
|
699
|
+
name=self.name,
|
|
700
|
+
fullname=self.fullname,
|
|
701
|
+
id=self.id if id is _dummy else id,
|
|
702
|
+
values=self.values if values is _dummy else values,
|
|
703
|
+
upper_bound=self.upper_bound if upper_bound is _dummy else upper_bound,
|
|
704
|
+
default=self.default if default is _dummy else default,
|
|
705
|
+
variance=self.variance,
|
|
706
|
+
line=self.line if line == _dummy_int else line,
|
|
707
|
+
column=self.column if column == _dummy_int else column,
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
711
|
+
return visitor.visit_type_var(self)
|
|
712
|
+
|
|
713
|
+
def __hash__(self) -> int:
|
|
714
|
+
return hash((self.id, self.upper_bound, tuple(self.values)))
|
|
715
|
+
|
|
716
|
+
def __eq__(self, other: object) -> bool:
|
|
717
|
+
if not isinstance(other, TypeVarType):
|
|
718
|
+
return NotImplemented
|
|
719
|
+
return (
|
|
720
|
+
self.id == other.id
|
|
721
|
+
and self.upper_bound == other.upper_bound
|
|
722
|
+
and self.values == other.values
|
|
723
|
+
and self.default == other.default
|
|
724
|
+
)
|
|
725
|
+
|
|
726
|
+
def serialize(self) -> JsonDict:
|
|
727
|
+
assert not self.id.is_meta_var()
|
|
728
|
+
return {
|
|
729
|
+
".class": "TypeVarType",
|
|
730
|
+
"name": self.name,
|
|
731
|
+
"fullname": self.fullname,
|
|
732
|
+
"id": self.id.raw_id,
|
|
733
|
+
"namespace": self.id.namespace,
|
|
734
|
+
"values": [v.serialize() for v in self.values],
|
|
735
|
+
"upper_bound": self.upper_bound.serialize(),
|
|
736
|
+
"default": self.default.serialize(),
|
|
737
|
+
"variance": self.variance,
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
@classmethod
|
|
741
|
+
def deserialize(cls, data: JsonDict) -> TypeVarType:
|
|
742
|
+
assert data[".class"] == "TypeVarType"
|
|
743
|
+
return TypeVarType(
|
|
744
|
+
name=data["name"],
|
|
745
|
+
fullname=data["fullname"],
|
|
746
|
+
id=TypeVarId(data["id"], namespace=data["namespace"]),
|
|
747
|
+
values=[deserialize_type(v) for v in data["values"]],
|
|
748
|
+
upper_bound=deserialize_type(data["upper_bound"]),
|
|
749
|
+
default=deserialize_type(data["default"]),
|
|
750
|
+
variance=data["variance"],
|
|
751
|
+
)
|
|
752
|
+
|
|
753
|
+
def write(self, data: WriteBuffer) -> None:
|
|
754
|
+
write_tag(data, TYPE_VAR_TYPE)
|
|
755
|
+
write_str(data, self.name)
|
|
756
|
+
write_str(data, self.fullname)
|
|
757
|
+
write_int(data, self.id.raw_id)
|
|
758
|
+
write_str(data, self.id.namespace)
|
|
759
|
+
write_type_list(data, self.values)
|
|
760
|
+
self.upper_bound.write(data)
|
|
761
|
+
self.default.write(data)
|
|
762
|
+
write_int(data, self.variance)
|
|
763
|
+
write_tag(data, END_TAG)
|
|
764
|
+
|
|
765
|
+
@classmethod
|
|
766
|
+
def read(cls, data: ReadBuffer) -> TypeVarType:
|
|
767
|
+
ret = TypeVarType(
|
|
768
|
+
read_str(data),
|
|
769
|
+
read_str(data),
|
|
770
|
+
TypeVarId(read_int(data), namespace=read_str(data)),
|
|
771
|
+
read_type_list(data),
|
|
772
|
+
read_type(data),
|
|
773
|
+
read_type(data),
|
|
774
|
+
read_int(data),
|
|
775
|
+
)
|
|
776
|
+
assert read_tag(data) == END_TAG
|
|
777
|
+
return ret
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
class ParamSpecFlavor:
|
|
781
|
+
# Simple ParamSpec reference such as "P"
|
|
782
|
+
BARE: Final = 0
|
|
783
|
+
# P.args
|
|
784
|
+
ARGS: Final = 1
|
|
785
|
+
# P.kwargs
|
|
786
|
+
KWARGS: Final = 2
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
class ParamSpecType(TypeVarLikeType):
|
|
790
|
+
"""Type that refers to a ParamSpec.
|
|
791
|
+
|
|
792
|
+
A ParamSpec is a type variable that represents the parameter
|
|
793
|
+
types, names and kinds of a callable (i.e., the signature without
|
|
794
|
+
the return type).
|
|
795
|
+
|
|
796
|
+
This can be one of these forms
|
|
797
|
+
* P (ParamSpecFlavor.BARE)
|
|
798
|
+
* P.args (ParamSpecFlavor.ARGS)
|
|
799
|
+
* P.kwargs (ParamSpecFLavor.KWARGS)
|
|
800
|
+
|
|
801
|
+
The upper_bound is really used as a fallback type -- it's shared
|
|
802
|
+
with TypeVarType for simplicity. It can't be specified by the user
|
|
803
|
+
and the value is directly derived from the flavor (currently
|
|
804
|
+
always just 'object').
|
|
805
|
+
"""
|
|
806
|
+
|
|
807
|
+
__slots__ = ("flavor", "prefix")
|
|
808
|
+
|
|
809
|
+
flavor: int
|
|
810
|
+
prefix: Parameters
|
|
811
|
+
|
|
812
|
+
def __init__(
|
|
813
|
+
self,
|
|
814
|
+
name: str,
|
|
815
|
+
fullname: str,
|
|
816
|
+
id: TypeVarId,
|
|
817
|
+
flavor: int,
|
|
818
|
+
upper_bound: Type,
|
|
819
|
+
default: Type,
|
|
820
|
+
*,
|
|
821
|
+
line: int = -1,
|
|
822
|
+
column: int = -1,
|
|
823
|
+
prefix: Parameters | None = None,
|
|
824
|
+
) -> None:
|
|
825
|
+
super().__init__(name, fullname, id, upper_bound, default, line=line, column=column)
|
|
826
|
+
self.flavor = flavor
|
|
827
|
+
self.prefix = prefix or Parameters([], [], [])
|
|
828
|
+
|
|
829
|
+
def with_flavor(self, flavor: int) -> ParamSpecType:
|
|
830
|
+
return ParamSpecType(
|
|
831
|
+
self.name,
|
|
832
|
+
self.fullname,
|
|
833
|
+
self.id,
|
|
834
|
+
flavor,
|
|
835
|
+
upper_bound=self.upper_bound,
|
|
836
|
+
default=self.default,
|
|
837
|
+
prefix=self.prefix,
|
|
838
|
+
)
|
|
839
|
+
|
|
840
|
+
def copy_modified(
|
|
841
|
+
self,
|
|
842
|
+
*,
|
|
843
|
+
id: Bogus[TypeVarId] = _dummy,
|
|
844
|
+
flavor: int = _dummy_int,
|
|
845
|
+
prefix: Bogus[Parameters] = _dummy,
|
|
846
|
+
default: Bogus[Type] = _dummy,
|
|
847
|
+
**kwargs: Any,
|
|
848
|
+
) -> ParamSpecType:
|
|
849
|
+
return ParamSpecType(
|
|
850
|
+
self.name,
|
|
851
|
+
self.fullname,
|
|
852
|
+
id if id is not _dummy else self.id,
|
|
853
|
+
flavor if flavor != _dummy_int else self.flavor,
|
|
854
|
+
self.upper_bound,
|
|
855
|
+
default=default if default is not _dummy else self.default,
|
|
856
|
+
line=self.line,
|
|
857
|
+
column=self.column,
|
|
858
|
+
prefix=prefix if prefix is not _dummy else self.prefix,
|
|
859
|
+
)
|
|
860
|
+
|
|
861
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
862
|
+
return visitor.visit_param_spec(self)
|
|
863
|
+
|
|
864
|
+
def name_with_suffix(self) -> str:
|
|
865
|
+
n = self.name
|
|
866
|
+
if self.flavor == ParamSpecFlavor.ARGS:
|
|
867
|
+
return f"{n}.args"
|
|
868
|
+
elif self.flavor == ParamSpecFlavor.KWARGS:
|
|
869
|
+
return f"{n}.kwargs"
|
|
870
|
+
return n
|
|
871
|
+
|
|
872
|
+
def __hash__(self) -> int:
|
|
873
|
+
return hash((self.id, self.flavor, self.prefix))
|
|
874
|
+
|
|
875
|
+
def __eq__(self, other: object) -> bool:
|
|
876
|
+
if not isinstance(other, ParamSpecType):
|
|
877
|
+
return NotImplemented
|
|
878
|
+
# Upper bound can be ignored, since it's determined by flavor.
|
|
879
|
+
return (
|
|
880
|
+
self.id == other.id
|
|
881
|
+
and self.flavor == other.flavor
|
|
882
|
+
and self.prefix == other.prefix
|
|
883
|
+
and self.default == other.default
|
|
884
|
+
)
|
|
885
|
+
|
|
886
|
+
def serialize(self) -> JsonDict:
|
|
887
|
+
assert not self.id.is_meta_var()
|
|
888
|
+
return {
|
|
889
|
+
".class": "ParamSpecType",
|
|
890
|
+
"name": self.name,
|
|
891
|
+
"fullname": self.fullname,
|
|
892
|
+
"id": self.id.raw_id,
|
|
893
|
+
"namespace": self.id.namespace,
|
|
894
|
+
"flavor": self.flavor,
|
|
895
|
+
"upper_bound": self.upper_bound.serialize(),
|
|
896
|
+
"default": self.default.serialize(),
|
|
897
|
+
"prefix": self.prefix.serialize(),
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
@classmethod
|
|
901
|
+
def deserialize(cls, data: JsonDict) -> ParamSpecType:
|
|
902
|
+
assert data[".class"] == "ParamSpecType"
|
|
903
|
+
return ParamSpecType(
|
|
904
|
+
data["name"],
|
|
905
|
+
data["fullname"],
|
|
906
|
+
TypeVarId(data["id"], namespace=data["namespace"]),
|
|
907
|
+
data["flavor"],
|
|
908
|
+
deserialize_type(data["upper_bound"]),
|
|
909
|
+
deserialize_type(data["default"]),
|
|
910
|
+
prefix=Parameters.deserialize(data["prefix"]),
|
|
911
|
+
)
|
|
912
|
+
|
|
913
|
+
def write(self, data: WriteBuffer) -> None:
|
|
914
|
+
write_tag(data, PARAM_SPEC_TYPE)
|
|
915
|
+
self.prefix.write(data)
|
|
916
|
+
write_str(data, self.name)
|
|
917
|
+
write_str(data, self.fullname)
|
|
918
|
+
write_int(data, self.id.raw_id)
|
|
919
|
+
write_str(data, self.id.namespace)
|
|
920
|
+
write_int(data, self.flavor)
|
|
921
|
+
self.upper_bound.write(data)
|
|
922
|
+
self.default.write(data)
|
|
923
|
+
write_tag(data, END_TAG)
|
|
924
|
+
|
|
925
|
+
@classmethod
|
|
926
|
+
def read(cls, data: ReadBuffer) -> ParamSpecType:
|
|
927
|
+
assert read_tag(data) == PARAMETERS
|
|
928
|
+
prefix = Parameters.read(data)
|
|
929
|
+
ret = ParamSpecType(
|
|
930
|
+
read_str(data),
|
|
931
|
+
read_str(data),
|
|
932
|
+
TypeVarId(read_int(data), namespace=read_str(data)),
|
|
933
|
+
read_int(data),
|
|
934
|
+
read_type(data),
|
|
935
|
+
read_type(data),
|
|
936
|
+
prefix=prefix,
|
|
937
|
+
)
|
|
938
|
+
assert read_tag(data) == END_TAG
|
|
939
|
+
return ret
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
class TypeVarTupleType(TypeVarLikeType):
|
|
943
|
+
"""Type that refers to a TypeVarTuple.
|
|
944
|
+
|
|
945
|
+
See PEP646 for more information.
|
|
946
|
+
"""
|
|
947
|
+
|
|
948
|
+
__slots__ = ("tuple_fallback", "min_len")
|
|
949
|
+
|
|
950
|
+
def __init__(
|
|
951
|
+
self,
|
|
952
|
+
name: str,
|
|
953
|
+
fullname: str,
|
|
954
|
+
id: TypeVarId,
|
|
955
|
+
upper_bound: Type,
|
|
956
|
+
tuple_fallback: Instance,
|
|
957
|
+
default: Type,
|
|
958
|
+
*,
|
|
959
|
+
line: int = -1,
|
|
960
|
+
column: int = -1,
|
|
961
|
+
min_len: int = 0,
|
|
962
|
+
) -> None:
|
|
963
|
+
super().__init__(name, fullname, id, upper_bound, default, line=line, column=column)
|
|
964
|
+
self.tuple_fallback = tuple_fallback
|
|
965
|
+
# This value is not settable by a user. It is an internal-only thing to support
|
|
966
|
+
# len()-narrowing of variadic tuples.
|
|
967
|
+
self.min_len = min_len
|
|
968
|
+
|
|
969
|
+
def serialize(self) -> JsonDict:
|
|
970
|
+
assert not self.id.is_meta_var()
|
|
971
|
+
return {
|
|
972
|
+
".class": "TypeVarTupleType",
|
|
973
|
+
"name": self.name,
|
|
974
|
+
"fullname": self.fullname,
|
|
975
|
+
"id": self.id.raw_id,
|
|
976
|
+
"namespace": self.id.namespace,
|
|
977
|
+
"upper_bound": self.upper_bound.serialize(),
|
|
978
|
+
"tuple_fallback": self.tuple_fallback.serialize(),
|
|
979
|
+
"default": self.default.serialize(),
|
|
980
|
+
"min_len": self.min_len,
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
@classmethod
|
|
984
|
+
def deserialize(cls, data: JsonDict) -> TypeVarTupleType:
|
|
985
|
+
assert data[".class"] == "TypeVarTupleType"
|
|
986
|
+
return TypeVarTupleType(
|
|
987
|
+
data["name"],
|
|
988
|
+
data["fullname"],
|
|
989
|
+
TypeVarId(data["id"], namespace=data["namespace"]),
|
|
990
|
+
deserialize_type(data["upper_bound"]),
|
|
991
|
+
Instance.deserialize(data["tuple_fallback"]),
|
|
992
|
+
deserialize_type(data["default"]),
|
|
993
|
+
min_len=data["min_len"],
|
|
994
|
+
)
|
|
995
|
+
|
|
996
|
+
def write(self, data: WriteBuffer) -> None:
|
|
997
|
+
write_tag(data, TYPE_VAR_TUPLE_TYPE)
|
|
998
|
+
self.tuple_fallback.write(data)
|
|
999
|
+
write_str(data, self.name)
|
|
1000
|
+
write_str(data, self.fullname)
|
|
1001
|
+
write_int(data, self.id.raw_id)
|
|
1002
|
+
write_str(data, self.id.namespace)
|
|
1003
|
+
self.upper_bound.write(data)
|
|
1004
|
+
self.default.write(data)
|
|
1005
|
+
write_int(data, self.min_len)
|
|
1006
|
+
write_tag(data, END_TAG)
|
|
1007
|
+
|
|
1008
|
+
@classmethod
|
|
1009
|
+
def read(cls, data: ReadBuffer) -> TypeVarTupleType:
|
|
1010
|
+
assert read_tag(data) == INSTANCE
|
|
1011
|
+
fallback = Instance.read(data)
|
|
1012
|
+
ret = TypeVarTupleType(
|
|
1013
|
+
read_str(data),
|
|
1014
|
+
read_str(data),
|
|
1015
|
+
TypeVarId(read_int(data), namespace=read_str(data)),
|
|
1016
|
+
read_type(data),
|
|
1017
|
+
fallback,
|
|
1018
|
+
read_type(data),
|
|
1019
|
+
min_len=read_int(data),
|
|
1020
|
+
)
|
|
1021
|
+
assert read_tag(data) == END_TAG
|
|
1022
|
+
return ret
|
|
1023
|
+
|
|
1024
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1025
|
+
return visitor.visit_type_var_tuple(self)
|
|
1026
|
+
|
|
1027
|
+
def __hash__(self) -> int:
|
|
1028
|
+
return hash((self.id, self.min_len))
|
|
1029
|
+
|
|
1030
|
+
def __eq__(self, other: object) -> bool:
|
|
1031
|
+
if not isinstance(other, TypeVarTupleType):
|
|
1032
|
+
return NotImplemented
|
|
1033
|
+
return (
|
|
1034
|
+
self.id == other.id and self.min_len == other.min_len and self.default == other.default
|
|
1035
|
+
)
|
|
1036
|
+
|
|
1037
|
+
def copy_modified(
|
|
1038
|
+
self,
|
|
1039
|
+
*,
|
|
1040
|
+
id: Bogus[TypeVarId] = _dummy,
|
|
1041
|
+
upper_bound: Bogus[Type] = _dummy,
|
|
1042
|
+
default: Bogus[Type] = _dummy,
|
|
1043
|
+
min_len: Bogus[int] = _dummy,
|
|
1044
|
+
**kwargs: Any,
|
|
1045
|
+
) -> TypeVarTupleType:
|
|
1046
|
+
return TypeVarTupleType(
|
|
1047
|
+
self.name,
|
|
1048
|
+
self.fullname,
|
|
1049
|
+
self.id if id is _dummy else id,
|
|
1050
|
+
self.upper_bound if upper_bound is _dummy else upper_bound,
|
|
1051
|
+
self.tuple_fallback,
|
|
1052
|
+
self.default if default is _dummy else default,
|
|
1053
|
+
line=self.line,
|
|
1054
|
+
column=self.column,
|
|
1055
|
+
min_len=self.min_len if min_len is _dummy else min_len,
|
|
1056
|
+
)
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
class UnboundType(ProperType):
|
|
1060
|
+
"""Instance type that has not been bound during semantic analysis."""
|
|
1061
|
+
|
|
1062
|
+
__slots__ = (
|
|
1063
|
+
"name",
|
|
1064
|
+
"args",
|
|
1065
|
+
"optional",
|
|
1066
|
+
"empty_tuple_index",
|
|
1067
|
+
"original_str_expr",
|
|
1068
|
+
"original_str_fallback",
|
|
1069
|
+
)
|
|
1070
|
+
|
|
1071
|
+
def __init__(
|
|
1072
|
+
self,
|
|
1073
|
+
name: str,
|
|
1074
|
+
args: Sequence[Type] | None = None,
|
|
1075
|
+
*,
|
|
1076
|
+
line: int = -1,
|
|
1077
|
+
column: int = -1,
|
|
1078
|
+
optional: bool = False,
|
|
1079
|
+
empty_tuple_index: bool = False,
|
|
1080
|
+
original_str_expr: str | None = None,
|
|
1081
|
+
original_str_fallback: str | None = None,
|
|
1082
|
+
) -> None:
|
|
1083
|
+
super().__init__(line, column)
|
|
1084
|
+
if not args:
|
|
1085
|
+
args = []
|
|
1086
|
+
self.name = name
|
|
1087
|
+
self.args = tuple(args)
|
|
1088
|
+
# Should this type be wrapped in an Optional?
|
|
1089
|
+
self.optional = optional
|
|
1090
|
+
# Special case for X[()]
|
|
1091
|
+
self.empty_tuple_index = empty_tuple_index
|
|
1092
|
+
# If this UnboundType was originally defined as a str or bytes, keep track of
|
|
1093
|
+
# the original contents of that string-like thing. This way, if this UnboundExpr
|
|
1094
|
+
# ever shows up inside of a LiteralType, we can determine whether that
|
|
1095
|
+
# Literal[...] is valid or not. E.g. Literal[foo] is most likely invalid
|
|
1096
|
+
# (unless 'foo' is an alias for another literal or something) and
|
|
1097
|
+
# Literal["foo"] most likely is.
|
|
1098
|
+
#
|
|
1099
|
+
# We keep track of the entire string instead of just using a boolean flag
|
|
1100
|
+
# so we can distinguish between things like Literal["foo"] vs
|
|
1101
|
+
# Literal[" foo "].
|
|
1102
|
+
#
|
|
1103
|
+
# We also keep track of what the original base fallback type was supposed to be
|
|
1104
|
+
# so we don't have to try and recompute it later
|
|
1105
|
+
self.original_str_expr = original_str_expr
|
|
1106
|
+
self.original_str_fallback = original_str_fallback
|
|
1107
|
+
|
|
1108
|
+
def copy_modified(self, args: Bogus[Sequence[Type] | None] = _dummy) -> UnboundType:
|
|
1109
|
+
if args is _dummy:
|
|
1110
|
+
args = self.args
|
|
1111
|
+
return UnboundType(
|
|
1112
|
+
name=self.name,
|
|
1113
|
+
args=args,
|
|
1114
|
+
line=self.line,
|
|
1115
|
+
column=self.column,
|
|
1116
|
+
optional=self.optional,
|
|
1117
|
+
empty_tuple_index=self.empty_tuple_index,
|
|
1118
|
+
original_str_expr=self.original_str_expr,
|
|
1119
|
+
original_str_fallback=self.original_str_fallback,
|
|
1120
|
+
)
|
|
1121
|
+
|
|
1122
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1123
|
+
return visitor.visit_unbound_type(self)
|
|
1124
|
+
|
|
1125
|
+
def __hash__(self) -> int:
|
|
1126
|
+
return hash((self.name, self.optional, tuple(self.args), self.original_str_expr))
|
|
1127
|
+
|
|
1128
|
+
def __eq__(self, other: object) -> bool:
|
|
1129
|
+
if not isinstance(other, UnboundType):
|
|
1130
|
+
return NotImplemented
|
|
1131
|
+
return (
|
|
1132
|
+
self.name == other.name
|
|
1133
|
+
and self.optional == other.optional
|
|
1134
|
+
and self.args == other.args
|
|
1135
|
+
and self.original_str_expr == other.original_str_expr
|
|
1136
|
+
and self.original_str_fallback == other.original_str_fallback
|
|
1137
|
+
)
|
|
1138
|
+
|
|
1139
|
+
def serialize(self) -> JsonDict:
|
|
1140
|
+
return {
|
|
1141
|
+
".class": "UnboundType",
|
|
1142
|
+
"name": self.name,
|
|
1143
|
+
"args": [a.serialize() for a in self.args],
|
|
1144
|
+
"expr": self.original_str_expr,
|
|
1145
|
+
"expr_fallback": self.original_str_fallback,
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
@classmethod
|
|
1149
|
+
def deserialize(cls, data: JsonDict) -> UnboundType:
|
|
1150
|
+
assert data[".class"] == "UnboundType"
|
|
1151
|
+
return UnboundType(
|
|
1152
|
+
data["name"],
|
|
1153
|
+
[deserialize_type(a) for a in data["args"]],
|
|
1154
|
+
original_str_expr=data["expr"],
|
|
1155
|
+
original_str_fallback=data["expr_fallback"],
|
|
1156
|
+
)
|
|
1157
|
+
|
|
1158
|
+
def write(self, data: WriteBuffer) -> None:
|
|
1159
|
+
write_tag(data, UNBOUND_TYPE)
|
|
1160
|
+
write_str(data, self.name)
|
|
1161
|
+
write_type_list(data, self.args)
|
|
1162
|
+
write_str_opt(data, self.original_str_expr)
|
|
1163
|
+
write_str_opt(data, self.original_str_fallback)
|
|
1164
|
+
write_tag(data, END_TAG)
|
|
1165
|
+
|
|
1166
|
+
@classmethod
|
|
1167
|
+
def read(cls, data: ReadBuffer) -> UnboundType:
|
|
1168
|
+
ret = UnboundType(
|
|
1169
|
+
read_str(data),
|
|
1170
|
+
read_type_list(data),
|
|
1171
|
+
original_str_expr=read_str_opt(data),
|
|
1172
|
+
original_str_fallback=read_str_opt(data),
|
|
1173
|
+
)
|
|
1174
|
+
assert read_tag(data) == END_TAG
|
|
1175
|
+
return ret
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
class CallableArgument(ProperType):
|
|
1179
|
+
"""Represents a Arg(type, 'name') inside a Callable's type list.
|
|
1180
|
+
|
|
1181
|
+
Note that this is a synthetic type for helping parse ASTs, not a real type.
|
|
1182
|
+
"""
|
|
1183
|
+
|
|
1184
|
+
__slots__ = ("typ", "name", "constructor")
|
|
1185
|
+
|
|
1186
|
+
typ: Type
|
|
1187
|
+
name: str | None
|
|
1188
|
+
constructor: str | None
|
|
1189
|
+
|
|
1190
|
+
def __init__(
|
|
1191
|
+
self,
|
|
1192
|
+
typ: Type,
|
|
1193
|
+
name: str | None,
|
|
1194
|
+
constructor: str | None,
|
|
1195
|
+
line: int = -1,
|
|
1196
|
+
column: int = -1,
|
|
1197
|
+
) -> None:
|
|
1198
|
+
super().__init__(line, column)
|
|
1199
|
+
self.typ = typ
|
|
1200
|
+
self.name = name
|
|
1201
|
+
self.constructor = constructor
|
|
1202
|
+
|
|
1203
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1204
|
+
assert isinstance(visitor, SyntheticTypeVisitor)
|
|
1205
|
+
ret: T = visitor.visit_callable_argument(self)
|
|
1206
|
+
return ret
|
|
1207
|
+
|
|
1208
|
+
def serialize(self) -> JsonDict:
|
|
1209
|
+
assert False, "Synthetic types don't serialize"
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
class TypeList(ProperType):
|
|
1213
|
+
"""Information about argument types and names [...].
|
|
1214
|
+
|
|
1215
|
+
This is used for the arguments of a Callable type, i.e. for
|
|
1216
|
+
[arg, ...] in Callable[[arg, ...], ret]. This is not a real type
|
|
1217
|
+
but a syntactic AST construct. UnboundTypes can also have TypeList
|
|
1218
|
+
types before they are processed into Callable types.
|
|
1219
|
+
"""
|
|
1220
|
+
|
|
1221
|
+
__slots__ = ("items",)
|
|
1222
|
+
|
|
1223
|
+
items: list[Type]
|
|
1224
|
+
|
|
1225
|
+
def __init__(self, items: list[Type], line: int = -1, column: int = -1) -> None:
|
|
1226
|
+
super().__init__(line, column)
|
|
1227
|
+
self.items = items
|
|
1228
|
+
|
|
1229
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1230
|
+
assert isinstance(visitor, SyntheticTypeVisitor)
|
|
1231
|
+
ret: T = visitor.visit_type_list(self)
|
|
1232
|
+
return ret
|
|
1233
|
+
|
|
1234
|
+
def serialize(self) -> JsonDict:
|
|
1235
|
+
assert False, "Synthetic types don't serialize"
|
|
1236
|
+
|
|
1237
|
+
def __hash__(self) -> int:
|
|
1238
|
+
return hash(tuple(self.items))
|
|
1239
|
+
|
|
1240
|
+
def __eq__(self, other: object) -> bool:
|
|
1241
|
+
return isinstance(other, TypeList) and self.items == other.items
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
class UnpackType(ProperType):
|
|
1245
|
+
"""Type operator Unpack from PEP646. Can be either with Unpack[]
|
|
1246
|
+
or unpacking * syntax.
|
|
1247
|
+
|
|
1248
|
+
The inner type should be either a TypeVarTuple, or a variable length tuple.
|
|
1249
|
+
In an exceptional case of callable star argument it can be a fixed length tuple.
|
|
1250
|
+
|
|
1251
|
+
Note: the above restrictions are only guaranteed by normalizations after semantic
|
|
1252
|
+
analysis, if your code needs to handle UnpackType *during* semantic analysis, it is
|
|
1253
|
+
wild west, technically anything can be present in the wrapped type.
|
|
1254
|
+
"""
|
|
1255
|
+
|
|
1256
|
+
__slots__ = ["type", "from_star_syntax"]
|
|
1257
|
+
|
|
1258
|
+
def __init__(
|
|
1259
|
+
self, typ: Type, line: int = -1, column: int = -1, from_star_syntax: bool = False
|
|
1260
|
+
) -> None:
|
|
1261
|
+
super().__init__(line, column)
|
|
1262
|
+
self.type = typ
|
|
1263
|
+
self.from_star_syntax = from_star_syntax
|
|
1264
|
+
|
|
1265
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1266
|
+
return visitor.visit_unpack_type(self)
|
|
1267
|
+
|
|
1268
|
+
def serialize(self) -> JsonDict:
|
|
1269
|
+
return {".class": "UnpackType", "type": self.type.serialize()}
|
|
1270
|
+
|
|
1271
|
+
def write(self, data: WriteBuffer) -> None:
|
|
1272
|
+
write_tag(data, UNPACK_TYPE)
|
|
1273
|
+
self.type.write(data)
|
|
1274
|
+
write_tag(data, END_TAG)
|
|
1275
|
+
|
|
1276
|
+
@classmethod
|
|
1277
|
+
def read(cls, data: ReadBuffer) -> UnpackType:
|
|
1278
|
+
ret = UnpackType(read_type(data))
|
|
1279
|
+
assert read_tag(data) == END_TAG
|
|
1280
|
+
return ret
|
|
1281
|
+
|
|
1282
|
+
@classmethod
|
|
1283
|
+
def deserialize(cls, data: JsonDict) -> UnpackType:
|
|
1284
|
+
assert data[".class"] == "UnpackType"
|
|
1285
|
+
typ = data["type"]
|
|
1286
|
+
return UnpackType(deserialize_type(typ))
|
|
1287
|
+
|
|
1288
|
+
def __hash__(self) -> int:
|
|
1289
|
+
return hash(self.type)
|
|
1290
|
+
|
|
1291
|
+
def __eq__(self, other: object) -> bool:
|
|
1292
|
+
return isinstance(other, UnpackType) and self.type == other.type
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
class AnyType(ProperType):
|
|
1296
|
+
"""The type 'Any'."""
|
|
1297
|
+
|
|
1298
|
+
__slots__ = ("type_of_any", "source_any", "missing_import_name")
|
|
1299
|
+
|
|
1300
|
+
def __init__(
|
|
1301
|
+
self,
|
|
1302
|
+
type_of_any: int,
|
|
1303
|
+
source_any: AnyType | None = None,
|
|
1304
|
+
missing_import_name: str | None = None,
|
|
1305
|
+
line: int = -1,
|
|
1306
|
+
column: int = -1,
|
|
1307
|
+
) -> None:
|
|
1308
|
+
super().__init__(line, column)
|
|
1309
|
+
self.type_of_any = type_of_any
|
|
1310
|
+
# If this Any was created as a result of interacting with another 'Any', record the source
|
|
1311
|
+
# and use it in reports.
|
|
1312
|
+
self.source_any = source_any
|
|
1313
|
+
if source_any and source_any.source_any:
|
|
1314
|
+
self.source_any = source_any.source_any
|
|
1315
|
+
|
|
1316
|
+
if source_any is None:
|
|
1317
|
+
self.missing_import_name = missing_import_name
|
|
1318
|
+
else:
|
|
1319
|
+
self.missing_import_name = source_any.missing_import_name
|
|
1320
|
+
|
|
1321
|
+
# Only unimported type anys and anys from other anys should have an import name
|
|
1322
|
+
assert missing_import_name is None or type_of_any in (
|
|
1323
|
+
TypeOfAny.from_unimported_type,
|
|
1324
|
+
TypeOfAny.from_another_any,
|
|
1325
|
+
)
|
|
1326
|
+
# Only Anys that come from another Any can have source_any.
|
|
1327
|
+
assert type_of_any != TypeOfAny.from_another_any or source_any is not None
|
|
1328
|
+
# We should not have chains of Anys.
|
|
1329
|
+
assert not self.source_any or self.source_any.type_of_any != TypeOfAny.from_another_any
|
|
1330
|
+
|
|
1331
|
+
@property
|
|
1332
|
+
def is_from_error(self) -> bool:
|
|
1333
|
+
return self.type_of_any == TypeOfAny.from_error
|
|
1334
|
+
|
|
1335
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1336
|
+
return visitor.visit_any(self)
|
|
1337
|
+
|
|
1338
|
+
def copy_modified(
|
|
1339
|
+
self,
|
|
1340
|
+
# Mark with Bogus because _dummy is just an object (with type Any)
|
|
1341
|
+
type_of_any: int = _dummy_int,
|
|
1342
|
+
original_any: Bogus[AnyType | None] = _dummy,
|
|
1343
|
+
missing_import_name: Bogus[str | None] = _dummy,
|
|
1344
|
+
) -> AnyType:
|
|
1345
|
+
if type_of_any == _dummy_int:
|
|
1346
|
+
type_of_any = self.type_of_any
|
|
1347
|
+
if original_any is _dummy:
|
|
1348
|
+
original_any = self.source_any
|
|
1349
|
+
if missing_import_name is _dummy:
|
|
1350
|
+
missing_import_name = self.missing_import_name
|
|
1351
|
+
return AnyType(
|
|
1352
|
+
type_of_any=type_of_any,
|
|
1353
|
+
source_any=original_any,
|
|
1354
|
+
missing_import_name=missing_import_name,
|
|
1355
|
+
line=self.line,
|
|
1356
|
+
column=self.column,
|
|
1357
|
+
)
|
|
1358
|
+
|
|
1359
|
+
def __hash__(self) -> int:
|
|
1360
|
+
return hash(AnyType)
|
|
1361
|
+
|
|
1362
|
+
def __eq__(self, other: object) -> bool:
|
|
1363
|
+
return isinstance(other, AnyType)
|
|
1364
|
+
|
|
1365
|
+
def serialize(self) -> JsonDict:
|
|
1366
|
+
return {
|
|
1367
|
+
".class": "AnyType",
|
|
1368
|
+
"type_of_any": self.type_of_any,
|
|
1369
|
+
"source_any": self.source_any.serialize() if self.source_any is not None else None,
|
|
1370
|
+
"missing_import_name": self.missing_import_name,
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
@classmethod
|
|
1374
|
+
def deserialize(cls, data: JsonDict) -> AnyType:
|
|
1375
|
+
assert data[".class"] == "AnyType"
|
|
1376
|
+
source = data["source_any"]
|
|
1377
|
+
return AnyType(
|
|
1378
|
+
data["type_of_any"],
|
|
1379
|
+
AnyType.deserialize(source) if source is not None else None,
|
|
1380
|
+
data["missing_import_name"],
|
|
1381
|
+
)
|
|
1382
|
+
|
|
1383
|
+
def write(self, data: WriteBuffer) -> None:
|
|
1384
|
+
write_tag(data, ANY_TYPE)
|
|
1385
|
+
write_type_opt(data, self.source_any)
|
|
1386
|
+
write_int(data, self.type_of_any)
|
|
1387
|
+
write_str_opt(data, self.missing_import_name)
|
|
1388
|
+
write_tag(data, END_TAG)
|
|
1389
|
+
|
|
1390
|
+
@classmethod
|
|
1391
|
+
def read(cls, data: ReadBuffer) -> AnyType:
|
|
1392
|
+
tag = read_tag(data)
|
|
1393
|
+
if tag != LITERAL_NONE:
|
|
1394
|
+
assert tag == ANY_TYPE
|
|
1395
|
+
source_any = AnyType.read(data)
|
|
1396
|
+
else:
|
|
1397
|
+
source_any = None
|
|
1398
|
+
ret = AnyType(read_int(data), source_any, read_str_opt(data))
|
|
1399
|
+
assert read_tag(data) == END_TAG
|
|
1400
|
+
return ret
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
class UninhabitedType(ProperType):
|
|
1404
|
+
"""This type has no members.
|
|
1405
|
+
|
|
1406
|
+
This type is the bottom type.
|
|
1407
|
+
With strict Optional checking, it is the only common subtype between all
|
|
1408
|
+
other types, which allows `meet` to be well defined. Without strict
|
|
1409
|
+
Optional checking, NoneType fills this role.
|
|
1410
|
+
|
|
1411
|
+
In general, for any type T:
|
|
1412
|
+
join(UninhabitedType, T) = T
|
|
1413
|
+
meet(UninhabitedType, T) = UninhabitedType
|
|
1414
|
+
is_subtype(UninhabitedType, T) = True
|
|
1415
|
+
"""
|
|
1416
|
+
|
|
1417
|
+
__slots__ = ("ambiguous",)
|
|
1418
|
+
|
|
1419
|
+
ambiguous: bool # Is this a result of inference for a variable without constraints?
|
|
1420
|
+
|
|
1421
|
+
def __init__(self, line: int = -1, column: int = -1, *, ambiguous: bool = False) -> None:
|
|
1422
|
+
super().__init__(line, column)
|
|
1423
|
+
self.ambiguous = ambiguous
|
|
1424
|
+
|
|
1425
|
+
def can_be_true_default(self) -> bool:
|
|
1426
|
+
return False
|
|
1427
|
+
|
|
1428
|
+
def can_be_false_default(self) -> bool:
|
|
1429
|
+
return False
|
|
1430
|
+
|
|
1431
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1432
|
+
return visitor.visit_uninhabited_type(self)
|
|
1433
|
+
|
|
1434
|
+
def __hash__(self) -> int:
|
|
1435
|
+
return hash((UninhabitedType, self.ambiguous))
|
|
1436
|
+
|
|
1437
|
+
def __eq__(self, other: object) -> bool:
|
|
1438
|
+
return isinstance(other, UninhabitedType) and other.ambiguous == self.ambiguous
|
|
1439
|
+
|
|
1440
|
+
def serialize(self) -> JsonDict:
|
|
1441
|
+
return {".class": "UninhabitedType"}
|
|
1442
|
+
|
|
1443
|
+
@classmethod
|
|
1444
|
+
def deserialize(cls, data: JsonDict) -> UninhabitedType:
|
|
1445
|
+
assert data[".class"] == "UninhabitedType"
|
|
1446
|
+
return UninhabitedType()
|
|
1447
|
+
|
|
1448
|
+
def write(self, data: WriteBuffer) -> None:
|
|
1449
|
+
write_tag(data, UNINHABITED_TYPE)
|
|
1450
|
+
write_tag(data, END_TAG)
|
|
1451
|
+
|
|
1452
|
+
@classmethod
|
|
1453
|
+
def read(cls, data: ReadBuffer) -> UninhabitedType:
|
|
1454
|
+
assert read_tag(data) == END_TAG
|
|
1455
|
+
return UninhabitedType()
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
class NoneType(ProperType):
|
|
1459
|
+
"""The type of 'None'.
|
|
1460
|
+
|
|
1461
|
+
This type can be written by users as 'None'.
|
|
1462
|
+
"""
|
|
1463
|
+
|
|
1464
|
+
__slots__ = ()
|
|
1465
|
+
|
|
1466
|
+
def __init__(self, line: int = -1, column: int = -1) -> None:
|
|
1467
|
+
super().__init__(line, column)
|
|
1468
|
+
|
|
1469
|
+
def can_be_true_default(self) -> bool:
|
|
1470
|
+
return False
|
|
1471
|
+
|
|
1472
|
+
def __hash__(self) -> int:
|
|
1473
|
+
return hash(NoneType)
|
|
1474
|
+
|
|
1475
|
+
def __eq__(self, other: object) -> bool:
|
|
1476
|
+
return isinstance(other, NoneType)
|
|
1477
|
+
|
|
1478
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1479
|
+
return visitor.visit_none_type(self)
|
|
1480
|
+
|
|
1481
|
+
def serialize(self) -> JsonDict:
|
|
1482
|
+
return {".class": "NoneType"}
|
|
1483
|
+
|
|
1484
|
+
@classmethod
|
|
1485
|
+
def deserialize(cls, data: JsonDict) -> NoneType:
|
|
1486
|
+
assert data[".class"] == "NoneType"
|
|
1487
|
+
return NoneType()
|
|
1488
|
+
|
|
1489
|
+
def write(self, data: WriteBuffer) -> None:
|
|
1490
|
+
write_tag(data, NONE_TYPE)
|
|
1491
|
+
write_tag(data, END_TAG)
|
|
1492
|
+
|
|
1493
|
+
@classmethod
|
|
1494
|
+
def read(cls, data: ReadBuffer) -> NoneType:
|
|
1495
|
+
assert read_tag(data) == END_TAG
|
|
1496
|
+
return NoneType()
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
# NoneType used to be called NoneTyp so to avoid needlessly breaking
|
|
1500
|
+
# external plugins we keep that alias here.
|
|
1501
|
+
NoneTyp = NoneType
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
class ErasedType(ProperType):
|
|
1505
|
+
"""Placeholder for an erased type.
|
|
1506
|
+
|
|
1507
|
+
This is used during type inference. This has the special property that
|
|
1508
|
+
it is ignored during type inference.
|
|
1509
|
+
"""
|
|
1510
|
+
|
|
1511
|
+
__slots__ = ()
|
|
1512
|
+
|
|
1513
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1514
|
+
return visitor.visit_erased_type(self)
|
|
1515
|
+
|
|
1516
|
+
|
|
1517
|
+
class DeletedType(ProperType):
|
|
1518
|
+
"""Type of deleted variables.
|
|
1519
|
+
|
|
1520
|
+
These can be used as lvalues but not rvalues.
|
|
1521
|
+
"""
|
|
1522
|
+
|
|
1523
|
+
__slots__ = ("source",)
|
|
1524
|
+
|
|
1525
|
+
source: str | None # May be None; name that generated this value
|
|
1526
|
+
|
|
1527
|
+
def __init__(self, source: str | None = None, line: int = -1, column: int = -1) -> None:
|
|
1528
|
+
super().__init__(line, column)
|
|
1529
|
+
self.source = source
|
|
1530
|
+
|
|
1531
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1532
|
+
return visitor.visit_deleted_type(self)
|
|
1533
|
+
|
|
1534
|
+
def serialize(self) -> JsonDict:
|
|
1535
|
+
return {".class": "DeletedType", "source": self.source}
|
|
1536
|
+
|
|
1537
|
+
@classmethod
|
|
1538
|
+
def deserialize(cls, data: JsonDict) -> DeletedType:
|
|
1539
|
+
assert data[".class"] == "DeletedType"
|
|
1540
|
+
return DeletedType(data["source"])
|
|
1541
|
+
|
|
1542
|
+
def write(self, data: WriteBuffer) -> None:
|
|
1543
|
+
write_tag(data, DELETED_TYPE)
|
|
1544
|
+
write_str_opt(data, self.source)
|
|
1545
|
+
write_tag(data, END_TAG)
|
|
1546
|
+
|
|
1547
|
+
@classmethod
|
|
1548
|
+
def read(cls, data: ReadBuffer) -> DeletedType:
|
|
1549
|
+
ret = DeletedType(read_str_opt(data))
|
|
1550
|
+
assert read_tag(data) == END_TAG
|
|
1551
|
+
return ret
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
# Fake TypeInfo to be used as a placeholder during Instance de-serialization.
|
|
1555
|
+
NOT_READY: Final = mypy.nodes.FakeInfo("De-serialization failure: TypeInfo not fixed")
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
class ExtraAttrs:
|
|
1559
|
+
"""Summary of module attributes and types.
|
|
1560
|
+
|
|
1561
|
+
This is used for instances of types.ModuleType, because they can have different
|
|
1562
|
+
attributes per instance, and for type narrowing with hasattr() checks.
|
|
1563
|
+
"""
|
|
1564
|
+
|
|
1565
|
+
def __init__(
|
|
1566
|
+
self,
|
|
1567
|
+
attrs: dict[str, Type],
|
|
1568
|
+
immutable: set[str] | None = None,
|
|
1569
|
+
mod_name: str | None = None,
|
|
1570
|
+
) -> None:
|
|
1571
|
+
self.attrs = attrs
|
|
1572
|
+
if immutable is None:
|
|
1573
|
+
immutable = set()
|
|
1574
|
+
self.immutable = immutable
|
|
1575
|
+
self.mod_name = mod_name
|
|
1576
|
+
|
|
1577
|
+
def __hash__(self) -> int:
|
|
1578
|
+
return hash((tuple(self.attrs.items()), tuple(sorted(self.immutable))))
|
|
1579
|
+
|
|
1580
|
+
def __eq__(self, other: object) -> bool:
|
|
1581
|
+
if not isinstance(other, ExtraAttrs):
|
|
1582
|
+
return NotImplemented
|
|
1583
|
+
return self.attrs == other.attrs and self.immutable == other.immutable
|
|
1584
|
+
|
|
1585
|
+
def copy(self) -> ExtraAttrs:
|
|
1586
|
+
return ExtraAttrs(self.attrs.copy(), self.immutable.copy(), self.mod_name)
|
|
1587
|
+
|
|
1588
|
+
def __repr__(self) -> str:
|
|
1589
|
+
return f"ExtraAttrs({self.attrs!r}, {self.immutable!r}, {self.mod_name!r})"
|
|
1590
|
+
|
|
1591
|
+
def serialize(self) -> JsonDict:
|
|
1592
|
+
return {
|
|
1593
|
+
".class": "ExtraAttrs",
|
|
1594
|
+
"attrs": {k: v.serialize() for k, v in self.attrs.items()},
|
|
1595
|
+
"immutable": sorted(self.immutable),
|
|
1596
|
+
"mod_name": self.mod_name,
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
@classmethod
|
|
1600
|
+
def deserialize(cls, data: JsonDict) -> ExtraAttrs:
|
|
1601
|
+
assert data[".class"] == "ExtraAttrs"
|
|
1602
|
+
return ExtraAttrs(
|
|
1603
|
+
{k: deserialize_type(v) for k, v in data["attrs"].items()},
|
|
1604
|
+
set(data["immutable"]),
|
|
1605
|
+
data["mod_name"],
|
|
1606
|
+
)
|
|
1607
|
+
|
|
1608
|
+
def write(self, data: WriteBuffer) -> None:
|
|
1609
|
+
write_tag(data, EXTRA_ATTRS)
|
|
1610
|
+
write_type_map(data, self.attrs)
|
|
1611
|
+
write_str_list(data, sorted(self.immutable))
|
|
1612
|
+
write_str_opt(data, self.mod_name)
|
|
1613
|
+
write_tag(data, END_TAG)
|
|
1614
|
+
|
|
1615
|
+
@classmethod
|
|
1616
|
+
def read(cls, data: ReadBuffer) -> ExtraAttrs:
|
|
1617
|
+
ret = ExtraAttrs(read_type_map(data), set(read_str_list(data)), read_str_opt(data))
|
|
1618
|
+
assert read_tag(data) == END_TAG
|
|
1619
|
+
return ret
|
|
1620
|
+
|
|
1621
|
+
|
|
1622
|
+
class Instance(ProperType):
|
|
1623
|
+
"""An instance type of form C[T1, ..., Tn].
|
|
1624
|
+
|
|
1625
|
+
The list of type variables may be empty.
|
|
1626
|
+
|
|
1627
|
+
Several types have fallbacks to `Instance`, because in Python everything is an object
|
|
1628
|
+
and this concept is impossible to express without intersection types. We therefore use
|
|
1629
|
+
fallbacks for all "non-special" (like UninhabitedType, ErasedType etc) types.
|
|
1630
|
+
"""
|
|
1631
|
+
|
|
1632
|
+
__slots__ = ("type", "args", "invalid", "type_ref", "last_known_value", "_hash", "extra_attrs")
|
|
1633
|
+
|
|
1634
|
+
def __init__(
|
|
1635
|
+
self,
|
|
1636
|
+
typ: mypy.nodes.TypeInfo,
|
|
1637
|
+
args: Sequence[Type],
|
|
1638
|
+
line: int = -1,
|
|
1639
|
+
column: int = -1,
|
|
1640
|
+
*,
|
|
1641
|
+
last_known_value: LiteralType | None = None,
|
|
1642
|
+
extra_attrs: ExtraAttrs | None = None,
|
|
1643
|
+
) -> None:
|
|
1644
|
+
super().__init__(line, column)
|
|
1645
|
+
self.type = typ
|
|
1646
|
+
self.args = tuple(args)
|
|
1647
|
+
self.type_ref: str | None = None
|
|
1648
|
+
|
|
1649
|
+
# This field keeps track of the underlying Literal[...] value associated with
|
|
1650
|
+
# this instance, if one is known.
|
|
1651
|
+
#
|
|
1652
|
+
# This field is set whenever possible within expressions, but is erased upon
|
|
1653
|
+
# variable assignment (see erasetype.remove_instance_last_known_values) unless
|
|
1654
|
+
# the variable is declared to be final.
|
|
1655
|
+
#
|
|
1656
|
+
# For example, consider the following program:
|
|
1657
|
+
#
|
|
1658
|
+
# a = 1
|
|
1659
|
+
# b: Final[int] = 2
|
|
1660
|
+
# c: Final = 3
|
|
1661
|
+
# print(a + b + c + 4)
|
|
1662
|
+
#
|
|
1663
|
+
# The 'Instance' objects associated with the expressions '1', '2', '3', and '4' will
|
|
1664
|
+
# have last_known_values of type Literal[1], Literal[2], Literal[3], and Literal[4]
|
|
1665
|
+
# respectively. However, the Instance object assigned to 'a' and 'b' will have their
|
|
1666
|
+
# last_known_value erased: variable 'a' is mutable; variable 'b' was declared to be
|
|
1667
|
+
# specifically an int.
|
|
1668
|
+
#
|
|
1669
|
+
# Or more broadly, this field lets this Instance "remember" its original declaration
|
|
1670
|
+
# when applicable. We want this behavior because we want implicit Final declarations
|
|
1671
|
+
# to act pretty much identically with constants: we should be able to replace any
|
|
1672
|
+
# places where we use some Final variable with the original value and get the same
|
|
1673
|
+
# type-checking behavior. For example, we want this program:
|
|
1674
|
+
#
|
|
1675
|
+
# def expects_literal(x: Literal[3]) -> None: pass
|
|
1676
|
+
# var: Final = 3
|
|
1677
|
+
# expects_literal(var)
|
|
1678
|
+
#
|
|
1679
|
+
# ...to type-check in the exact same way as if we had written the program like this:
|
|
1680
|
+
#
|
|
1681
|
+
# def expects_literal(x: Literal[3]) -> None: pass
|
|
1682
|
+
# expects_literal(3)
|
|
1683
|
+
#
|
|
1684
|
+
# In order to make this work (especially with literal types), we need var's type
|
|
1685
|
+
# (an Instance) to remember the "original" value.
|
|
1686
|
+
#
|
|
1687
|
+
# Preserving this value within expressions is useful for similar reasons.
|
|
1688
|
+
#
|
|
1689
|
+
# Currently most of mypy will ignore this field and will continue to treat this type like
|
|
1690
|
+
# a regular Instance. We end up using this field only when we are explicitly within a
|
|
1691
|
+
# Literal context.
|
|
1692
|
+
self.last_known_value = last_known_value
|
|
1693
|
+
|
|
1694
|
+
# Cached hash value
|
|
1695
|
+
self._hash = -1
|
|
1696
|
+
|
|
1697
|
+
# Additional attributes defined per instance of this type. For example modules
|
|
1698
|
+
# have different attributes per instance of types.ModuleType.
|
|
1699
|
+
self.extra_attrs = extra_attrs
|
|
1700
|
+
|
|
1701
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
1702
|
+
return visitor.visit_instance(self)
|
|
1703
|
+
|
|
1704
|
+
def __hash__(self) -> int:
|
|
1705
|
+
if self._hash == -1:
|
|
1706
|
+
self._hash = hash((self.type, self.args, self.last_known_value, self.extra_attrs))
|
|
1707
|
+
return self._hash
|
|
1708
|
+
|
|
1709
|
+
def __eq__(self, other: object) -> bool:
|
|
1710
|
+
if not isinstance(other, Instance):
|
|
1711
|
+
return NotImplemented
|
|
1712
|
+
return (
|
|
1713
|
+
self.type == other.type
|
|
1714
|
+
and self.args == other.args
|
|
1715
|
+
and self.last_known_value == other.last_known_value
|
|
1716
|
+
and self.extra_attrs == other.extra_attrs
|
|
1717
|
+
)
|
|
1718
|
+
|
|
1719
|
+
def serialize(self) -> JsonDict | str:
|
|
1720
|
+
assert self.type is not None
|
|
1721
|
+
type_ref = self.type.fullname
|
|
1722
|
+
if not self.args and not self.last_known_value and not self.extra_attrs:
|
|
1723
|
+
return type_ref
|
|
1724
|
+
data: JsonDict = {
|
|
1725
|
+
".class": "Instance",
|
|
1726
|
+
"type_ref": type_ref,
|
|
1727
|
+
"args": [arg.serialize() for arg in self.args],
|
|
1728
|
+
}
|
|
1729
|
+
if self.last_known_value is not None:
|
|
1730
|
+
data["last_known_value"] = self.last_known_value.serialize()
|
|
1731
|
+
data["extra_attrs"] = self.extra_attrs.serialize() if self.extra_attrs else None
|
|
1732
|
+
return data
|
|
1733
|
+
|
|
1734
|
+
@classmethod
|
|
1735
|
+
def deserialize(cls, data: JsonDict | str) -> Instance:
|
|
1736
|
+
if isinstance(data, str):
|
|
1737
|
+
inst = Instance(NOT_READY, [])
|
|
1738
|
+
inst.type_ref = data
|
|
1739
|
+
return inst
|
|
1740
|
+
assert data[".class"] == "Instance"
|
|
1741
|
+
args: list[Type] = []
|
|
1742
|
+
if "args" in data:
|
|
1743
|
+
args_list = data["args"]
|
|
1744
|
+
assert isinstance(args_list, list)
|
|
1745
|
+
args = [deserialize_type(arg) for arg in args_list]
|
|
1746
|
+
inst = Instance(NOT_READY, args)
|
|
1747
|
+
inst.type_ref = data["type_ref"] # Will be fixed up by fixup.py later.
|
|
1748
|
+
if "last_known_value" in data:
|
|
1749
|
+
inst.last_known_value = LiteralType.deserialize(data["last_known_value"])
|
|
1750
|
+
if data.get("extra_attrs") is not None:
|
|
1751
|
+
inst.extra_attrs = ExtraAttrs.deserialize(data["extra_attrs"])
|
|
1752
|
+
return inst
|
|
1753
|
+
|
|
1754
|
+
def write(self, data: WriteBuffer) -> None:
|
|
1755
|
+
write_tag(data, INSTANCE)
|
|
1756
|
+
if not self.args and not self.last_known_value and not self.extra_attrs:
|
|
1757
|
+
type_ref = self.type.fullname
|
|
1758
|
+
if type_ref == "builtins.str":
|
|
1759
|
+
write_tag(data, INSTANCE_STR)
|
|
1760
|
+
elif type_ref == "builtins.function":
|
|
1761
|
+
write_tag(data, INSTANCE_FUNCTION)
|
|
1762
|
+
elif type_ref == "builtins.int":
|
|
1763
|
+
write_tag(data, INSTANCE_INT)
|
|
1764
|
+
elif type_ref == "builtins.bool":
|
|
1765
|
+
write_tag(data, INSTANCE_BOOL)
|
|
1766
|
+
elif type_ref == "builtins.object":
|
|
1767
|
+
write_tag(data, INSTANCE_OBJECT)
|
|
1768
|
+
else:
|
|
1769
|
+
write_tag(data, INSTANCE_SIMPLE)
|
|
1770
|
+
write_str_bare(data, type_ref)
|
|
1771
|
+
return
|
|
1772
|
+
write_tag(data, INSTANCE_GENERIC)
|
|
1773
|
+
write_str(data, self.type.fullname)
|
|
1774
|
+
write_type_list(data, self.args)
|
|
1775
|
+
write_type_opt(data, self.last_known_value)
|
|
1776
|
+
if self.extra_attrs is None:
|
|
1777
|
+
write_tag(data, LITERAL_NONE)
|
|
1778
|
+
else:
|
|
1779
|
+
self.extra_attrs.write(data)
|
|
1780
|
+
write_tag(data, END_TAG)
|
|
1781
|
+
|
|
1782
|
+
@classmethod
|
|
1783
|
+
def read(cls, data: ReadBuffer) -> Instance:
|
|
1784
|
+
tag = read_tag(data)
|
|
1785
|
+
# This is quite verbose, but this is very hot code, so we are not
|
|
1786
|
+
# using dictionary lookups here.
|
|
1787
|
+
if tag == INSTANCE_STR:
|
|
1788
|
+
if instance_cache.str_type is None:
|
|
1789
|
+
instance_cache.str_type = Instance(NOT_READY, [])
|
|
1790
|
+
instance_cache.str_type.type_ref = "builtins.str"
|
|
1791
|
+
return instance_cache.str_type
|
|
1792
|
+
if tag == INSTANCE_FUNCTION:
|
|
1793
|
+
if instance_cache.function_type is None:
|
|
1794
|
+
instance_cache.function_type = Instance(NOT_READY, [])
|
|
1795
|
+
instance_cache.function_type.type_ref = "builtins.function"
|
|
1796
|
+
return instance_cache.function_type
|
|
1797
|
+
if tag == INSTANCE_INT:
|
|
1798
|
+
if instance_cache.int_type is None:
|
|
1799
|
+
instance_cache.int_type = Instance(NOT_READY, [])
|
|
1800
|
+
instance_cache.int_type.type_ref = "builtins.int"
|
|
1801
|
+
return instance_cache.int_type
|
|
1802
|
+
if tag == INSTANCE_BOOL:
|
|
1803
|
+
if instance_cache.bool_type is None:
|
|
1804
|
+
instance_cache.bool_type = Instance(NOT_READY, [])
|
|
1805
|
+
instance_cache.bool_type.type_ref = "builtins.bool"
|
|
1806
|
+
return instance_cache.bool_type
|
|
1807
|
+
if tag == INSTANCE_OBJECT:
|
|
1808
|
+
if instance_cache.object_type is None:
|
|
1809
|
+
instance_cache.object_type = Instance(NOT_READY, [])
|
|
1810
|
+
instance_cache.object_type.type_ref = "builtins.object"
|
|
1811
|
+
return instance_cache.object_type
|
|
1812
|
+
if tag == INSTANCE_SIMPLE:
|
|
1813
|
+
inst = Instance(NOT_READY, [])
|
|
1814
|
+
inst.type_ref = read_str_bare(data)
|
|
1815
|
+
return inst
|
|
1816
|
+
assert tag == INSTANCE_GENERIC
|
|
1817
|
+
type_ref = read_str(data)
|
|
1818
|
+
inst = Instance(NOT_READY, read_type_list(data))
|
|
1819
|
+
inst.type_ref = type_ref
|
|
1820
|
+
tag = read_tag(data)
|
|
1821
|
+
if tag != LITERAL_NONE:
|
|
1822
|
+
assert tag == LITERAL_TYPE
|
|
1823
|
+
inst.last_known_value = LiteralType.read(data)
|
|
1824
|
+
tag = read_tag(data)
|
|
1825
|
+
if tag != LITERAL_NONE:
|
|
1826
|
+
assert tag == EXTRA_ATTRS
|
|
1827
|
+
inst.extra_attrs = ExtraAttrs.read(data)
|
|
1828
|
+
assert read_tag(data) == END_TAG
|
|
1829
|
+
return inst
|
|
1830
|
+
|
|
1831
|
+
def copy_modified(
|
|
1832
|
+
self,
|
|
1833
|
+
*,
|
|
1834
|
+
args: Bogus[list[Type]] = _dummy,
|
|
1835
|
+
last_known_value: Bogus[LiteralType | None] = _dummy,
|
|
1836
|
+
) -> Instance:
|
|
1837
|
+
new = Instance(
|
|
1838
|
+
typ=self.type,
|
|
1839
|
+
args=args if args is not _dummy else self.args,
|
|
1840
|
+
line=self.line,
|
|
1841
|
+
column=self.column,
|
|
1842
|
+
last_known_value=(
|
|
1843
|
+
last_known_value if last_known_value is not _dummy else self.last_known_value
|
|
1844
|
+
),
|
|
1845
|
+
extra_attrs=self.extra_attrs,
|
|
1846
|
+
)
|
|
1847
|
+
new.can_be_true = self.can_be_true
|
|
1848
|
+
new.can_be_false = self.can_be_false
|
|
1849
|
+
return new
|
|
1850
|
+
|
|
1851
|
+
def copy_with_extra_attr(self, name: str, typ: Type) -> Instance:
|
|
1852
|
+
if self.extra_attrs:
|
|
1853
|
+
existing_attrs = self.extra_attrs.copy()
|
|
1854
|
+
else:
|
|
1855
|
+
existing_attrs = ExtraAttrs({}, set(), None)
|
|
1856
|
+
existing_attrs.attrs[name] = typ
|
|
1857
|
+
new = self.copy_modified()
|
|
1858
|
+
new.extra_attrs = existing_attrs
|
|
1859
|
+
return new
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
class InstanceCache:
|
|
1863
|
+
def __init__(self) -> None:
|
|
1864
|
+
self.str_type: Instance | None = None
|
|
1865
|
+
self.function_type: Instance | None = None
|
|
1866
|
+
self.int_type: Instance | None = None
|
|
1867
|
+
self.bool_type: Instance | None = None
|
|
1868
|
+
self.object_type: Instance | None = None
|
|
1869
|
+
|
|
1870
|
+
def reset(self) -> None:
|
|
1871
|
+
self.str_type = None
|
|
1872
|
+
self.function_type = None
|
|
1873
|
+
self.int_type = None
|
|
1874
|
+
self.bool_type = None
|
|
1875
|
+
self.object_type = None
|
|
1876
|
+
|
|
1877
|
+
|
|
1878
|
+
instance_cache: Final = InstanceCache()
|
|
1879
|
+
|
|
1880
|
+
|
|
1881
|
+
class FunctionLike(ProperType):
|
|
1882
|
+
"""Abstract base class for function types."""
|
|
1883
|
+
|
|
1884
|
+
__slots__ = ("fallback",)
|
|
1885
|
+
|
|
1886
|
+
fallback: Instance
|
|
1887
|
+
|
|
1888
|
+
def __init__(self, line: int = -1, column: int = -1) -> None:
|
|
1889
|
+
super().__init__(line, column)
|
|
1890
|
+
self._can_be_false = False
|
|
1891
|
+
|
|
1892
|
+
@abstractmethod
|
|
1893
|
+
def is_type_obj(self) -> bool:
|
|
1894
|
+
pass
|
|
1895
|
+
|
|
1896
|
+
@abstractmethod
|
|
1897
|
+
def type_object(self) -> mypy.nodes.TypeInfo:
|
|
1898
|
+
pass
|
|
1899
|
+
|
|
1900
|
+
@property
|
|
1901
|
+
@abstractmethod
|
|
1902
|
+
def items(self) -> list[CallableType]:
|
|
1903
|
+
pass
|
|
1904
|
+
|
|
1905
|
+
@abstractmethod
|
|
1906
|
+
def with_name(self, name: str) -> FunctionLike:
|
|
1907
|
+
pass
|
|
1908
|
+
|
|
1909
|
+
@abstractmethod
|
|
1910
|
+
def get_name(self) -> str | None:
|
|
1911
|
+
pass
|
|
1912
|
+
|
|
1913
|
+
def bound(self) -> bool:
|
|
1914
|
+
return bool(self.items) and self.items[0].is_bound
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
class FormalArgument:
|
|
1918
|
+
def __init__(self, name: str | None, pos: int | None, typ: Type, required: bool) -> None:
|
|
1919
|
+
self.name = name
|
|
1920
|
+
self.pos = pos
|
|
1921
|
+
self.typ = typ
|
|
1922
|
+
self.required = required
|
|
1923
|
+
|
|
1924
|
+
def __eq__(self, other: object) -> bool:
|
|
1925
|
+
if not isinstance(other, FormalArgument):
|
|
1926
|
+
return NotImplemented
|
|
1927
|
+
return (
|
|
1928
|
+
self.name == other.name
|
|
1929
|
+
and self.pos == other.pos
|
|
1930
|
+
and self.typ == other.typ
|
|
1931
|
+
and self.required == other.required
|
|
1932
|
+
)
|
|
1933
|
+
|
|
1934
|
+
def __hash__(self) -> int:
|
|
1935
|
+
return hash((self.name, self.pos, self.typ, self.required))
|
|
1936
|
+
|
|
1937
|
+
|
|
1938
|
+
class Parameters(ProperType):
|
|
1939
|
+
"""Type that represents the parameters to a function.
|
|
1940
|
+
|
|
1941
|
+
Used for ParamSpec analysis. Note that by convention we handle this
|
|
1942
|
+
type as a Callable without return type, not as a "tuple with names",
|
|
1943
|
+
so that it behaves contravariantly, in particular [x: int] <: [int].
|
|
1944
|
+
"""
|
|
1945
|
+
|
|
1946
|
+
__slots__ = (
|
|
1947
|
+
"arg_types",
|
|
1948
|
+
"arg_kinds",
|
|
1949
|
+
"arg_names",
|
|
1950
|
+
"min_args",
|
|
1951
|
+
"is_ellipsis_args",
|
|
1952
|
+
# TODO: variables don't really belong here, but they are used to allow hacky support
|
|
1953
|
+
# for forall . Foo[[x: T], T] by capturing generic callable with ParamSpec, see #15909
|
|
1954
|
+
"variables",
|
|
1955
|
+
"imprecise_arg_kinds",
|
|
1956
|
+
)
|
|
1957
|
+
|
|
1958
|
+
def __init__(
|
|
1959
|
+
self,
|
|
1960
|
+
arg_types: Sequence[Type],
|
|
1961
|
+
arg_kinds: list[ArgKind],
|
|
1962
|
+
arg_names: Sequence[str | None],
|
|
1963
|
+
*,
|
|
1964
|
+
variables: Sequence[TypeVarLikeType] | None = None,
|
|
1965
|
+
is_ellipsis_args: bool = False,
|
|
1966
|
+
imprecise_arg_kinds: bool = False,
|
|
1967
|
+
line: int = -1,
|
|
1968
|
+
column: int = -1,
|
|
1969
|
+
) -> None:
|
|
1970
|
+
super().__init__(line, column)
|
|
1971
|
+
self.arg_types = list(arg_types)
|
|
1972
|
+
self.arg_kinds = arg_kinds
|
|
1973
|
+
self.arg_names = list(arg_names)
|
|
1974
|
+
assert len(arg_types) == len(arg_kinds) == len(arg_names)
|
|
1975
|
+
assert not any(isinstance(t, Parameters) for t in arg_types)
|
|
1976
|
+
self.min_args = arg_kinds.count(ARG_POS)
|
|
1977
|
+
self.is_ellipsis_args = is_ellipsis_args
|
|
1978
|
+
self.variables = variables or []
|
|
1979
|
+
self.imprecise_arg_kinds = imprecise_arg_kinds
|
|
1980
|
+
|
|
1981
|
+
def copy_modified(
|
|
1982
|
+
self,
|
|
1983
|
+
arg_types: Bogus[Sequence[Type]] = _dummy,
|
|
1984
|
+
arg_kinds: Bogus[list[ArgKind]] = _dummy,
|
|
1985
|
+
arg_names: Bogus[Sequence[str | None]] = _dummy,
|
|
1986
|
+
*,
|
|
1987
|
+
variables: Bogus[Sequence[TypeVarLikeType]] = _dummy,
|
|
1988
|
+
is_ellipsis_args: Bogus[bool] = _dummy,
|
|
1989
|
+
imprecise_arg_kinds: Bogus[bool] = _dummy,
|
|
1990
|
+
) -> Parameters:
|
|
1991
|
+
return Parameters(
|
|
1992
|
+
arg_types=arg_types if arg_types is not _dummy else self.arg_types,
|
|
1993
|
+
arg_kinds=arg_kinds if arg_kinds is not _dummy else self.arg_kinds,
|
|
1994
|
+
arg_names=arg_names if arg_names is not _dummy else self.arg_names,
|
|
1995
|
+
is_ellipsis_args=(
|
|
1996
|
+
is_ellipsis_args if is_ellipsis_args is not _dummy else self.is_ellipsis_args
|
|
1997
|
+
),
|
|
1998
|
+
variables=variables if variables is not _dummy else self.variables,
|
|
1999
|
+
imprecise_arg_kinds=(
|
|
2000
|
+
imprecise_arg_kinds
|
|
2001
|
+
if imprecise_arg_kinds is not _dummy
|
|
2002
|
+
else self.imprecise_arg_kinds
|
|
2003
|
+
),
|
|
2004
|
+
)
|
|
2005
|
+
|
|
2006
|
+
# TODO: here is a lot of code duplication with Callable type, fix this.
|
|
2007
|
+
def var_arg(self) -> FormalArgument | None:
|
|
2008
|
+
"""The formal argument for *args."""
|
|
2009
|
+
for position, (type, kind) in enumerate(zip(self.arg_types, self.arg_kinds)):
|
|
2010
|
+
if kind == ARG_STAR:
|
|
2011
|
+
return FormalArgument(None, position, type, False)
|
|
2012
|
+
return None
|
|
2013
|
+
|
|
2014
|
+
def kw_arg(self) -> FormalArgument | None:
|
|
2015
|
+
"""The formal argument for **kwargs."""
|
|
2016
|
+
for position, (type, kind) in enumerate(zip(self.arg_types, self.arg_kinds)):
|
|
2017
|
+
if kind == ARG_STAR2:
|
|
2018
|
+
return FormalArgument(None, position, type, False)
|
|
2019
|
+
return None
|
|
2020
|
+
|
|
2021
|
+
def formal_arguments(self, include_star_args: bool = False) -> list[FormalArgument]:
|
|
2022
|
+
"""Yields the formal arguments corresponding to this callable, ignoring *arg and **kwargs.
|
|
2023
|
+
|
|
2024
|
+
To handle *args and **kwargs, use the 'callable.var_args' and 'callable.kw_args' fields,
|
|
2025
|
+
if they are not None.
|
|
2026
|
+
|
|
2027
|
+
If you really want to include star args in the yielded output, set the
|
|
2028
|
+
'include_star_args' parameter to 'True'."""
|
|
2029
|
+
args = []
|
|
2030
|
+
done_with_positional = False
|
|
2031
|
+
for i in range(len(self.arg_types)):
|
|
2032
|
+
kind = self.arg_kinds[i]
|
|
2033
|
+
if kind.is_named() or kind.is_star():
|
|
2034
|
+
done_with_positional = True
|
|
2035
|
+
if not include_star_args and kind.is_star():
|
|
2036
|
+
continue
|
|
2037
|
+
|
|
2038
|
+
required = kind.is_required()
|
|
2039
|
+
pos = None if done_with_positional else i
|
|
2040
|
+
arg = FormalArgument(self.arg_names[i], pos, self.arg_types[i], required)
|
|
2041
|
+
args.append(arg)
|
|
2042
|
+
return args
|
|
2043
|
+
|
|
2044
|
+
def argument_by_name(self, name: str | None) -> FormalArgument | None:
|
|
2045
|
+
if name is None:
|
|
2046
|
+
return None
|
|
2047
|
+
seen_star = False
|
|
2048
|
+
for i, (arg_name, kind, typ) in enumerate(
|
|
2049
|
+
zip(self.arg_names, self.arg_kinds, self.arg_types)
|
|
2050
|
+
):
|
|
2051
|
+
# No more positional arguments after these.
|
|
2052
|
+
if kind.is_named() or kind.is_star():
|
|
2053
|
+
seen_star = True
|
|
2054
|
+
if kind.is_star():
|
|
2055
|
+
continue
|
|
2056
|
+
if arg_name == name:
|
|
2057
|
+
position = None if seen_star else i
|
|
2058
|
+
return FormalArgument(name, position, typ, kind.is_required())
|
|
2059
|
+
return self.try_synthesizing_arg_from_kwarg(name)
|
|
2060
|
+
|
|
2061
|
+
def argument_by_position(self, position: int | None) -> FormalArgument | None:
|
|
2062
|
+
if position is None:
|
|
2063
|
+
return None
|
|
2064
|
+
if position >= len(self.arg_names):
|
|
2065
|
+
return self.try_synthesizing_arg_from_vararg(position)
|
|
2066
|
+
name, kind, typ = (
|
|
2067
|
+
self.arg_names[position],
|
|
2068
|
+
self.arg_kinds[position],
|
|
2069
|
+
self.arg_types[position],
|
|
2070
|
+
)
|
|
2071
|
+
if kind.is_positional():
|
|
2072
|
+
return FormalArgument(name, position, typ, kind == ARG_POS)
|
|
2073
|
+
else:
|
|
2074
|
+
return self.try_synthesizing_arg_from_vararg(position)
|
|
2075
|
+
|
|
2076
|
+
def try_synthesizing_arg_from_kwarg(self, name: str | None) -> FormalArgument | None:
|
|
2077
|
+
kw_arg = self.kw_arg()
|
|
2078
|
+
if kw_arg is not None:
|
|
2079
|
+
return FormalArgument(name, None, kw_arg.typ, False)
|
|
2080
|
+
else:
|
|
2081
|
+
return None
|
|
2082
|
+
|
|
2083
|
+
def try_synthesizing_arg_from_vararg(self, position: int | None) -> FormalArgument | None:
|
|
2084
|
+
var_arg = self.var_arg()
|
|
2085
|
+
if var_arg is not None:
|
|
2086
|
+
return FormalArgument(None, position, var_arg.typ, False)
|
|
2087
|
+
else:
|
|
2088
|
+
return None
|
|
2089
|
+
|
|
2090
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
2091
|
+
return visitor.visit_parameters(self)
|
|
2092
|
+
|
|
2093
|
+
def serialize(self) -> JsonDict:
|
|
2094
|
+
return {
|
|
2095
|
+
".class": "Parameters",
|
|
2096
|
+
"arg_types": [t.serialize() for t in self.arg_types],
|
|
2097
|
+
"arg_kinds": [int(x.value) for x in self.arg_kinds],
|
|
2098
|
+
"arg_names": self.arg_names,
|
|
2099
|
+
"variables": [tv.serialize() for tv in self.variables],
|
|
2100
|
+
"imprecise_arg_kinds": self.imprecise_arg_kinds,
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
@classmethod
|
|
2104
|
+
def deserialize(cls, data: JsonDict) -> Parameters:
|
|
2105
|
+
assert data[".class"] == "Parameters"
|
|
2106
|
+
return Parameters(
|
|
2107
|
+
[deserialize_type(t) for t in data["arg_types"]],
|
|
2108
|
+
# This is a micro-optimization until mypyc gets dedicated enum support. Otherwise,
|
|
2109
|
+
# we would spend ~20% of types deserialization time in Enum.__call__().
|
|
2110
|
+
[ARG_KINDS[x] for x in data["arg_kinds"]],
|
|
2111
|
+
data["arg_names"],
|
|
2112
|
+
variables=[cast(TypeVarLikeType, deserialize_type(v)) for v in data["variables"]],
|
|
2113
|
+
imprecise_arg_kinds=data["imprecise_arg_kinds"],
|
|
2114
|
+
)
|
|
2115
|
+
|
|
2116
|
+
def write(self, data: WriteBuffer) -> None:
|
|
2117
|
+
write_tag(data, PARAMETERS)
|
|
2118
|
+
write_type_list(data, self.arg_types)
|
|
2119
|
+
write_int_list(data, [int(x.value) for x in self.arg_kinds])
|
|
2120
|
+
write_str_opt_list(data, self.arg_names)
|
|
2121
|
+
write_type_list(data, self.variables)
|
|
2122
|
+
write_bool(data, self.imprecise_arg_kinds)
|
|
2123
|
+
write_tag(data, END_TAG)
|
|
2124
|
+
|
|
2125
|
+
@classmethod
|
|
2126
|
+
def read(cls, data: ReadBuffer) -> Parameters:
|
|
2127
|
+
ret = Parameters(
|
|
2128
|
+
read_type_list(data),
|
|
2129
|
+
# This is a micro-optimization until mypyc gets dedicated enum support. Otherwise,
|
|
2130
|
+
# we would spend ~20% of types deserialization time in Enum.__call__().
|
|
2131
|
+
[ARG_KINDS[ak] for ak in read_int_list(data)],
|
|
2132
|
+
read_str_opt_list(data),
|
|
2133
|
+
variables=read_type_var_likes(data),
|
|
2134
|
+
imprecise_arg_kinds=read_bool(data),
|
|
2135
|
+
)
|
|
2136
|
+
assert read_tag(data) == END_TAG
|
|
2137
|
+
return ret
|
|
2138
|
+
|
|
2139
|
+
def __hash__(self) -> int:
|
|
2140
|
+
return hash(
|
|
2141
|
+
(
|
|
2142
|
+
self.is_ellipsis_args,
|
|
2143
|
+
tuple(self.arg_types),
|
|
2144
|
+
tuple(self.arg_names),
|
|
2145
|
+
tuple(self.arg_kinds),
|
|
2146
|
+
)
|
|
2147
|
+
)
|
|
2148
|
+
|
|
2149
|
+
def __eq__(self, other: object) -> bool:
|
|
2150
|
+
if isinstance(other, Parameters):
|
|
2151
|
+
return (
|
|
2152
|
+
self.arg_types == other.arg_types
|
|
2153
|
+
and self.arg_names == other.arg_names
|
|
2154
|
+
and self.arg_kinds == other.arg_kinds
|
|
2155
|
+
and self.is_ellipsis_args == other.is_ellipsis_args
|
|
2156
|
+
)
|
|
2157
|
+
else:
|
|
2158
|
+
return NotImplemented
|
|
2159
|
+
|
|
2160
|
+
|
|
2161
|
+
CT = TypeVar("CT", bound="CallableType")
|
|
2162
|
+
|
|
2163
|
+
|
|
2164
|
+
class CallableType(FunctionLike):
|
|
2165
|
+
"""Type of a non-overloaded callable object (such as function)."""
|
|
2166
|
+
|
|
2167
|
+
__slots__ = (
|
|
2168
|
+
"arg_types", # Types of function arguments
|
|
2169
|
+
"arg_kinds", # ARG_ constants
|
|
2170
|
+
"arg_names", # Argument names; None if not a keyword argument
|
|
2171
|
+
"ret_type", # Return value type
|
|
2172
|
+
"name", # Name (may be None; for error messages and plugins)
|
|
2173
|
+
"definition", # For error messages. May be None.
|
|
2174
|
+
"variables", # Type variables for a generic function
|
|
2175
|
+
"is_ellipsis_args", # Is this Callable[..., t] (with literal '...')?
|
|
2176
|
+
"implicit", # Was this type implicitly generated instead of explicitly
|
|
2177
|
+
# specified by the user?
|
|
2178
|
+
"special_sig", # Non-None for signatures that require special handling
|
|
2179
|
+
# (currently only values are 'dict' for a signature similar to
|
|
2180
|
+
# 'dict' and 'partial' for a `functools.partial` evaluation, and 'tuple')
|
|
2181
|
+
"from_type_type", # Was this callable generated by analyzing Type[...]
|
|
2182
|
+
# instantiation?
|
|
2183
|
+
"is_bound", # Is this a bound method?
|
|
2184
|
+
"type_guard", # T, if -> TypeGuard[T] (ret_type is bool in this case).
|
|
2185
|
+
"type_is", # T, if -> TypeIs[T] (ret_type is bool in this case).
|
|
2186
|
+
"from_concatenate", # whether this callable is from a concatenate object
|
|
2187
|
+
# (this is used for error messages)
|
|
2188
|
+
"imprecise_arg_kinds",
|
|
2189
|
+
"unpack_kwargs", # Was an Unpack[...] with **kwargs used to define this callable?
|
|
2190
|
+
"instance_type", # Real underlying type of a type object. This is different from
|
|
2191
|
+
# ret_type in case we have e.g. a custom __new__() return annotation.
|
|
2192
|
+
)
|
|
2193
|
+
|
|
2194
|
+
def __init__(
|
|
2195
|
+
self,
|
|
2196
|
+
# maybe this should be refactored to take a Parameters object
|
|
2197
|
+
arg_types: Sequence[Type],
|
|
2198
|
+
arg_kinds: list[ArgKind],
|
|
2199
|
+
arg_names: Sequence[str | None],
|
|
2200
|
+
ret_type: Type,
|
|
2201
|
+
fallback: Instance,
|
|
2202
|
+
name: str | None = None,
|
|
2203
|
+
definition: SymbolNode | None = None,
|
|
2204
|
+
variables: Sequence[TypeVarLikeType] | None = None,
|
|
2205
|
+
line: int = -1,
|
|
2206
|
+
column: int = -1,
|
|
2207
|
+
is_ellipsis_args: bool = False,
|
|
2208
|
+
implicit: bool = False,
|
|
2209
|
+
special_sig: str | None = None,
|
|
2210
|
+
from_type_type: bool = False,
|
|
2211
|
+
is_bound: bool = False,
|
|
2212
|
+
type_guard: Type | None = None,
|
|
2213
|
+
type_is: Type | None = None,
|
|
2214
|
+
from_concatenate: bool = False,
|
|
2215
|
+
imprecise_arg_kinds: bool = False,
|
|
2216
|
+
unpack_kwargs: bool = False,
|
|
2217
|
+
instance_type: ProperType | None = None,
|
|
2218
|
+
) -> None:
|
|
2219
|
+
super().__init__(line, column)
|
|
2220
|
+
assert len(arg_types) == len(arg_kinds) == len(arg_names)
|
|
2221
|
+
self.arg_types = list(arg_types)
|
|
2222
|
+
for t in self.arg_types:
|
|
2223
|
+
if isinstance(t, ParamSpecType):
|
|
2224
|
+
assert not t.prefix.arg_types
|
|
2225
|
+
# TODO: should we assert that only ARG_STAR contain ParamSpecType?
|
|
2226
|
+
# See testParamSpecJoin, that relies on passing e.g `P.args` as plain argument.
|
|
2227
|
+
self.arg_kinds = arg_kinds
|
|
2228
|
+
self.arg_names = list(arg_names)
|
|
2229
|
+
self.ret_type = ret_type
|
|
2230
|
+
self.fallback = fallback
|
|
2231
|
+
assert not name or "<bound method" not in name
|
|
2232
|
+
self.name = name
|
|
2233
|
+
# The rules for what exactly is considered a definition:
|
|
2234
|
+
# * If it is a non-decorated function, FuncDef is the definition
|
|
2235
|
+
# * If it is a decorated function, enclosing Decorator is the definition
|
|
2236
|
+
self.definition = definition
|
|
2237
|
+
self.variables: tuple[TypeVarLikeType, ...]
|
|
2238
|
+
if variables is None:
|
|
2239
|
+
self.variables = ()
|
|
2240
|
+
else:
|
|
2241
|
+
self.variables = tuple(variables)
|
|
2242
|
+
self.is_ellipsis_args = is_ellipsis_args
|
|
2243
|
+
self.implicit = implicit
|
|
2244
|
+
self.special_sig = special_sig
|
|
2245
|
+
self.from_type_type = from_type_type
|
|
2246
|
+
self.from_concatenate = from_concatenate
|
|
2247
|
+
self.imprecise_arg_kinds = imprecise_arg_kinds
|
|
2248
|
+
self.is_bound = is_bound
|
|
2249
|
+
self.type_guard = type_guard
|
|
2250
|
+
self.type_is = type_is
|
|
2251
|
+
self.unpack_kwargs = unpack_kwargs
|
|
2252
|
+
self.instance_type = instance_type
|
|
2253
|
+
|
|
2254
|
+
def copy_modified(
|
|
2255
|
+
self: CT,
|
|
2256
|
+
arg_types: Bogus[Sequence[Type]] = _dummy,
|
|
2257
|
+
arg_kinds: Bogus[list[ArgKind]] = _dummy,
|
|
2258
|
+
arg_names: Bogus[Sequence[str | None]] = _dummy,
|
|
2259
|
+
ret_type: Bogus[Type] = _dummy,
|
|
2260
|
+
fallback: Bogus[Instance] = _dummy,
|
|
2261
|
+
name: Bogus[str | None] = _dummy,
|
|
2262
|
+
definition: Bogus[SymbolNode | None] = _dummy,
|
|
2263
|
+
variables: Bogus[Sequence[TypeVarLikeType]] = _dummy,
|
|
2264
|
+
line: int = _dummy_int,
|
|
2265
|
+
column: int = _dummy_int,
|
|
2266
|
+
is_ellipsis_args: Bogus[bool] = _dummy,
|
|
2267
|
+
implicit: Bogus[bool] = _dummy,
|
|
2268
|
+
special_sig: Bogus[str | None] = _dummy,
|
|
2269
|
+
from_type_type: Bogus[bool] = _dummy,
|
|
2270
|
+
is_bound: Bogus[bool] = _dummy,
|
|
2271
|
+
type_guard: Bogus[Type | None] = _dummy,
|
|
2272
|
+
type_is: Bogus[Type | None] = _dummy,
|
|
2273
|
+
from_concatenate: Bogus[bool] = _dummy,
|
|
2274
|
+
imprecise_arg_kinds: Bogus[bool] = _dummy,
|
|
2275
|
+
unpack_kwargs: Bogus[bool] = _dummy,
|
|
2276
|
+
instance_type: Bogus[ProperType | None] = _dummy,
|
|
2277
|
+
) -> CT:
|
|
2278
|
+
modified = CallableType(
|
|
2279
|
+
arg_types=arg_types if arg_types is not _dummy else self.arg_types,
|
|
2280
|
+
arg_kinds=arg_kinds if arg_kinds is not _dummy else self.arg_kinds,
|
|
2281
|
+
arg_names=arg_names if arg_names is not _dummy else self.arg_names,
|
|
2282
|
+
ret_type=ret_type if ret_type is not _dummy else self.ret_type,
|
|
2283
|
+
fallback=fallback if fallback is not _dummy else self.fallback,
|
|
2284
|
+
name=name if name is not _dummy else self.name,
|
|
2285
|
+
definition=definition if definition is not _dummy else self.definition,
|
|
2286
|
+
variables=variables if variables is not _dummy else self.variables,
|
|
2287
|
+
line=line if line != _dummy_int else self.line,
|
|
2288
|
+
column=column if column != _dummy_int else self.column,
|
|
2289
|
+
is_ellipsis_args=(
|
|
2290
|
+
is_ellipsis_args if is_ellipsis_args is not _dummy else self.is_ellipsis_args
|
|
2291
|
+
),
|
|
2292
|
+
implicit=implicit if implicit is not _dummy else self.implicit,
|
|
2293
|
+
special_sig=special_sig if special_sig is not _dummy else self.special_sig,
|
|
2294
|
+
from_type_type=from_type_type if from_type_type is not _dummy else self.from_type_type,
|
|
2295
|
+
is_bound=is_bound if is_bound is not _dummy else self.is_bound,
|
|
2296
|
+
type_guard=type_guard if type_guard is not _dummy else self.type_guard,
|
|
2297
|
+
type_is=type_is if type_is is not _dummy else self.type_is,
|
|
2298
|
+
from_concatenate=(
|
|
2299
|
+
from_concatenate if from_concatenate is not _dummy else self.from_concatenate
|
|
2300
|
+
),
|
|
2301
|
+
imprecise_arg_kinds=(
|
|
2302
|
+
imprecise_arg_kinds
|
|
2303
|
+
if imprecise_arg_kinds is not _dummy
|
|
2304
|
+
else self.imprecise_arg_kinds
|
|
2305
|
+
),
|
|
2306
|
+
unpack_kwargs=unpack_kwargs if unpack_kwargs is not _dummy else self.unpack_kwargs,
|
|
2307
|
+
instance_type=instance_type if instance_type is not _dummy else self.instance_type,
|
|
2308
|
+
)
|
|
2309
|
+
# Optimization: Only NewTypes are supported as subtypes since
|
|
2310
|
+
# the class is effectively final, so we can use a cast safely.
|
|
2311
|
+
return cast(CT, modified)
|
|
2312
|
+
|
|
2313
|
+
def var_arg(self) -> FormalArgument | None:
|
|
2314
|
+
"""The formal argument for *args."""
|
|
2315
|
+
for position, (type, kind) in enumerate(zip(self.arg_types, self.arg_kinds)):
|
|
2316
|
+
if kind == ARG_STAR:
|
|
2317
|
+
return FormalArgument(None, position, type, False)
|
|
2318
|
+
return None
|
|
2319
|
+
|
|
2320
|
+
def kw_arg(self) -> FormalArgument | None:
|
|
2321
|
+
"""The formal argument for **kwargs."""
|
|
2322
|
+
for position, (type, kind) in enumerate(zip(self.arg_types, self.arg_kinds)):
|
|
2323
|
+
if kind == ARG_STAR2:
|
|
2324
|
+
return FormalArgument(None, position, type, False)
|
|
2325
|
+
return None
|
|
2326
|
+
|
|
2327
|
+
@property
|
|
2328
|
+
def min_args(self) -> int:
|
|
2329
|
+
return self.arg_kinds.count(ARG_POS)
|
|
2330
|
+
|
|
2331
|
+
@property
|
|
2332
|
+
def is_var_arg(self) -> bool:
|
|
2333
|
+
"""Does this callable have a *args argument?"""
|
|
2334
|
+
return ARG_STAR in self.arg_kinds
|
|
2335
|
+
|
|
2336
|
+
@property
|
|
2337
|
+
def is_kw_arg(self) -> bool:
|
|
2338
|
+
"""Does this callable have a **kwargs argument?"""
|
|
2339
|
+
return ARG_STAR2 in self.arg_kinds
|
|
2340
|
+
|
|
2341
|
+
def is_type_obj(self) -> bool:
|
|
2342
|
+
return self.fallback.type.is_metaclass() and not isinstance(
|
|
2343
|
+
get_proper_type(self.ret_type), UninhabitedType
|
|
2344
|
+
)
|
|
2345
|
+
|
|
2346
|
+
def get_instance_type(self, *, force_fallback: bool = False) -> ProperType:
|
|
2347
|
+
"""Get underlying type of a type object.
|
|
2348
|
+
|
|
2349
|
+
By default, this will return a precise self-type, essentially whatever is
|
|
2350
|
+
returned by fill_typevars(). Most notably this is a TupleType for named tuples.
|
|
2351
|
+
If an Instance fallback is required, use force_fallback=True.
|
|
2352
|
+
"""
|
|
2353
|
+
assert self.is_type_obj()
|
|
2354
|
+
if self.instance_type is not None:
|
|
2355
|
+
ret = self.instance_type
|
|
2356
|
+
else:
|
|
2357
|
+
# Fall back to historic behavior in case instance_type is not set. This
|
|
2358
|
+
# will avoid crashes on type objects generated by plugins, and on (unknown)
|
|
2359
|
+
# corner cases where is_type_obj() may "accidentally" return True.
|
|
2360
|
+
ret = get_proper_type(self.ret_type)
|
|
2361
|
+
if not force_fallback:
|
|
2362
|
+
return ret
|
|
2363
|
+
if isinstance(ret, TypeVarType):
|
|
2364
|
+
ret = get_proper_type(ret.upper_bound)
|
|
2365
|
+
if isinstance(ret, TupleType):
|
|
2366
|
+
ret = ret.partial_fallback
|
|
2367
|
+
if isinstance(ret, TypedDictType):
|
|
2368
|
+
ret = ret.fallback
|
|
2369
|
+
if isinstance(ret, LiteralType):
|
|
2370
|
+
ret = ret.fallback
|
|
2371
|
+
return ret
|
|
2372
|
+
|
|
2373
|
+
def type_object(self) -> mypy.nodes.TypeInfo:
|
|
2374
|
+
instance_type = self.get_instance_type(force_fallback=True)
|
|
2375
|
+
assert isinstance(instance_type, Instance)
|
|
2376
|
+
return instance_type.type
|
|
2377
|
+
|
|
2378
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
2379
|
+
return visitor.visit_callable_type(self)
|
|
2380
|
+
|
|
2381
|
+
def with_name(self, name: str) -> CallableType:
|
|
2382
|
+
"""Return a copy of this type with the specified name."""
|
|
2383
|
+
return self.copy_modified(name=name)
|
|
2384
|
+
|
|
2385
|
+
def get_name(self) -> str | None:
|
|
2386
|
+
return self.name
|
|
2387
|
+
|
|
2388
|
+
def max_possible_positional_args(self) -> int:
|
|
2389
|
+
"""Returns maximum number of positional arguments this method could possibly accept.
|
|
2390
|
+
|
|
2391
|
+
This takes into account *arg and **kwargs but excludes keyword-only args."""
|
|
2392
|
+
if self.is_var_arg or self.is_kw_arg:
|
|
2393
|
+
return sys.maxsize
|
|
2394
|
+
return sum(kind.is_positional() for kind in self.arg_kinds)
|
|
2395
|
+
|
|
2396
|
+
def formal_arguments(self, include_star_args: bool = False) -> list[FormalArgument]:
|
|
2397
|
+
"""Return a list of the formal arguments of this callable, ignoring *arg and **kwargs.
|
|
2398
|
+
|
|
2399
|
+
To handle *args and **kwargs, use the 'callable.var_args' and 'callable.kw_args' fields,
|
|
2400
|
+
if they are not None.
|
|
2401
|
+
|
|
2402
|
+
If you really want to include star args in the yielded output, set the
|
|
2403
|
+
'include_star_args' parameter to 'True'."""
|
|
2404
|
+
args = []
|
|
2405
|
+
done_with_positional = False
|
|
2406
|
+
for i in range(len(self.arg_types)):
|
|
2407
|
+
kind = self.arg_kinds[i]
|
|
2408
|
+
if kind.is_named() or kind.is_star():
|
|
2409
|
+
done_with_positional = True
|
|
2410
|
+
if not include_star_args and kind.is_star():
|
|
2411
|
+
continue
|
|
2412
|
+
|
|
2413
|
+
required = kind.is_required()
|
|
2414
|
+
pos = None if done_with_positional else i
|
|
2415
|
+
arg = FormalArgument(self.arg_names[i], pos, self.arg_types[i], required)
|
|
2416
|
+
args.append(arg)
|
|
2417
|
+
return args
|
|
2418
|
+
|
|
2419
|
+
def argument_by_name(self, name: str | None) -> FormalArgument | None:
|
|
2420
|
+
if name is None:
|
|
2421
|
+
return None
|
|
2422
|
+
seen_star = False
|
|
2423
|
+
for i, (arg_name, kind, typ) in enumerate(
|
|
2424
|
+
zip(self.arg_names, self.arg_kinds, self.arg_types)
|
|
2425
|
+
):
|
|
2426
|
+
# No more positional arguments after these.
|
|
2427
|
+
if kind.is_named() or kind.is_star():
|
|
2428
|
+
seen_star = True
|
|
2429
|
+
if kind.is_star():
|
|
2430
|
+
continue
|
|
2431
|
+
if arg_name == name:
|
|
2432
|
+
position = None if seen_star else i
|
|
2433
|
+
return FormalArgument(name, position, typ, kind.is_required())
|
|
2434
|
+
return self.try_synthesizing_arg_from_kwarg(name)
|
|
2435
|
+
|
|
2436
|
+
def argument_by_position(self, position: int | None) -> FormalArgument | None:
|
|
2437
|
+
if position is None:
|
|
2438
|
+
return None
|
|
2439
|
+
if position >= len(self.arg_names):
|
|
2440
|
+
return self.try_synthesizing_arg_from_vararg(position)
|
|
2441
|
+
name, kind, typ = (
|
|
2442
|
+
self.arg_names[position],
|
|
2443
|
+
self.arg_kinds[position],
|
|
2444
|
+
self.arg_types[position],
|
|
2445
|
+
)
|
|
2446
|
+
if kind.is_positional():
|
|
2447
|
+
return FormalArgument(name, position, typ, kind == ARG_POS)
|
|
2448
|
+
else:
|
|
2449
|
+
return self.try_synthesizing_arg_from_vararg(position)
|
|
2450
|
+
|
|
2451
|
+
def try_synthesizing_arg_from_kwarg(self, name: str | None) -> FormalArgument | None:
|
|
2452
|
+
kw_arg = self.kw_arg()
|
|
2453
|
+
if kw_arg is not None:
|
|
2454
|
+
return FormalArgument(name, None, kw_arg.typ, False)
|
|
2455
|
+
else:
|
|
2456
|
+
return None
|
|
2457
|
+
|
|
2458
|
+
def try_synthesizing_arg_from_vararg(self, position: int | None) -> FormalArgument | None:
|
|
2459
|
+
var_arg = self.var_arg()
|
|
2460
|
+
if var_arg is not None:
|
|
2461
|
+
return FormalArgument(None, position, var_arg.typ, False)
|
|
2462
|
+
else:
|
|
2463
|
+
return None
|
|
2464
|
+
|
|
2465
|
+
@property
|
|
2466
|
+
def items(self) -> list[CallableType]:
|
|
2467
|
+
return [self]
|
|
2468
|
+
|
|
2469
|
+
def is_generic(self) -> bool:
|
|
2470
|
+
return bool(self.variables)
|
|
2471
|
+
|
|
2472
|
+
def type_var_ids(self) -> list[TypeVarId]:
|
|
2473
|
+
a: list[TypeVarId] = []
|
|
2474
|
+
for tv in self.variables:
|
|
2475
|
+
a.append(tv.id)
|
|
2476
|
+
return a
|
|
2477
|
+
|
|
2478
|
+
def param_spec(self) -> ParamSpecType | None:
|
|
2479
|
+
"""Return ParamSpec if callable can be called with one.
|
|
2480
|
+
|
|
2481
|
+
A Callable accepting ParamSpec P args (*args, **kwargs) must have the
|
|
2482
|
+
two final parameters like this: *args: P.args, **kwargs: P.kwargs.
|
|
2483
|
+
"""
|
|
2484
|
+
if len(self.arg_types) < 2:
|
|
2485
|
+
return None
|
|
2486
|
+
if self.arg_kinds[-2] != ARG_STAR or self.arg_kinds[-1] != ARG_STAR2:
|
|
2487
|
+
return None
|
|
2488
|
+
arg_type = self.arg_types[-2]
|
|
2489
|
+
if not isinstance(arg_type, ParamSpecType):
|
|
2490
|
+
return None
|
|
2491
|
+
|
|
2492
|
+
# Prepend prefix for def f(prefix..., *args: P.args, **kwargs: P.kwargs) -> ...
|
|
2493
|
+
# TODO: confirm that all arg kinds are positional
|
|
2494
|
+
prefix = Parameters(self.arg_types[:-2], self.arg_kinds[:-2], self.arg_names[:-2])
|
|
2495
|
+
return arg_type.copy_modified(flavor=ParamSpecFlavor.BARE, prefix=prefix)
|
|
2496
|
+
|
|
2497
|
+
def normalize_trivial_unpack(self) -> None:
|
|
2498
|
+
# Normalize trivial unpack in var args as *args: *tuple[X, ...] -> *args: X in place.
|
|
2499
|
+
if self.is_var_arg:
|
|
2500
|
+
star_index = self.arg_kinds.index(ARG_STAR)
|
|
2501
|
+
star_type = self.arg_types[star_index]
|
|
2502
|
+
if isinstance(star_type, UnpackType):
|
|
2503
|
+
p_type = get_proper_type(star_type.type)
|
|
2504
|
+
if isinstance(p_type, Instance):
|
|
2505
|
+
assert p_type.type.fullname == "builtins.tuple"
|
|
2506
|
+
self.arg_types[star_index] = p_type.args[0]
|
|
2507
|
+
|
|
2508
|
+
def with_unpacked_kwargs(self) -> NormalizedCallableType:
|
|
2509
|
+
if not self.unpack_kwargs:
|
|
2510
|
+
return cast(NormalizedCallableType, self)
|
|
2511
|
+
last_type = get_proper_type(self.arg_types[-1])
|
|
2512
|
+
assert isinstance(last_type, TypedDictType)
|
|
2513
|
+
extra_kinds = [
|
|
2514
|
+
ArgKind.ARG_NAMED if name in last_type.required_keys else ArgKind.ARG_NAMED_OPT
|
|
2515
|
+
for name in last_type.items
|
|
2516
|
+
]
|
|
2517
|
+
new_arg_kinds = self.arg_kinds[:-1] + extra_kinds
|
|
2518
|
+
new_arg_names = self.arg_names[:-1] + list(last_type.items)
|
|
2519
|
+
new_arg_types = self.arg_types[:-1] + list(last_type.items.values())
|
|
2520
|
+
return NormalizedCallableType(
|
|
2521
|
+
self.copy_modified(
|
|
2522
|
+
arg_kinds=new_arg_kinds,
|
|
2523
|
+
arg_names=new_arg_names,
|
|
2524
|
+
arg_types=new_arg_types,
|
|
2525
|
+
unpack_kwargs=False,
|
|
2526
|
+
)
|
|
2527
|
+
)
|
|
2528
|
+
|
|
2529
|
+
def with_normalized_var_args(self) -> Self:
|
|
2530
|
+
var_arg = self.var_arg()
|
|
2531
|
+
if not var_arg or not isinstance(var_arg.typ, UnpackType):
|
|
2532
|
+
return self
|
|
2533
|
+
unpacked = get_proper_type(var_arg.typ.type)
|
|
2534
|
+
if not isinstance(unpacked, TupleType):
|
|
2535
|
+
# Note that we don't normalize *args: *tuple[X, ...] -> *args: X,
|
|
2536
|
+
# this should be done once in semanal_typeargs.py for user-defined types,
|
|
2537
|
+
# and we ourselves rarely construct such type.
|
|
2538
|
+
return self
|
|
2539
|
+
unpack_index = find_unpack_in_list(unpacked.items)
|
|
2540
|
+
if unpack_index == 0 and len(unpacked.items) > 1:
|
|
2541
|
+
# Already normalized.
|
|
2542
|
+
return self
|
|
2543
|
+
|
|
2544
|
+
# Boilerplate:
|
|
2545
|
+
var_arg_index = self.arg_kinds.index(ARG_STAR)
|
|
2546
|
+
types_prefix = self.arg_types[:var_arg_index]
|
|
2547
|
+
kinds_prefix = self.arg_kinds[:var_arg_index]
|
|
2548
|
+
names_prefix = self.arg_names[:var_arg_index]
|
|
2549
|
+
types_suffix = self.arg_types[var_arg_index + 1 :]
|
|
2550
|
+
kinds_suffix = self.arg_kinds[var_arg_index + 1 :]
|
|
2551
|
+
names_suffix = self.arg_names[var_arg_index + 1 :]
|
|
2552
|
+
no_name: str | None = None # to silence mypy
|
|
2553
|
+
|
|
2554
|
+
# Now we have something non-trivial to do.
|
|
2555
|
+
if unpack_index is None:
|
|
2556
|
+
# Plain *Tuple[X, Y, Z] -> replace with ARG_POS completely
|
|
2557
|
+
types_middle = unpacked.items
|
|
2558
|
+
kinds_middle = [ARG_POS] * len(unpacked.items)
|
|
2559
|
+
names_middle = [no_name] * len(unpacked.items)
|
|
2560
|
+
else:
|
|
2561
|
+
# *Tuple[X, *Ts, Y, Z] or *Tuple[X, *tuple[T, ...], X, Z], here
|
|
2562
|
+
# we replace the prefix by ARG_POS (this is how some places expect
|
|
2563
|
+
# Callables to be represented)
|
|
2564
|
+
nested_unpack = unpacked.items[unpack_index]
|
|
2565
|
+
assert isinstance(nested_unpack, UnpackType)
|
|
2566
|
+
nested_unpacked = get_proper_type(nested_unpack.type)
|
|
2567
|
+
if unpack_index == len(unpacked.items) - 1:
|
|
2568
|
+
# Normalize also single item tuples like
|
|
2569
|
+
# *args: *Tuple[*tuple[X, ...]] -> *args: X
|
|
2570
|
+
# *args: *Tuple[*Ts] -> *args: *Ts
|
|
2571
|
+
# This may be not strictly necessary, but these are very verbose.
|
|
2572
|
+
if isinstance(nested_unpacked, Instance):
|
|
2573
|
+
assert nested_unpacked.type.fullname == "builtins.tuple"
|
|
2574
|
+
new_unpack = nested_unpacked.args[0]
|
|
2575
|
+
else:
|
|
2576
|
+
if not isinstance(nested_unpacked, TypeVarTupleType):
|
|
2577
|
+
# We found a non-normalized tuple type, this means this method
|
|
2578
|
+
# is called during semantic analysis (e.g. from get_proper_type())
|
|
2579
|
+
# there is no point in normalizing callables at this stage.
|
|
2580
|
+
return self
|
|
2581
|
+
new_unpack = nested_unpack
|
|
2582
|
+
else:
|
|
2583
|
+
new_unpack = UnpackType(
|
|
2584
|
+
unpacked.copy_modified(items=unpacked.items[unpack_index:])
|
|
2585
|
+
)
|
|
2586
|
+
types_middle = unpacked.items[:unpack_index] + [new_unpack]
|
|
2587
|
+
kinds_middle = [ARG_POS] * unpack_index + [ARG_STAR]
|
|
2588
|
+
names_middle = [no_name] * unpack_index + [self.arg_names[var_arg_index]]
|
|
2589
|
+
return self.copy_modified(
|
|
2590
|
+
arg_types=types_prefix + types_middle + types_suffix,
|
|
2591
|
+
arg_kinds=kinds_prefix + kinds_middle + kinds_suffix,
|
|
2592
|
+
arg_names=names_prefix + names_middle + names_suffix,
|
|
2593
|
+
)
|
|
2594
|
+
|
|
2595
|
+
def __hash__(self) -> int:
|
|
2596
|
+
return hash(
|
|
2597
|
+
(
|
|
2598
|
+
self.ret_type,
|
|
2599
|
+
self.is_ellipsis_args,
|
|
2600
|
+
self.name,
|
|
2601
|
+
tuple(self.arg_types),
|
|
2602
|
+
tuple(self.arg_names),
|
|
2603
|
+
tuple(self.arg_kinds),
|
|
2604
|
+
self.fallback,
|
|
2605
|
+
)
|
|
2606
|
+
)
|
|
2607
|
+
|
|
2608
|
+
def __eq__(self, other: object) -> bool:
|
|
2609
|
+
if isinstance(other, CallableType):
|
|
2610
|
+
return (
|
|
2611
|
+
self.ret_type == other.ret_type
|
|
2612
|
+
and self.arg_types == other.arg_types
|
|
2613
|
+
and self.arg_names == other.arg_names
|
|
2614
|
+
and self.arg_kinds == other.arg_kinds
|
|
2615
|
+
and self.name == other.name
|
|
2616
|
+
and self.is_ellipsis_args == other.is_ellipsis_args
|
|
2617
|
+
and self.type_guard == other.type_guard
|
|
2618
|
+
and self.type_is == other.type_is
|
|
2619
|
+
and self.fallback == other.fallback
|
|
2620
|
+
)
|
|
2621
|
+
else:
|
|
2622
|
+
return NotImplemented
|
|
2623
|
+
|
|
2624
|
+
def serialize(self) -> JsonDict:
|
|
2625
|
+
# TODO: As an optimization, leave out everything related to
|
|
2626
|
+
# generic functions for non-generic functions.
|
|
2627
|
+
return {
|
|
2628
|
+
".class": "CallableType",
|
|
2629
|
+
"arg_types": [t.serialize() for t in self.arg_types],
|
|
2630
|
+
"arg_kinds": [int(x.value) for x in self.arg_kinds],
|
|
2631
|
+
"arg_names": self.arg_names,
|
|
2632
|
+
"ret_type": self.ret_type.serialize(),
|
|
2633
|
+
"fallback": self.fallback.serialize(),
|
|
2634
|
+
"name": self.name,
|
|
2635
|
+
# We don't serialize the definition (only used for error messages).
|
|
2636
|
+
"variables": [v.serialize() for v in self.variables],
|
|
2637
|
+
"is_ellipsis_args": self.is_ellipsis_args,
|
|
2638
|
+
"implicit": self.implicit,
|
|
2639
|
+
"is_bound": self.is_bound,
|
|
2640
|
+
"type_guard": self.type_guard.serialize() if self.type_guard is not None else None,
|
|
2641
|
+
"type_is": self.type_is.serialize() if self.type_is is not None else None,
|
|
2642
|
+
"from_concatenate": self.from_concatenate,
|
|
2643
|
+
"imprecise_arg_kinds": self.imprecise_arg_kinds,
|
|
2644
|
+
"unpack_kwargs": self.unpack_kwargs,
|
|
2645
|
+
"instance_type": (
|
|
2646
|
+
self.instance_type.serialize() if self.instance_type is not None else None
|
|
2647
|
+
),
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
@classmethod
|
|
2651
|
+
def deserialize(cls, data: JsonDict) -> CallableType:
|
|
2652
|
+
assert data[".class"] == "CallableType"
|
|
2653
|
+
# The .definition link is set in fixup.py.
|
|
2654
|
+
return CallableType(
|
|
2655
|
+
[deserialize_type(t) for t in data["arg_types"]],
|
|
2656
|
+
[ARG_KINDS[x] for x in data["arg_kinds"]],
|
|
2657
|
+
data["arg_names"],
|
|
2658
|
+
deserialize_type(data["ret_type"]),
|
|
2659
|
+
Instance.deserialize(data["fallback"]),
|
|
2660
|
+
name=data["name"],
|
|
2661
|
+
variables=[cast(TypeVarLikeType, deserialize_type(v)) for v in data["variables"]],
|
|
2662
|
+
is_ellipsis_args=data["is_ellipsis_args"],
|
|
2663
|
+
implicit=data["implicit"],
|
|
2664
|
+
is_bound=data["is_bound"],
|
|
2665
|
+
type_guard=(
|
|
2666
|
+
deserialize_type(data["type_guard"]) if data["type_guard"] is not None else None
|
|
2667
|
+
),
|
|
2668
|
+
type_is=deserialize_type(data["type_is"]) if data["type_is"] is not None else None,
|
|
2669
|
+
from_concatenate=data["from_concatenate"],
|
|
2670
|
+
imprecise_arg_kinds=data["imprecise_arg_kinds"],
|
|
2671
|
+
unpack_kwargs=data["unpack_kwargs"],
|
|
2672
|
+
instance_type=(
|
|
2673
|
+
cast(ProperType, deserialize_type(data["instance_type"]))
|
|
2674
|
+
if data["instance_type"] is not None
|
|
2675
|
+
else None
|
|
2676
|
+
),
|
|
2677
|
+
)
|
|
2678
|
+
|
|
2679
|
+
def write(self, data: WriteBuffer) -> None:
|
|
2680
|
+
write_tag(data, CALLABLE_TYPE)
|
|
2681
|
+
self.fallback.write(data)
|
|
2682
|
+
write_type_opt(data, self.instance_type)
|
|
2683
|
+
write_flags(
|
|
2684
|
+
data,
|
|
2685
|
+
[
|
|
2686
|
+
self.is_ellipsis_args,
|
|
2687
|
+
self.implicit,
|
|
2688
|
+
self.is_bound,
|
|
2689
|
+
self.from_concatenate,
|
|
2690
|
+
self.imprecise_arg_kinds,
|
|
2691
|
+
self.unpack_kwargs,
|
|
2692
|
+
],
|
|
2693
|
+
)
|
|
2694
|
+
write_type_list(data, self.arg_types)
|
|
2695
|
+
write_int_list(data, [int(x.value) for x in self.arg_kinds])
|
|
2696
|
+
write_str_opt_list(data, self.arg_names)
|
|
2697
|
+
self.ret_type.write(data)
|
|
2698
|
+
write_str_opt(data, self.name)
|
|
2699
|
+
write_type_list(data, self.variables)
|
|
2700
|
+
write_type_opt(data, self.type_guard)
|
|
2701
|
+
write_type_opt(data, self.type_is)
|
|
2702
|
+
write_tag(data, END_TAG)
|
|
2703
|
+
|
|
2704
|
+
@classmethod
|
|
2705
|
+
def read(cls, data: ReadBuffer) -> CallableType:
|
|
2706
|
+
assert read_tag(data) == INSTANCE
|
|
2707
|
+
fallback = Instance.read(data)
|
|
2708
|
+
instance_type = read_type_opt(data)
|
|
2709
|
+
assert instance_type is None or isinstance(instance_type, ProperType)
|
|
2710
|
+
(
|
|
2711
|
+
is_ellipsis_args,
|
|
2712
|
+
implicit,
|
|
2713
|
+
is_bound,
|
|
2714
|
+
from_concatenate,
|
|
2715
|
+
imprecise_arg_kinds,
|
|
2716
|
+
unpack_kwargs,
|
|
2717
|
+
) = read_flags(data, num_flags=6)
|
|
2718
|
+
ret = CallableType(
|
|
2719
|
+
read_type_list(data),
|
|
2720
|
+
[ARG_KINDS[ak] for ak in read_int_list(data)],
|
|
2721
|
+
read_str_opt_list(data),
|
|
2722
|
+
read_type(data),
|
|
2723
|
+
fallback,
|
|
2724
|
+
name=read_str_opt(data),
|
|
2725
|
+
variables=read_type_var_likes(data),
|
|
2726
|
+
is_ellipsis_args=is_ellipsis_args,
|
|
2727
|
+
implicit=implicit,
|
|
2728
|
+
is_bound=is_bound,
|
|
2729
|
+
type_guard=read_type_opt(data),
|
|
2730
|
+
type_is=read_type_opt(data),
|
|
2731
|
+
from_concatenate=from_concatenate,
|
|
2732
|
+
imprecise_arg_kinds=imprecise_arg_kinds,
|
|
2733
|
+
unpack_kwargs=unpack_kwargs,
|
|
2734
|
+
instance_type=instance_type,
|
|
2735
|
+
)
|
|
2736
|
+
assert read_tag(data) == END_TAG
|
|
2737
|
+
return ret
|
|
2738
|
+
|
|
2739
|
+
|
|
2740
|
+
# This is a little safety net to prevent reckless special-casing of callables
|
|
2741
|
+
# that can potentially break Unpack[...] with **kwargs.
|
|
2742
|
+
# TODO: use this in more places in checkexpr.py etc?
|
|
2743
|
+
NormalizedCallableType = NewType("NormalizedCallableType", CallableType)
|
|
2744
|
+
|
|
2745
|
+
|
|
2746
|
+
class Overloaded(FunctionLike):
|
|
2747
|
+
"""Overloaded function type T1, ... Tn, where each Ti is CallableType.
|
|
2748
|
+
|
|
2749
|
+
The variant to call is chosen based on static argument
|
|
2750
|
+
types. Overloaded function types can only be defined in stub
|
|
2751
|
+
files, and thus there is no explicit runtime dispatch
|
|
2752
|
+
implementation.
|
|
2753
|
+
"""
|
|
2754
|
+
|
|
2755
|
+
__slots__ = ("_items",)
|
|
2756
|
+
|
|
2757
|
+
_items: list[CallableType] # Must not be empty
|
|
2758
|
+
|
|
2759
|
+
def __init__(self, items: list[CallableType]) -> None:
|
|
2760
|
+
super().__init__(items[0].line, items[0].column)
|
|
2761
|
+
self._items = items
|
|
2762
|
+
self.fallback = items[0].fallback
|
|
2763
|
+
|
|
2764
|
+
@property
|
|
2765
|
+
def items(self) -> list[CallableType]:
|
|
2766
|
+
return self._items
|
|
2767
|
+
|
|
2768
|
+
def name(self) -> str | None:
|
|
2769
|
+
return self.get_name()
|
|
2770
|
+
|
|
2771
|
+
def is_type_obj(self) -> bool:
|
|
2772
|
+
# All the items must have the same type object status, so it's
|
|
2773
|
+
# sufficient to query only (any) one of them.
|
|
2774
|
+
return self._items[0].is_type_obj()
|
|
2775
|
+
|
|
2776
|
+
def type_object(self) -> mypy.nodes.TypeInfo:
|
|
2777
|
+
# All the items must have the same type object, so it's sufficient to
|
|
2778
|
+
# query only (any) one of them.
|
|
2779
|
+
return self._items[0].type_object()
|
|
2780
|
+
|
|
2781
|
+
def with_name(self, name: str) -> Overloaded:
|
|
2782
|
+
ni: list[CallableType] = []
|
|
2783
|
+
for it in self._items:
|
|
2784
|
+
ni.append(it.with_name(name))
|
|
2785
|
+
return Overloaded(ni)
|
|
2786
|
+
|
|
2787
|
+
def get_name(self) -> str | None:
|
|
2788
|
+
return self._items[0].name
|
|
2789
|
+
|
|
2790
|
+
def with_unpacked_kwargs(self) -> Overloaded:
|
|
2791
|
+
if any(i.unpack_kwargs for i in self.items):
|
|
2792
|
+
return Overloaded([i.with_unpacked_kwargs() for i in self.items])
|
|
2793
|
+
return self
|
|
2794
|
+
|
|
2795
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
2796
|
+
return visitor.visit_overloaded(self)
|
|
2797
|
+
|
|
2798
|
+
def __hash__(self) -> int:
|
|
2799
|
+
return hash(tuple(self.items))
|
|
2800
|
+
|
|
2801
|
+
def __eq__(self, other: object) -> bool:
|
|
2802
|
+
if not isinstance(other, Overloaded):
|
|
2803
|
+
return NotImplemented
|
|
2804
|
+
return self.items == other.items
|
|
2805
|
+
|
|
2806
|
+
def serialize(self) -> JsonDict:
|
|
2807
|
+
return {".class": "Overloaded", "items": [t.serialize() for t in self.items]}
|
|
2808
|
+
|
|
2809
|
+
@classmethod
|
|
2810
|
+
def deserialize(cls, data: JsonDict) -> Overloaded:
|
|
2811
|
+
assert data[".class"] == "Overloaded"
|
|
2812
|
+
return Overloaded([CallableType.deserialize(t) for t in data["items"]])
|
|
2813
|
+
|
|
2814
|
+
def write(self, data: WriteBuffer) -> None:
|
|
2815
|
+
write_tag(data, OVERLOADED)
|
|
2816
|
+
write_type_list(data, self.items)
|
|
2817
|
+
write_tag(data, END_TAG)
|
|
2818
|
+
|
|
2819
|
+
@classmethod
|
|
2820
|
+
def read(cls, data: ReadBuffer) -> Overloaded:
|
|
2821
|
+
items = []
|
|
2822
|
+
assert read_tag(data) == LIST_GEN
|
|
2823
|
+
for _ in range(read_int_bare(data)):
|
|
2824
|
+
assert read_tag(data) == CALLABLE_TYPE
|
|
2825
|
+
items.append(CallableType.read(data))
|
|
2826
|
+
assert read_tag(data) == END_TAG
|
|
2827
|
+
return Overloaded(items)
|
|
2828
|
+
|
|
2829
|
+
|
|
2830
|
+
class TupleType(ProperType):
|
|
2831
|
+
"""The tuple type Tuple[T1, ..., Tn] (at least one type argument).
|
|
2832
|
+
|
|
2833
|
+
Instance variables:
|
|
2834
|
+
items: Tuple item types
|
|
2835
|
+
partial_fallback: The (imprecise) underlying instance type that is used
|
|
2836
|
+
for non-tuple methods. This is generally builtins.tuple[Any, ...] for
|
|
2837
|
+
regular tuples, but it's different for named tuples and classes with
|
|
2838
|
+
a tuple base class. Use mypy.typeops.tuple_fallback to calculate the
|
|
2839
|
+
precise fallback type derived from item types.
|
|
2840
|
+
implicit: If True, derived from a tuple expression (t,....) instead of Tuple[t, ...]
|
|
2841
|
+
"""
|
|
2842
|
+
|
|
2843
|
+
__slots__ = ("items", "partial_fallback", "implicit")
|
|
2844
|
+
|
|
2845
|
+
items: list[Type]
|
|
2846
|
+
partial_fallback: Instance
|
|
2847
|
+
implicit: bool
|
|
2848
|
+
|
|
2849
|
+
def __init__(
|
|
2850
|
+
self,
|
|
2851
|
+
items: list[Type],
|
|
2852
|
+
fallback: Instance,
|
|
2853
|
+
line: int = -1,
|
|
2854
|
+
column: int = -1,
|
|
2855
|
+
implicit: bool = False,
|
|
2856
|
+
) -> None:
|
|
2857
|
+
super().__init__(line, column)
|
|
2858
|
+
self.partial_fallback = fallback
|
|
2859
|
+
self.items = items
|
|
2860
|
+
self.implicit = implicit
|
|
2861
|
+
|
|
2862
|
+
def can_be_true_default(self) -> bool:
|
|
2863
|
+
if self.can_be_any_bool():
|
|
2864
|
+
# Corner case: it is a `NamedTuple` with `__bool__` method defined.
|
|
2865
|
+
# It can be anything: both `True` and `False`.
|
|
2866
|
+
return True
|
|
2867
|
+
return self.length() > 0
|
|
2868
|
+
|
|
2869
|
+
def can_be_false_default(self) -> bool:
|
|
2870
|
+
if self.can_be_any_bool():
|
|
2871
|
+
# Corner case: it is a `NamedTuple` with `__bool__` method defined.
|
|
2872
|
+
# It can be anything: both `True` and `False`.
|
|
2873
|
+
return True
|
|
2874
|
+
if self.length() == 0:
|
|
2875
|
+
return True
|
|
2876
|
+
if self.length() > 1:
|
|
2877
|
+
return False
|
|
2878
|
+
# Special case tuple[*Ts] may or may not be false.
|
|
2879
|
+
item = self.items[0]
|
|
2880
|
+
if not isinstance(item, UnpackType):
|
|
2881
|
+
return False
|
|
2882
|
+
if not isinstance(item.type, TypeVarTupleType):
|
|
2883
|
+
# Non-normalized tuple[int, ...] can be false.
|
|
2884
|
+
return True
|
|
2885
|
+
return item.type.min_len == 0
|
|
2886
|
+
|
|
2887
|
+
def can_be_any_bool(self) -> bool:
|
|
2888
|
+
return bool(
|
|
2889
|
+
self.partial_fallback.type
|
|
2890
|
+
and self.partial_fallback.type.fullname != "builtins.tuple"
|
|
2891
|
+
and self.partial_fallback.type.names.get("__bool__")
|
|
2892
|
+
)
|
|
2893
|
+
|
|
2894
|
+
def length(self) -> int:
|
|
2895
|
+
return len(self.items)
|
|
2896
|
+
|
|
2897
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
2898
|
+
return visitor.visit_tuple_type(self)
|
|
2899
|
+
|
|
2900
|
+
def __hash__(self) -> int:
|
|
2901
|
+
return hash((tuple(self.items), self.partial_fallback))
|
|
2902
|
+
|
|
2903
|
+
def __eq__(self, other: object) -> bool:
|
|
2904
|
+
if not isinstance(other, TupleType):
|
|
2905
|
+
return NotImplemented
|
|
2906
|
+
return self.items == other.items and self.partial_fallback == other.partial_fallback
|
|
2907
|
+
|
|
2908
|
+
def serialize(self) -> JsonDict:
|
|
2909
|
+
return {
|
|
2910
|
+
".class": "TupleType",
|
|
2911
|
+
"items": [t.serialize() for t in self.items],
|
|
2912
|
+
"partial_fallback": self.partial_fallback.serialize(),
|
|
2913
|
+
"implicit": self.implicit,
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
@classmethod
|
|
2917
|
+
def deserialize(cls, data: JsonDict) -> TupleType:
|
|
2918
|
+
assert data[".class"] == "TupleType"
|
|
2919
|
+
return TupleType(
|
|
2920
|
+
[deserialize_type(t) for t in data["items"]],
|
|
2921
|
+
Instance.deserialize(data["partial_fallback"]),
|
|
2922
|
+
implicit=data["implicit"],
|
|
2923
|
+
)
|
|
2924
|
+
|
|
2925
|
+
def write(self, data: WriteBuffer) -> None:
|
|
2926
|
+
write_tag(data, TUPLE_TYPE)
|
|
2927
|
+
self.partial_fallback.write(data)
|
|
2928
|
+
write_type_list(data, self.items)
|
|
2929
|
+
write_bool(data, self.implicit)
|
|
2930
|
+
write_tag(data, END_TAG)
|
|
2931
|
+
|
|
2932
|
+
@classmethod
|
|
2933
|
+
def read(cls, data: ReadBuffer) -> TupleType:
|
|
2934
|
+
assert read_tag(data) == INSTANCE
|
|
2935
|
+
fallback = Instance.read(data)
|
|
2936
|
+
ret = TupleType(read_type_list(data), fallback, implicit=read_bool(data))
|
|
2937
|
+
assert read_tag(data) == END_TAG
|
|
2938
|
+
return ret
|
|
2939
|
+
|
|
2940
|
+
def copy_modified(
|
|
2941
|
+
self, *, fallback: Instance | None = None, items: list[Type] | None = None
|
|
2942
|
+
) -> TupleType:
|
|
2943
|
+
if fallback is None:
|
|
2944
|
+
fallback = self.partial_fallback
|
|
2945
|
+
if items is None:
|
|
2946
|
+
items = self.items
|
|
2947
|
+
return TupleType(items, fallback, self.line, self.column)
|
|
2948
|
+
|
|
2949
|
+
def slice(
|
|
2950
|
+
self, begin: int | None, end: int | None, stride: int | None, *, fallback: Instance | None
|
|
2951
|
+
) -> TupleType | None:
|
|
2952
|
+
if fallback is None:
|
|
2953
|
+
fallback = self.partial_fallback
|
|
2954
|
+
|
|
2955
|
+
if any(isinstance(t, UnpackType) for t in self.items):
|
|
2956
|
+
total = len(self.items)
|
|
2957
|
+
unpack_index = find_unpack_in_list(self.items)
|
|
2958
|
+
assert unpack_index is not None
|
|
2959
|
+
if begin is None and end is None:
|
|
2960
|
+
# We special-case this to support reversing variadic tuples.
|
|
2961
|
+
# General support for slicing is tricky, so we handle only simple cases.
|
|
2962
|
+
if stride == -1:
|
|
2963
|
+
slice_items = self.items[::-1]
|
|
2964
|
+
elif stride is None or stride == 1:
|
|
2965
|
+
slice_items = self.items
|
|
2966
|
+
else:
|
|
2967
|
+
return None
|
|
2968
|
+
elif (begin is None or unpack_index >= begin >= 0) and (
|
|
2969
|
+
end is not None and unpack_index >= end >= 0
|
|
2970
|
+
):
|
|
2971
|
+
# Start and end are in the prefix, everything works in this case.
|
|
2972
|
+
slice_items = self.items[begin:end:stride]
|
|
2973
|
+
elif (begin is not None and unpack_index - total < begin < 0) and (
|
|
2974
|
+
end is None or unpack_index - total < end < 0
|
|
2975
|
+
):
|
|
2976
|
+
# Start and end are in the suffix, everything works in this case.
|
|
2977
|
+
slice_items = self.items[begin:end:stride]
|
|
2978
|
+
elif (begin is None or unpack_index >= begin >= 0) and (
|
|
2979
|
+
end is None or unpack_index - total < end < 0
|
|
2980
|
+
):
|
|
2981
|
+
# Start in the prefix, end in the suffix, we can support only trivial strides.
|
|
2982
|
+
if stride is None or stride == 1:
|
|
2983
|
+
slice_items = self.items[begin:end:stride]
|
|
2984
|
+
else:
|
|
2985
|
+
return None
|
|
2986
|
+
elif (begin is not None and unpack_index - total < begin < 0) and (
|
|
2987
|
+
end is not None and unpack_index >= end >= 0
|
|
2988
|
+
):
|
|
2989
|
+
# Start in the suffix, end in the prefix, we can support only trivial strides.
|
|
2990
|
+
if stride is None or stride == -1:
|
|
2991
|
+
slice_items = self.items[begin:end:stride]
|
|
2992
|
+
else:
|
|
2993
|
+
return None
|
|
2994
|
+
else:
|
|
2995
|
+
# TODO: there are some additional cases we can support for homogeneous variadic
|
|
2996
|
+
# items, we can "eat away" finite number of items.
|
|
2997
|
+
return None
|
|
2998
|
+
else:
|
|
2999
|
+
slice_items = self.items[begin:end:stride]
|
|
3000
|
+
return TupleType(slice_items, fallback, self.line, self.column, self.implicit)
|
|
3001
|
+
|
|
3002
|
+
|
|
3003
|
+
class TypedDictItem(NamedTuple):
|
|
3004
|
+
"""Type, mutability and requiredness of an item in a TypedDict.
|
|
3005
|
+
|
|
3006
|
+
If typ is `None`, the item comes from a missing item in an open TypedDict, and
|
|
3007
|
+
the type should be treated as if it were a `builtins.object`. (Missing items in
|
|
3008
|
+
closed TypedDicts will have an uninhabited type.)
|
|
3009
|
+
|
|
3010
|
+
TODO: pass a `builtins.object` instead of None when TypedDictType gains a
|
|
3011
|
+
proper extra_items field.
|
|
3012
|
+
"""
|
|
3013
|
+
|
|
3014
|
+
typ: Type | None
|
|
3015
|
+
required: bool
|
|
3016
|
+
readonly: bool
|
|
3017
|
+
|
|
3018
|
+
@property
|
|
3019
|
+
def mutable(self) -> bool:
|
|
3020
|
+
return not self.readonly
|
|
3021
|
+
|
|
3022
|
+
|
|
3023
|
+
class TypedDictType(ProperType):
|
|
3024
|
+
"""Type of TypedDict object {'k1': v1, ..., 'kn': vn}.
|
|
3025
|
+
|
|
3026
|
+
A TypedDict object is a dictionary with specific string (literal) keys. Each
|
|
3027
|
+
key has a value with a distinct type that depends on the key. TypedDict objects
|
|
3028
|
+
are normal dict objects at runtime.
|
|
3029
|
+
|
|
3030
|
+
A TypedDictType can be either named or anonymous. If it's anonymous, its
|
|
3031
|
+
fallback will be typing_extensions._TypedDict (Instance). _TypedDict is a subclass
|
|
3032
|
+
of Mapping[str, object] and defines all non-mapping dict methods that TypedDict
|
|
3033
|
+
supports. Some dict methods are unsafe and not supported. _TypedDict isn't defined
|
|
3034
|
+
at runtime.
|
|
3035
|
+
|
|
3036
|
+
If a TypedDict is named, its fallback will be an Instance of the named type
|
|
3037
|
+
(ex: "Point") whose TypeInfo has a typeddict_type that is anonymous. This
|
|
3038
|
+
is similar to how named tuples work.
|
|
3039
|
+
|
|
3040
|
+
TODO: The fallback structure is perhaps overly complicated.
|
|
3041
|
+
"""
|
|
3042
|
+
|
|
3043
|
+
__slots__ = (
|
|
3044
|
+
"items",
|
|
3045
|
+
"required_keys",
|
|
3046
|
+
"readonly_keys",
|
|
3047
|
+
"is_closed",
|
|
3048
|
+
"fallback",
|
|
3049
|
+
"extra_items_from",
|
|
3050
|
+
"to_be_mutated",
|
|
3051
|
+
)
|
|
3052
|
+
|
|
3053
|
+
items: dict[str, Type] # item_name -> item_type
|
|
3054
|
+
required_keys: set[str]
|
|
3055
|
+
readonly_keys: set[str]
|
|
3056
|
+
fallback: Instance
|
|
3057
|
+
|
|
3058
|
+
extra_items_from: list[ProperType] # only used during semantic analysis
|
|
3059
|
+
to_be_mutated: bool # only used in a plugin for `.update`, `|=`, etc
|
|
3060
|
+
|
|
3061
|
+
def __init__(
|
|
3062
|
+
self,
|
|
3063
|
+
items: dict[str, Type],
|
|
3064
|
+
required_keys: set[str],
|
|
3065
|
+
readonly_keys: set[str],
|
|
3066
|
+
fallback: Instance,
|
|
3067
|
+
line: int = -1,
|
|
3068
|
+
column: int = -1,
|
|
3069
|
+
*,
|
|
3070
|
+
is_closed: bool = False,
|
|
3071
|
+
) -> None:
|
|
3072
|
+
super().__init__(line, column)
|
|
3073
|
+
self.items = items
|
|
3074
|
+
self.required_keys = required_keys
|
|
3075
|
+
self.readonly_keys = readonly_keys
|
|
3076
|
+
self.is_closed = is_closed
|
|
3077
|
+
self.fallback = fallback
|
|
3078
|
+
self.can_be_true = len(self.items) > 0
|
|
3079
|
+
self.can_be_false = len(self.required_keys) == 0
|
|
3080
|
+
self.extra_items_from = []
|
|
3081
|
+
self.to_be_mutated = False
|
|
3082
|
+
|
|
3083
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
3084
|
+
return visitor.visit_typeddict_type(self)
|
|
3085
|
+
|
|
3086
|
+
def __hash__(self) -> int:
|
|
3087
|
+
return hash(
|
|
3088
|
+
(
|
|
3089
|
+
frozenset(self.items.items()),
|
|
3090
|
+
self.fallback,
|
|
3091
|
+
frozenset(self.required_keys),
|
|
3092
|
+
frozenset(self.readonly_keys),
|
|
3093
|
+
self.is_closed,
|
|
3094
|
+
)
|
|
3095
|
+
)
|
|
3096
|
+
|
|
3097
|
+
def __eq__(self, other: object) -> bool:
|
|
3098
|
+
if not isinstance(other, TypedDictType):
|
|
3099
|
+
return NotImplemented
|
|
3100
|
+
if self is other:
|
|
3101
|
+
return True
|
|
3102
|
+
return (
|
|
3103
|
+
frozenset(self.items.keys()) == frozenset(other.items.keys())
|
|
3104
|
+
and all(
|
|
3105
|
+
left_item_type == right_item_type
|
|
3106
|
+
for (_, left_item_type, right_item_type) in self.zip(other)
|
|
3107
|
+
)
|
|
3108
|
+
and self.fallback == other.fallback
|
|
3109
|
+
and self.required_keys == other.required_keys
|
|
3110
|
+
and self.readonly_keys == other.readonly_keys
|
|
3111
|
+
and self.is_closed == other.is_closed
|
|
3112
|
+
)
|
|
3113
|
+
|
|
3114
|
+
def serialize(self) -> JsonDict:
|
|
3115
|
+
return {
|
|
3116
|
+
".class": "TypedDictType",
|
|
3117
|
+
"items": [[n, t.serialize()] for (n, t) in self.items.items()],
|
|
3118
|
+
"required_keys": sorted(self.required_keys),
|
|
3119
|
+
"readonly_keys": sorted(self.readonly_keys),
|
|
3120
|
+
"fallback": self.fallback.serialize(),
|
|
3121
|
+
"is_closed": self.is_closed,
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
@classmethod
|
|
3125
|
+
def deserialize(cls, data: JsonDict) -> TypedDictType:
|
|
3126
|
+
assert data[".class"] == "TypedDictType"
|
|
3127
|
+
return TypedDictType(
|
|
3128
|
+
{n: deserialize_type(t) for (n, t) in data["items"]},
|
|
3129
|
+
set(data["required_keys"]),
|
|
3130
|
+
set(data["readonly_keys"]),
|
|
3131
|
+
Instance.deserialize(data["fallback"]),
|
|
3132
|
+
is_closed=bool(data["is_closed"]),
|
|
3133
|
+
)
|
|
3134
|
+
|
|
3135
|
+
def write(self, data: WriteBuffer) -> None:
|
|
3136
|
+
write_tag(data, TYPED_DICT_TYPE)
|
|
3137
|
+
self.fallback.write(data)
|
|
3138
|
+
write_type_map(data, self.items)
|
|
3139
|
+
write_str_list(data, sorted(self.required_keys))
|
|
3140
|
+
write_str_list(data, sorted(self.readonly_keys))
|
|
3141
|
+
write_bool(data, self.is_closed)
|
|
3142
|
+
write_tag(data, END_TAG)
|
|
3143
|
+
|
|
3144
|
+
@classmethod
|
|
3145
|
+
def read(cls, data: ReadBuffer) -> TypedDictType:
|
|
3146
|
+
assert read_tag(data) == INSTANCE
|
|
3147
|
+
fallback = Instance.read(data)
|
|
3148
|
+
ret = TypedDictType(
|
|
3149
|
+
read_type_map(data),
|
|
3150
|
+
set(read_str_list(data)),
|
|
3151
|
+
set(read_str_list(data)),
|
|
3152
|
+
fallback,
|
|
3153
|
+
is_closed=read_bool(data),
|
|
3154
|
+
)
|
|
3155
|
+
assert read_tag(data) == END_TAG
|
|
3156
|
+
return ret
|
|
3157
|
+
|
|
3158
|
+
@property
|
|
3159
|
+
def is_final(self) -> bool:
|
|
3160
|
+
return self.fallback.type.is_final
|
|
3161
|
+
|
|
3162
|
+
def is_anonymous(self) -> bool:
|
|
3163
|
+
return self.fallback.type.fullname in TPDICT_FB_NAMES
|
|
3164
|
+
|
|
3165
|
+
def create_anonymous_fallback(self) -> Instance:
|
|
3166
|
+
if self.is_anonymous():
|
|
3167
|
+
return self.fallback
|
|
3168
|
+
assert self.fallback.type.typeddict_type is not None
|
|
3169
|
+
return self.fallback.type.typeddict_type.create_anonymous_fallback()
|
|
3170
|
+
|
|
3171
|
+
def copy_modified(
|
|
3172
|
+
self,
|
|
3173
|
+
*,
|
|
3174
|
+
fallback: Instance | None = None,
|
|
3175
|
+
item_types: list[Type] | None = None,
|
|
3176
|
+
item_names: list[str] | None = None,
|
|
3177
|
+
required_keys: set[str] | None = None,
|
|
3178
|
+
readonly_keys: set[str] | None = None,
|
|
3179
|
+
is_closed: bool | None = None,
|
|
3180
|
+
) -> TypedDictType:
|
|
3181
|
+
if fallback is None:
|
|
3182
|
+
fallback = self.fallback
|
|
3183
|
+
if item_types is None:
|
|
3184
|
+
items = self.items
|
|
3185
|
+
else:
|
|
3186
|
+
items = dict(zip(self.items, item_types))
|
|
3187
|
+
if required_keys is None:
|
|
3188
|
+
required_keys = self.required_keys
|
|
3189
|
+
if readonly_keys is None:
|
|
3190
|
+
readonly_keys = self.readonly_keys
|
|
3191
|
+
if is_closed is None:
|
|
3192
|
+
is_closed = self.is_closed
|
|
3193
|
+
if item_names is not None:
|
|
3194
|
+
items = {k: v for (k, v) in items.items() if k in item_names}
|
|
3195
|
+
required_keys &= set(item_names)
|
|
3196
|
+
return TypedDictType(
|
|
3197
|
+
items,
|
|
3198
|
+
required_keys,
|
|
3199
|
+
readonly_keys,
|
|
3200
|
+
fallback,
|
|
3201
|
+
self.line,
|
|
3202
|
+
self.column,
|
|
3203
|
+
is_closed=is_closed,
|
|
3204
|
+
)
|
|
3205
|
+
|
|
3206
|
+
def zip(self, right: TypedDictType) -> Iterable[tuple[str, Type, Type]]:
|
|
3207
|
+
left = self
|
|
3208
|
+
for item_name, left_item_type in left.items.items():
|
|
3209
|
+
right_item_type = right.items.get(item_name)
|
|
3210
|
+
if right_item_type is not None:
|
|
3211
|
+
yield (item_name, left_item_type, right_item_type)
|
|
3212
|
+
|
|
3213
|
+
def item(self, item_name: str) -> TypedDictItem:
|
|
3214
|
+
item_type = self.items.get(item_name)
|
|
3215
|
+
if item_type is not None:
|
|
3216
|
+
is_required = item_name in self.required_keys
|
|
3217
|
+
is_readonly = item_name in self.readonly_keys
|
|
3218
|
+
elif self.is_closed:
|
|
3219
|
+
item_type = UninhabitedType()
|
|
3220
|
+
is_required = False
|
|
3221
|
+
is_readonly = False
|
|
3222
|
+
else:
|
|
3223
|
+
is_required = False
|
|
3224
|
+
is_readonly = True
|
|
3225
|
+
return TypedDictItem(item_type, is_required, is_readonly)
|
|
3226
|
+
|
|
3227
|
+
def zipall(self, right: TypedDictType) -> Iterable[tuple[str, TypedDictItem, TypedDictItem]]:
|
|
3228
|
+
left = self
|
|
3229
|
+
for item_name in left.items:
|
|
3230
|
+
yield (item_name, left.item(item_name), right.item(item_name))
|
|
3231
|
+
for item_name in right.items:
|
|
3232
|
+
if item_name in left.items:
|
|
3233
|
+
continue
|
|
3234
|
+
yield (item_name, left.item(item_name), right.item(item_name))
|
|
3235
|
+
|
|
3236
|
+
|
|
3237
|
+
class RawExpressionType(ProperType):
|
|
3238
|
+
"""A synthetic type representing some arbitrary expression that does not cleanly
|
|
3239
|
+
translate into a type.
|
|
3240
|
+
|
|
3241
|
+
This synthetic type is only used at the beginning stages of semantic analysis
|
|
3242
|
+
and should be completely removing during the process for mapping UnboundTypes to
|
|
3243
|
+
actual types: we either turn it into a LiteralType or an AnyType.
|
|
3244
|
+
|
|
3245
|
+
For example, suppose `Foo[1]` is initially represented as the following:
|
|
3246
|
+
|
|
3247
|
+
UnboundType(
|
|
3248
|
+
name='Foo',
|
|
3249
|
+
args=[
|
|
3250
|
+
RawExpressionType(value=1, base_type_name='builtins.int'),
|
|
3251
|
+
],
|
|
3252
|
+
)
|
|
3253
|
+
|
|
3254
|
+
As we perform semantic analysis, this type will transform into one of two
|
|
3255
|
+
possible forms.
|
|
3256
|
+
|
|
3257
|
+
If 'Foo' was an alias for 'Literal' all along, this type is transformed into:
|
|
3258
|
+
|
|
3259
|
+
LiteralType(value=1, fallback=int_instance_here)
|
|
3260
|
+
|
|
3261
|
+
Alternatively, if 'Foo' is an unrelated class, we report an error and instead
|
|
3262
|
+
produce something like this:
|
|
3263
|
+
|
|
3264
|
+
Instance(type=typeinfo_for_foo, args=[AnyType(TypeOfAny.from_error))
|
|
3265
|
+
|
|
3266
|
+
If the "note" field is not None, the provided note will be reported alongside the
|
|
3267
|
+
error at this point.
|
|
3268
|
+
|
|
3269
|
+
Note: if "literal_value" is None, that means this object is representing some
|
|
3270
|
+
expression that cannot possibly be a parameter of Literal[...]. For example,
|
|
3271
|
+
"Foo[3j]" would be represented as:
|
|
3272
|
+
|
|
3273
|
+
UnboundType(
|
|
3274
|
+
name='Foo',
|
|
3275
|
+
args=[
|
|
3276
|
+
RawExpressionType(value=None, base_type_name='builtins.complex'),
|
|
3277
|
+
],
|
|
3278
|
+
)
|
|
3279
|
+
"""
|
|
3280
|
+
|
|
3281
|
+
__slots__ = ("literal_value", "base_type_name", "note")
|
|
3282
|
+
|
|
3283
|
+
def __init__(
|
|
3284
|
+
self,
|
|
3285
|
+
literal_value: LiteralValue | None,
|
|
3286
|
+
base_type_name: str,
|
|
3287
|
+
line: int = -1,
|
|
3288
|
+
column: int = -1,
|
|
3289
|
+
note: str | None = None,
|
|
3290
|
+
) -> None:
|
|
3291
|
+
super().__init__(line, column)
|
|
3292
|
+
self.literal_value = literal_value
|
|
3293
|
+
self.base_type_name = base_type_name
|
|
3294
|
+
self.note = note
|
|
3295
|
+
|
|
3296
|
+
def simple_name(self) -> str:
|
|
3297
|
+
return self.base_type_name.replace("builtins.", "")
|
|
3298
|
+
|
|
3299
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
3300
|
+
assert isinstance(visitor, SyntheticTypeVisitor)
|
|
3301
|
+
ret: T = visitor.visit_raw_expression_type(self)
|
|
3302
|
+
return ret
|
|
3303
|
+
|
|
3304
|
+
def serialize(self) -> JsonDict:
|
|
3305
|
+
assert False, "Synthetic types don't serialize"
|
|
3306
|
+
|
|
3307
|
+
def __hash__(self) -> int:
|
|
3308
|
+
return hash((self.literal_value, self.base_type_name))
|
|
3309
|
+
|
|
3310
|
+
def __eq__(self, other: object) -> bool:
|
|
3311
|
+
if isinstance(other, RawExpressionType):
|
|
3312
|
+
return (
|
|
3313
|
+
self.base_type_name == other.base_type_name
|
|
3314
|
+
and self.literal_value == other.literal_value
|
|
3315
|
+
)
|
|
3316
|
+
else:
|
|
3317
|
+
return NotImplemented
|
|
3318
|
+
|
|
3319
|
+
|
|
3320
|
+
class LiteralType(ProperType):
|
|
3321
|
+
"""The type of a Literal instance. Literal[Value]
|
|
3322
|
+
|
|
3323
|
+
A Literal always consists of:
|
|
3324
|
+
|
|
3325
|
+
1. A native Python object corresponding to the contained inner value
|
|
3326
|
+
2. A fallback for this Literal. The fallback also corresponds to the
|
|
3327
|
+
parent type this Literal subtypes.
|
|
3328
|
+
|
|
3329
|
+
For example, 'Literal[42]' is represented as
|
|
3330
|
+
'LiteralType(value=42, fallback=instance_of_int)'
|
|
3331
|
+
|
|
3332
|
+
As another example, `Literal[Color.RED]` (where Color is an enum) is
|
|
3333
|
+
represented as `LiteralType(value="RED", fallback=instance_of_color)'.
|
|
3334
|
+
"""
|
|
3335
|
+
|
|
3336
|
+
__slots__ = ("value", "fallback", "_hash")
|
|
3337
|
+
|
|
3338
|
+
def __init__(
|
|
3339
|
+
self, value: LiteralValue, fallback: Instance, line: int = -1, column: int = -1
|
|
3340
|
+
) -> None:
|
|
3341
|
+
super().__init__(line, column)
|
|
3342
|
+
self.value = value
|
|
3343
|
+
self.fallback = fallback
|
|
3344
|
+
|
|
3345
|
+
# NOTE: Enum types are always truthy by default, but this can be changed
|
|
3346
|
+
# in subclasses, so we need to get the truthyness from the Enum
|
|
3347
|
+
# type rather than base it on the value (which is a non-empty
|
|
3348
|
+
# string for enums, so always truthy)
|
|
3349
|
+
# TODO: We should consider moving this branch to the `can_be_true`
|
|
3350
|
+
# `can_be_false` properties instead, so the truthyness only
|
|
3351
|
+
# needs to be determined once per set of Enum literals.
|
|
3352
|
+
# However, the same can be said for `TypeAliasType` in some
|
|
3353
|
+
# cases and we only set the default based on the type it is
|
|
3354
|
+
# aliasing. So if we decide to change this, we may want to
|
|
3355
|
+
# change that as well. perf_compare output was inconclusive
|
|
3356
|
+
# but slightly favored this version, probably because we have
|
|
3357
|
+
# almost no test cases where we would redundantly compute
|
|
3358
|
+
# `can_be_false`/`can_be_true`.
|
|
3359
|
+
def can_be_false_default(self) -> bool:
|
|
3360
|
+
if isinstance(self.value, SentinelValue):
|
|
3361
|
+
return False
|
|
3362
|
+
if self.fallback.type.is_enum:
|
|
3363
|
+
return self.fallback.can_be_false
|
|
3364
|
+
return not self.value
|
|
3365
|
+
|
|
3366
|
+
def can_be_true_default(self) -> bool:
|
|
3367
|
+
if isinstance(self.value, SentinelValue):
|
|
3368
|
+
return True
|
|
3369
|
+
if self.fallback.type.is_enum:
|
|
3370
|
+
return self.fallback.can_be_true
|
|
3371
|
+
return bool(self.value)
|
|
3372
|
+
|
|
3373
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
3374
|
+
return visitor.visit_literal_type(self)
|
|
3375
|
+
|
|
3376
|
+
def __hash__(self) -> int:
|
|
3377
|
+
# Intentionally a subset of __eq__ for perf
|
|
3378
|
+
return hash(self.value)
|
|
3379
|
+
|
|
3380
|
+
def __eq__(self, other: object) -> bool:
|
|
3381
|
+
if isinstance(other, LiteralType):
|
|
3382
|
+
return self.value == other.value and self.fallback == other.fallback
|
|
3383
|
+
else:
|
|
3384
|
+
return NotImplemented
|
|
3385
|
+
|
|
3386
|
+
def is_enum_literal(self) -> bool:
|
|
3387
|
+
return self.fallback.type.is_enum
|
|
3388
|
+
|
|
3389
|
+
def is_sentinel_literal(self) -> bool:
|
|
3390
|
+
return isinstance(self.value, SentinelValue)
|
|
3391
|
+
|
|
3392
|
+
def value_repr(self) -> str:
|
|
3393
|
+
"""Returns the string representation of the underlying type.
|
|
3394
|
+
|
|
3395
|
+
This function is almost equivalent to running `repr(self.value)`,
|
|
3396
|
+
except it includes some additional logic to correctly handle cases
|
|
3397
|
+
where the value is a string, byte string, a unicode string, or an enum.
|
|
3398
|
+
"""
|
|
3399
|
+
if isinstance(self.value, SentinelValue):
|
|
3400
|
+
return self.value.name
|
|
3401
|
+
|
|
3402
|
+
raw = repr(self.value)
|
|
3403
|
+
fallback_name = self.fallback.type.fullname
|
|
3404
|
+
|
|
3405
|
+
# If this is backed by an enum,
|
|
3406
|
+
if self.is_enum_literal():
|
|
3407
|
+
return f"{fallback_name}.{self.value}"
|
|
3408
|
+
|
|
3409
|
+
if fallback_name == "builtins.bytes":
|
|
3410
|
+
# Note: 'builtins.bytes' only appears in Python 3, so we want to
|
|
3411
|
+
# explicitly prefix with a "b"
|
|
3412
|
+
return "b" + raw
|
|
3413
|
+
else:
|
|
3414
|
+
# 'builtins.str' could mean either depending on context, but either way
|
|
3415
|
+
# we don't prefix: it's the "native" string. And of course, if value is
|
|
3416
|
+
# some other type, we just return that string repr directly.
|
|
3417
|
+
return raw
|
|
3418
|
+
|
|
3419
|
+
def serialize(self) -> JsonDict | str:
|
|
3420
|
+
value: LiteralValue | JsonDict = self.value
|
|
3421
|
+
if isinstance(value, SentinelValue):
|
|
3422
|
+
value = {".class": "SentinelValue", "fullname": value.fullname, "name": value.name}
|
|
3423
|
+
return {".class": "LiteralType", "value": value, "fallback": self.fallback.serialize()}
|
|
3424
|
+
|
|
3425
|
+
@classmethod
|
|
3426
|
+
def deserialize(cls, data: JsonDict) -> LiteralType:
|
|
3427
|
+
assert data[".class"] == "LiteralType"
|
|
3428
|
+
value = data["value"]
|
|
3429
|
+
if isinstance(value, dict):
|
|
3430
|
+
assert value[".class"] == "SentinelValue"
|
|
3431
|
+
value = SentinelValue(value["fullname"], value["name"])
|
|
3432
|
+
return LiteralType(value=value, fallback=Instance.deserialize(data["fallback"]))
|
|
3433
|
+
|
|
3434
|
+
def write(self, data: WriteBuffer) -> None:
|
|
3435
|
+
write_tag(data, LITERAL_TYPE)
|
|
3436
|
+
self.fallback.write(data)
|
|
3437
|
+
write_literal(data, self.value)
|
|
3438
|
+
write_tag(data, END_TAG)
|
|
3439
|
+
|
|
3440
|
+
@classmethod
|
|
3441
|
+
def read(cls, data: ReadBuffer) -> LiteralType:
|
|
3442
|
+
assert read_tag(data) == INSTANCE
|
|
3443
|
+
fallback = Instance.read(data)
|
|
3444
|
+
tag = read_tag(data)
|
|
3445
|
+
value = read_literal(data, tag)
|
|
3446
|
+
ret = LiteralType(value, fallback)
|
|
3447
|
+
assert read_tag(data) == END_TAG
|
|
3448
|
+
return ret
|
|
3449
|
+
|
|
3450
|
+
|
|
3451
|
+
class UnionType(ProperType):
|
|
3452
|
+
"""The union type Union[T1, ..., Tn] (at least one type argument)."""
|
|
3453
|
+
|
|
3454
|
+
__slots__ = (
|
|
3455
|
+
"items",
|
|
3456
|
+
"is_evaluated",
|
|
3457
|
+
"uses_pep604_syntax",
|
|
3458
|
+
"original_str_expr",
|
|
3459
|
+
"original_str_fallback",
|
|
3460
|
+
)
|
|
3461
|
+
|
|
3462
|
+
def __init__(
|
|
3463
|
+
self,
|
|
3464
|
+
items: Sequence[Type],
|
|
3465
|
+
line: int = -1,
|
|
3466
|
+
column: int = -1,
|
|
3467
|
+
*,
|
|
3468
|
+
is_evaluated: bool = True,
|
|
3469
|
+
uses_pep604_syntax: bool = False,
|
|
3470
|
+
) -> None:
|
|
3471
|
+
super().__init__(line, column)
|
|
3472
|
+
# We must keep this false to avoid crashes during semantic analysis.
|
|
3473
|
+
# TODO: maybe switch this to True during type-checking pass?
|
|
3474
|
+
self.items = flatten_nested_unions(items, handle_type_alias_type=False)
|
|
3475
|
+
# is_evaluated should be set to false for type comments and string literals
|
|
3476
|
+
self.is_evaluated = is_evaluated
|
|
3477
|
+
# uses_pep604_syntax is True if Union uses OR syntax (X | Y)
|
|
3478
|
+
self.uses_pep604_syntax = uses_pep604_syntax
|
|
3479
|
+
# The meaning of these two is the same as for UnboundType. A UnionType can be
|
|
3480
|
+
# return by type parser from a string "A|B", and we need to be able to fall back
|
|
3481
|
+
# to plain string, when such a string appears inside a Literal[...].
|
|
3482
|
+
self.original_str_expr: str | None = None
|
|
3483
|
+
self.original_str_fallback: str | None = None
|
|
3484
|
+
|
|
3485
|
+
def can_be_true_default(self) -> bool:
|
|
3486
|
+
return any(item.can_be_true for item in self.items)
|
|
3487
|
+
|
|
3488
|
+
def can_be_false_default(self) -> bool:
|
|
3489
|
+
return any(item.can_be_false for item in self.items)
|
|
3490
|
+
|
|
3491
|
+
def __hash__(self) -> int:
|
|
3492
|
+
return hash(frozenset(self.items))
|
|
3493
|
+
|
|
3494
|
+
def __eq__(self, other: object) -> bool:
|
|
3495
|
+
if not isinstance(other, UnionType):
|
|
3496
|
+
return NotImplemented
|
|
3497
|
+
if self is other:
|
|
3498
|
+
return True
|
|
3499
|
+
return frozenset(self.items) == frozenset(other.items)
|
|
3500
|
+
|
|
3501
|
+
@overload
|
|
3502
|
+
@staticmethod
|
|
3503
|
+
def make_union(
|
|
3504
|
+
items: Sequence[ProperType], line: int = -1, column: int = -1
|
|
3505
|
+
) -> ProperType: ...
|
|
3506
|
+
|
|
3507
|
+
@overload
|
|
3508
|
+
@staticmethod
|
|
3509
|
+
def make_union(items: Sequence[Type], line: int = -1, column: int = -1) -> Type: ...
|
|
3510
|
+
|
|
3511
|
+
@staticmethod
|
|
3512
|
+
def make_union(items: Sequence[Type], line: int = -1, column: int = -1) -> Type:
|
|
3513
|
+
if len(items) > 1:
|
|
3514
|
+
return UnionType(items, line, column)
|
|
3515
|
+
elif len(items) == 1:
|
|
3516
|
+
return items[0]
|
|
3517
|
+
else:
|
|
3518
|
+
return UninhabitedType()
|
|
3519
|
+
|
|
3520
|
+
def length(self) -> int:
|
|
3521
|
+
return len(self.items)
|
|
3522
|
+
|
|
3523
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
3524
|
+
return visitor.visit_union_type(self)
|
|
3525
|
+
|
|
3526
|
+
def relevant_items(self) -> list[Type]:
|
|
3527
|
+
"""Removes NoneTypes from Unions when strict Optional checking is off."""
|
|
3528
|
+
if state.strict_optional:
|
|
3529
|
+
return self.items
|
|
3530
|
+
else:
|
|
3531
|
+
return [i for i in self.items if not isinstance(get_proper_type(i), NoneType)]
|
|
3532
|
+
|
|
3533
|
+
def serialize(self) -> JsonDict:
|
|
3534
|
+
return {
|
|
3535
|
+
".class": "UnionType",
|
|
3536
|
+
"items": [t.serialize() for t in self.items],
|
|
3537
|
+
"uses_pep604_syntax": self.uses_pep604_syntax,
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3540
|
+
@classmethod
|
|
3541
|
+
def deserialize(cls, data: JsonDict) -> UnionType:
|
|
3542
|
+
assert data[".class"] == "UnionType"
|
|
3543
|
+
return UnionType(
|
|
3544
|
+
[deserialize_type(t) for t in data["items"]],
|
|
3545
|
+
uses_pep604_syntax=data["uses_pep604_syntax"],
|
|
3546
|
+
)
|
|
3547
|
+
|
|
3548
|
+
def write(self, data: WriteBuffer) -> None:
|
|
3549
|
+
write_tag(data, UNION_TYPE)
|
|
3550
|
+
write_type_list(data, self.items)
|
|
3551
|
+
write_bool(data, self.uses_pep604_syntax)
|
|
3552
|
+
write_tag(data, END_TAG)
|
|
3553
|
+
|
|
3554
|
+
@classmethod
|
|
3555
|
+
def read(cls, data: ReadBuffer) -> UnionType:
|
|
3556
|
+
ret = UnionType(read_type_list(data), uses_pep604_syntax=read_bool(data))
|
|
3557
|
+
assert read_tag(data) == END_TAG
|
|
3558
|
+
return ret
|
|
3559
|
+
|
|
3560
|
+
|
|
3561
|
+
class PartialType(ProperType):
|
|
3562
|
+
"""Type such as List[?] where type arguments are unknown, or partial None type.
|
|
3563
|
+
|
|
3564
|
+
These are used for inferring types in multiphase initialization such as this:
|
|
3565
|
+
|
|
3566
|
+
x = [] # x gets a partial type List[?], as item type is unknown
|
|
3567
|
+
x.append(1) # partial type gets replaced with normal type List[int]
|
|
3568
|
+
|
|
3569
|
+
Or with None:
|
|
3570
|
+
|
|
3571
|
+
x = None # x gets a partial type None
|
|
3572
|
+
if c:
|
|
3573
|
+
x = 1 # Infer actual type int for x
|
|
3574
|
+
"""
|
|
3575
|
+
|
|
3576
|
+
__slots__ = ("type", "var", "value_type")
|
|
3577
|
+
|
|
3578
|
+
# None for the 'None' partial type; otherwise a generic class
|
|
3579
|
+
type: mypy.nodes.TypeInfo | None
|
|
3580
|
+
var: mypy.nodes.Var
|
|
3581
|
+
# For partial defaultdict[K, V], the type V (K is unknown). If V is generic,
|
|
3582
|
+
# the type argument is Any and will be replaced later.
|
|
3583
|
+
value_type: Instance | None
|
|
3584
|
+
|
|
3585
|
+
def __init__(
|
|
3586
|
+
self,
|
|
3587
|
+
type: mypy.nodes.TypeInfo | None,
|
|
3588
|
+
var: mypy.nodes.Var,
|
|
3589
|
+
value_type: Instance | None = None,
|
|
3590
|
+
) -> None:
|
|
3591
|
+
super().__init__()
|
|
3592
|
+
self.type = type
|
|
3593
|
+
self.var = var
|
|
3594
|
+
self.value_type = value_type
|
|
3595
|
+
|
|
3596
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
3597
|
+
return visitor.visit_partial_type(self)
|
|
3598
|
+
|
|
3599
|
+
|
|
3600
|
+
class EllipsisType(ProperType):
|
|
3601
|
+
"""The type ... (ellipsis).
|
|
3602
|
+
|
|
3603
|
+
This is not a real type but a syntactic AST construct, used in Callable[..., T], for example.
|
|
3604
|
+
|
|
3605
|
+
A semantically analyzed type will never have ellipsis types.
|
|
3606
|
+
"""
|
|
3607
|
+
|
|
3608
|
+
__slots__ = ()
|
|
3609
|
+
|
|
3610
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
3611
|
+
assert isinstance(visitor, SyntheticTypeVisitor)
|
|
3612
|
+
ret: T = visitor.visit_ellipsis_type(self)
|
|
3613
|
+
return ret
|
|
3614
|
+
|
|
3615
|
+
def serialize(self) -> JsonDict:
|
|
3616
|
+
assert False, "Synthetic types don't serialize"
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
class TypeType(ProperType):
|
|
3620
|
+
"""For types like Type[User] or TypeForm[User | None].
|
|
3621
|
+
|
|
3622
|
+
Type[C] annotates variables that are class objects, constrained by
|
|
3623
|
+
the type argument. See PEP 484 for more details.
|
|
3624
|
+
|
|
3625
|
+
TypeForm[T] annotates variables that hold the result of evaluating
|
|
3626
|
+
a type expression. See PEP 747 for more details.
|
|
3627
|
+
|
|
3628
|
+
We may encounter expressions whose values are specific classes;
|
|
3629
|
+
those are represented as callables (possibly overloaded)
|
|
3630
|
+
corresponding to the class's constructor's signature and returning
|
|
3631
|
+
an instance of that class. The difference with Type[C] is that
|
|
3632
|
+
those callables always represent the exact class given as the
|
|
3633
|
+
return type; Type[C] represents any class that's a subclass of C,
|
|
3634
|
+
and C may also be a type variable or a union (or Any).
|
|
3635
|
+
|
|
3636
|
+
Many questions around subtype relationships between Type[C1] and
|
|
3637
|
+
def(...) -> C2 are answered by looking at the subtype
|
|
3638
|
+
relationships between C1 and C2, since Type[] is considered
|
|
3639
|
+
covariant.
|
|
3640
|
+
|
|
3641
|
+
There's an unsolved problem with constructor signatures (also
|
|
3642
|
+
unsolved in PEP 484): calling a variable whose type is Type[C]
|
|
3643
|
+
assumes the constructor signature for C, even though a subclass of
|
|
3644
|
+
C might completely change the constructor signature. For now we
|
|
3645
|
+
just assume that users of Type[C] are careful not to do that (in
|
|
3646
|
+
the future we might detect when they are violating that
|
|
3647
|
+
assumption).
|
|
3648
|
+
"""
|
|
3649
|
+
|
|
3650
|
+
__slots__ = ("item", "is_type_form")
|
|
3651
|
+
|
|
3652
|
+
# This can't be everything, but it can be a class reference,
|
|
3653
|
+
# a generic class instance, a union, Any, a type variable...
|
|
3654
|
+
item: ProperType
|
|
3655
|
+
|
|
3656
|
+
# If True then this TypeType represents a TypeForm[T].
|
|
3657
|
+
# If False then this TypeType represents a Type[C].
|
|
3658
|
+
is_type_form: bool
|
|
3659
|
+
|
|
3660
|
+
def __init__(
|
|
3661
|
+
self,
|
|
3662
|
+
item: Bogus[Instance | AnyType | TypeVarType | TupleType | NoneType | CallableType],
|
|
3663
|
+
*,
|
|
3664
|
+
line: int = -1,
|
|
3665
|
+
column: int = -1,
|
|
3666
|
+
is_type_form: bool = False,
|
|
3667
|
+
) -> None:
|
|
3668
|
+
"""To ensure Type[Union[A, B]] is always represented as Union[Type[A], Type[B]], item of
|
|
3669
|
+
type UnionType must be handled through make_normalized static method.
|
|
3670
|
+
"""
|
|
3671
|
+
super().__init__(line, column)
|
|
3672
|
+
self.item = item
|
|
3673
|
+
self.is_type_form = is_type_form
|
|
3674
|
+
|
|
3675
|
+
@staticmethod
|
|
3676
|
+
def make_normalized(
|
|
3677
|
+
item: Type, *, line: int = -1, column: int = -1, is_type_form: bool = False
|
|
3678
|
+
) -> ProperType:
|
|
3679
|
+
item = get_proper_type(item)
|
|
3680
|
+
if is_type_form:
|
|
3681
|
+
# Don't convert TypeForm[X | Y] to (TypeForm[X] | TypeForm[Y])
|
|
3682
|
+
pass
|
|
3683
|
+
else:
|
|
3684
|
+
if isinstance(item, UnionType):
|
|
3685
|
+
return UnionType.make_union(
|
|
3686
|
+
[TypeType.make_normalized(union_item) for union_item in item.items],
|
|
3687
|
+
line=line,
|
|
3688
|
+
column=column,
|
|
3689
|
+
)
|
|
3690
|
+
return TypeType(item, line=line, column=column, is_type_form=is_type_form) # type: ignore[arg-type]
|
|
3691
|
+
|
|
3692
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
3693
|
+
return visitor.visit_type_type(self)
|
|
3694
|
+
|
|
3695
|
+
def __hash__(self) -> int:
|
|
3696
|
+
return hash(self.item)
|
|
3697
|
+
|
|
3698
|
+
def __eq__(self, other: object) -> bool:
|
|
3699
|
+
if not isinstance(other, TypeType):
|
|
3700
|
+
return NotImplemented
|
|
3701
|
+
return self.item == other.item and self.is_type_form == other.is_type_form
|
|
3702
|
+
|
|
3703
|
+
def serialize(self) -> JsonDict:
|
|
3704
|
+
return {
|
|
3705
|
+
".class": "TypeType",
|
|
3706
|
+
"item": self.item.serialize(),
|
|
3707
|
+
"is_type_form": self.is_type_form,
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
@classmethod
|
|
3711
|
+
def deserialize(cls, data: JsonDict) -> Type:
|
|
3712
|
+
assert data[".class"] == "TypeType"
|
|
3713
|
+
return TypeType.make_normalized(
|
|
3714
|
+
deserialize_type(data["item"]), is_type_form=data["is_type_form"]
|
|
3715
|
+
)
|
|
3716
|
+
|
|
3717
|
+
def write(self, data: WriteBuffer) -> None:
|
|
3718
|
+
write_tag(data, TYPE_TYPE)
|
|
3719
|
+
self.item.write(data)
|
|
3720
|
+
write_bool(data, self.is_type_form)
|
|
3721
|
+
write_tag(data, END_TAG)
|
|
3722
|
+
|
|
3723
|
+
@classmethod
|
|
3724
|
+
def read(cls, data: ReadBuffer) -> Type:
|
|
3725
|
+
ret = TypeType.make_normalized(read_type(data), is_type_form=read_bool(data))
|
|
3726
|
+
assert read_tag(data) == END_TAG
|
|
3727
|
+
return ret
|
|
3728
|
+
|
|
3729
|
+
|
|
3730
|
+
class PlaceholderType(ProperType):
|
|
3731
|
+
"""Temporary, yet-unknown type during semantic analysis.
|
|
3732
|
+
|
|
3733
|
+
This is needed when there's a reference to a type before the real symbol
|
|
3734
|
+
table entry of the target type is available (specifically, we use a
|
|
3735
|
+
temporary PlaceholderNode symbol node). Consider this example:
|
|
3736
|
+
|
|
3737
|
+
class str(Sequence[str]): ...
|
|
3738
|
+
|
|
3739
|
+
We use a PlaceholderType for the 'str' in 'Sequence[str]' since we can't create
|
|
3740
|
+
a TypeInfo for 'str' until all base classes have been resolved. We'll soon
|
|
3741
|
+
perform another analysis iteration which replaces the base class with a complete
|
|
3742
|
+
type without any placeholders. After semantic analysis, no placeholder types must
|
|
3743
|
+
exist.
|
|
3744
|
+
"""
|
|
3745
|
+
|
|
3746
|
+
__slots__ = ("fullname", "args")
|
|
3747
|
+
|
|
3748
|
+
def __init__(self, fullname: str | None, args: list[Type], line: int) -> None:
|
|
3749
|
+
super().__init__(line)
|
|
3750
|
+
self.fullname = fullname # Must be a valid full name of an actual node (or None).
|
|
3751
|
+
self.args = args
|
|
3752
|
+
|
|
3753
|
+
def accept(self, visitor: TypeVisitor[T]) -> T:
|
|
3754
|
+
assert isinstance(visitor, SyntheticTypeVisitor)
|
|
3755
|
+
ret: T = visitor.visit_placeholder_type(self)
|
|
3756
|
+
return ret
|
|
3757
|
+
|
|
3758
|
+
def __hash__(self) -> int:
|
|
3759
|
+
return hash((self.fullname, tuple(self.args)))
|
|
3760
|
+
|
|
3761
|
+
def __eq__(self, other: object) -> bool:
|
|
3762
|
+
if not isinstance(other, PlaceholderType):
|
|
3763
|
+
return NotImplemented
|
|
3764
|
+
return self.fullname == other.fullname and self.args == other.args
|
|
3765
|
+
|
|
3766
|
+
def serialize(self) -> str:
|
|
3767
|
+
# We should never get here since all placeholders should be replaced
|
|
3768
|
+
# during semantic analysis.
|
|
3769
|
+
assert False, f"Internal error: unresolved placeholder type {self.fullname}"
|
|
3770
|
+
|
|
3771
|
+
|
|
3772
|
+
@overload
|
|
3773
|
+
def get_proper_type(typ: None) -> None: ...
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
@overload
|
|
3777
|
+
def get_proper_type(typ: Type) -> ProperType: ...
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
def get_proper_type(typ: Type | None) -> ProperType | None:
|
|
3781
|
+
"""Get the expansion of a type alias type.
|
|
3782
|
+
|
|
3783
|
+
If the type is already a proper type, this is a no-op. Use this function
|
|
3784
|
+
wherever a decision is made on a call like e.g. 'if isinstance(typ, UnionType): ...',
|
|
3785
|
+
because 'typ' in this case may be an alias to union. Note: if after making the decision
|
|
3786
|
+
on the isinstance() call you pass on the original type (and not one of its components)
|
|
3787
|
+
it is recommended to *always* pass on the unexpanded alias.
|
|
3788
|
+
"""
|
|
3789
|
+
if typ is None:
|
|
3790
|
+
return None
|
|
3791
|
+
# TODO: this is an ugly hack, remove.
|
|
3792
|
+
if isinstance(typ, TypeGuardedType):
|
|
3793
|
+
typ = typ.type_guard
|
|
3794
|
+
while isinstance(typ, TypeAliasType):
|
|
3795
|
+
typ = typ._expand_once()
|
|
3796
|
+
# TODO: store the name of original type alias on this type, so we can show it in errors.
|
|
3797
|
+
return cast(ProperType, typ)
|
|
3798
|
+
|
|
3799
|
+
|
|
3800
|
+
@overload
|
|
3801
|
+
def get_proper_types(types: list[Type] | tuple[Type, ...]) -> list[ProperType]: ...
|
|
3802
|
+
|
|
3803
|
+
|
|
3804
|
+
@overload
|
|
3805
|
+
def get_proper_types(
|
|
3806
|
+
types: list[Type | None] | tuple[Type | None, ...],
|
|
3807
|
+
) -> list[ProperType | None]: ...
|
|
3808
|
+
|
|
3809
|
+
|
|
3810
|
+
def get_proper_types(
|
|
3811
|
+
types: list[Type] | list[Type | None] | tuple[Type | None, ...],
|
|
3812
|
+
) -> list[ProperType] | list[ProperType | None]:
|
|
3813
|
+
if isinstance(types, list):
|
|
3814
|
+
typelist = types
|
|
3815
|
+
# Optimize for the common case so that we don't need to allocate anything
|
|
3816
|
+
if not any(isinstance(t, (TypeAliasType, TypeGuardedType)) for t in typelist):
|
|
3817
|
+
return cast("list[ProperType]", typelist)
|
|
3818
|
+
return [get_proper_type(t) for t in typelist]
|
|
3819
|
+
else:
|
|
3820
|
+
return [get_proper_type(t) for t in types]
|
|
3821
|
+
|
|
3822
|
+
|
|
3823
|
+
# We split off the type visitor base classes to another module
|
|
3824
|
+
# to make it easier to gradually get modules working with mypyc.
|
|
3825
|
+
# Import them here, after the types are defined.
|
|
3826
|
+
# This is intended as a re-export also.
|
|
3827
|
+
from mypy.type_visitor import (
|
|
3828
|
+
ALL_STRATEGY as ALL_STRATEGY,
|
|
3829
|
+
ANY_STRATEGY as ANY_STRATEGY,
|
|
3830
|
+
BoolTypeQuery as BoolTypeQuery,
|
|
3831
|
+
SyntheticTypeVisitor as SyntheticTypeVisitor,
|
|
3832
|
+
TypeQuery as TypeQuery,
|
|
3833
|
+
TypeTranslator as TypeTranslator,
|
|
3834
|
+
TypeVisitor as TypeVisitor,
|
|
3835
|
+
)
|
|
3836
|
+
|
|
3837
|
+
|
|
3838
|
+
class TypeStrVisitor(SyntheticTypeVisitor[str]):
|
|
3839
|
+
"""Visitor for pretty-printing types into strings.
|
|
3840
|
+
|
|
3841
|
+
This is mostly for debugging/testing.
|
|
3842
|
+
|
|
3843
|
+
Do not preserve original formatting.
|
|
3844
|
+
|
|
3845
|
+
Notes:
|
|
3846
|
+
- Represent unbound types as Foo? or Foo?[...].
|
|
3847
|
+
- Represent the NoneType type as None.
|
|
3848
|
+
- Represent Union[x, y] as x | y
|
|
3849
|
+
"""
|
|
3850
|
+
|
|
3851
|
+
def __init__(self, id_mapper: IdMapper | None = None, *, options: Options) -> None:
|
|
3852
|
+
self.id_mapper = id_mapper
|
|
3853
|
+
self.options = options
|
|
3854
|
+
self.dotted_aliases: set[TypeAliasType] | None = None
|
|
3855
|
+
|
|
3856
|
+
def visit_unbound_type(self, t: UnboundType, /) -> str:
|
|
3857
|
+
s = t.name + "?"
|
|
3858
|
+
if t.args:
|
|
3859
|
+
s += f"[{self.list_str(t.args)}]"
|
|
3860
|
+
return s
|
|
3861
|
+
|
|
3862
|
+
def visit_type_list(self, t: TypeList, /) -> str:
|
|
3863
|
+
return f"<TypeList {self.list_str(t.items)}>"
|
|
3864
|
+
|
|
3865
|
+
def visit_callable_argument(self, t: CallableArgument, /) -> str:
|
|
3866
|
+
typ = t.typ.accept(self)
|
|
3867
|
+
if t.name is None:
|
|
3868
|
+
return f"{t.constructor}({typ})"
|
|
3869
|
+
else:
|
|
3870
|
+
return f"{t.constructor}({typ}, {t.name})"
|
|
3871
|
+
|
|
3872
|
+
def visit_any(self, t: AnyType, /) -> str:
|
|
3873
|
+
return "Any"
|
|
3874
|
+
|
|
3875
|
+
def visit_none_type(self, t: NoneType, /) -> str:
|
|
3876
|
+
return "None"
|
|
3877
|
+
|
|
3878
|
+
def visit_uninhabited_type(self, t: UninhabitedType, /) -> str:
|
|
3879
|
+
return "Never"
|
|
3880
|
+
|
|
3881
|
+
def visit_erased_type(self, t: ErasedType, /) -> str:
|
|
3882
|
+
return "<Erased>"
|
|
3883
|
+
|
|
3884
|
+
def visit_deleted_type(self, t: DeletedType, /) -> str:
|
|
3885
|
+
if t.source is None:
|
|
3886
|
+
return "<Deleted>"
|
|
3887
|
+
else:
|
|
3888
|
+
return f"<Deleted '{t.source}'>"
|
|
3889
|
+
|
|
3890
|
+
def visit_instance(self, t: Instance, /) -> str:
|
|
3891
|
+
fullname = t.type.fullname
|
|
3892
|
+
if not self.options.reveal_verbose_types and fullname.startswith("builtins."):
|
|
3893
|
+
fullname = t.type.name
|
|
3894
|
+
if t.last_known_value and not t.args:
|
|
3895
|
+
# Instances with a literal fallback should never be generic. If they are,
|
|
3896
|
+
# something went wrong so we fall back to showing the full Instance repr.
|
|
3897
|
+
s = f"{t.last_known_value.accept(self)}?"
|
|
3898
|
+
|
|
3899
|
+
else:
|
|
3900
|
+
s = fullname or t.type.name or "<???>"
|
|
3901
|
+
|
|
3902
|
+
if t.args:
|
|
3903
|
+
if t.type.fullname == "builtins.tuple":
|
|
3904
|
+
assert len(t.args) == 1
|
|
3905
|
+
s += f"[{self.list_str(t.args)}, ...]"
|
|
3906
|
+
else:
|
|
3907
|
+
s += f"[{self.list_str(t.args)}]"
|
|
3908
|
+
elif t.type.has_type_var_tuple_type and len(t.type.type_vars) == 1:
|
|
3909
|
+
s += "[()]"
|
|
3910
|
+
if self.id_mapper:
|
|
3911
|
+
s += f"<{self.id_mapper.id(t.type)}>"
|
|
3912
|
+
return s
|
|
3913
|
+
|
|
3914
|
+
def visit_type_var(self, t: TypeVarType, /) -> str:
|
|
3915
|
+
if not self.options.reveal_verbose_types:
|
|
3916
|
+
s = t.name
|
|
3917
|
+
else:
|
|
3918
|
+
s = f"{t.name}`{t.id}"
|
|
3919
|
+
if self.id_mapper and t.upper_bound:
|
|
3920
|
+
s += f"(upper_bound={t.upper_bound.accept(self)})"
|
|
3921
|
+
if t.has_default() and self.options.reveal_verbose_types:
|
|
3922
|
+
s += f" = {t.default.accept(self)}"
|
|
3923
|
+
# TODO: disambiguate type variables with same name using namespace.
|
|
3924
|
+
# We should reuse find_type_overlaps() and scoped_type_var_name().
|
|
3925
|
+
return s
|
|
3926
|
+
|
|
3927
|
+
def visit_param_spec(self, t: ParamSpecType, /) -> str:
|
|
3928
|
+
# prefixes are displayed as Concatenate
|
|
3929
|
+
s = ""
|
|
3930
|
+
if t.prefix.arg_types:
|
|
3931
|
+
s += f"[{self.list_str(t.prefix.arg_types)}, **"
|
|
3932
|
+
if not self.options.reveal_verbose_types:
|
|
3933
|
+
s += t.name_with_suffix()
|
|
3934
|
+
else:
|
|
3935
|
+
s += f"{t.name_with_suffix()}`{t.id}"
|
|
3936
|
+
if t.prefix.arg_types:
|
|
3937
|
+
s += "]"
|
|
3938
|
+
if t.has_default() and self.options.reveal_verbose_types:
|
|
3939
|
+
s += f" = {t.default.accept(self)}"
|
|
3940
|
+
return s
|
|
3941
|
+
|
|
3942
|
+
def visit_parameters(self, t: Parameters, /) -> str:
|
|
3943
|
+
# This is copied from visit_callable -- is there a way to decrease duplication?
|
|
3944
|
+
if t.is_ellipsis_args:
|
|
3945
|
+
return "..."
|
|
3946
|
+
|
|
3947
|
+
s = ""
|
|
3948
|
+
bare_asterisk = False
|
|
3949
|
+
for i in range(len(t.arg_types)):
|
|
3950
|
+
if s != "":
|
|
3951
|
+
s += ", "
|
|
3952
|
+
if t.arg_kinds[i].is_named() and not bare_asterisk:
|
|
3953
|
+
s += "*, "
|
|
3954
|
+
bare_asterisk = True
|
|
3955
|
+
if t.arg_kinds[i] == ARG_STAR:
|
|
3956
|
+
s += "*"
|
|
3957
|
+
if t.arg_kinds[i] == ARG_STAR2:
|
|
3958
|
+
s += "**"
|
|
3959
|
+
name = t.arg_names[i]
|
|
3960
|
+
if name:
|
|
3961
|
+
s += f"{name}: "
|
|
3962
|
+
r = t.arg_types[i].accept(self)
|
|
3963
|
+
|
|
3964
|
+
s += r
|
|
3965
|
+
|
|
3966
|
+
if t.arg_kinds[i].is_optional():
|
|
3967
|
+
s += " ="
|
|
3968
|
+
|
|
3969
|
+
return f"[{s}]"
|
|
3970
|
+
|
|
3971
|
+
def visit_type_var_tuple(self, t: TypeVarTupleType, /) -> str:
|
|
3972
|
+
if not self.options.reveal_verbose_types:
|
|
3973
|
+
s = t.name
|
|
3974
|
+
else:
|
|
3975
|
+
s = f"{t.name}`{t.id}"
|
|
3976
|
+
if t.has_default() and self.options.reveal_verbose_types:
|
|
3977
|
+
s += f" = {t.default.accept(self)}"
|
|
3978
|
+
return s
|
|
3979
|
+
|
|
3980
|
+
def visit_callable_type(self, t: CallableType, /) -> str:
|
|
3981
|
+
param_spec = t.param_spec()
|
|
3982
|
+
if param_spec is not None:
|
|
3983
|
+
num_skip = 2
|
|
3984
|
+
else:
|
|
3985
|
+
num_skip = 0
|
|
3986
|
+
|
|
3987
|
+
s = ""
|
|
3988
|
+
asterisk = False
|
|
3989
|
+
for i in range(len(t.arg_types) - num_skip):
|
|
3990
|
+
if s != "":
|
|
3991
|
+
s += ", "
|
|
3992
|
+
if t.arg_kinds[i].is_named() and not asterisk:
|
|
3993
|
+
s += "*, "
|
|
3994
|
+
asterisk = True
|
|
3995
|
+
if t.arg_kinds[i] == ARG_STAR:
|
|
3996
|
+
s += "*"
|
|
3997
|
+
asterisk = True
|
|
3998
|
+
if t.arg_kinds[i] == ARG_STAR2:
|
|
3999
|
+
s += "**"
|
|
4000
|
+
name = t.arg_names[i]
|
|
4001
|
+
if not name and not self.options.reveal_verbose_types:
|
|
4002
|
+
# Avoid ambiguous (and weird) formatting for anonymous args/kwargs.
|
|
4003
|
+
if t.arg_kinds[i] == ARG_STAR and isinstance(t.arg_types[i], UnpackType):
|
|
4004
|
+
name = "args"
|
|
4005
|
+
elif t.arg_kinds[i] == ARG_STAR2 and t.unpack_kwargs:
|
|
4006
|
+
name = "kwargs"
|
|
4007
|
+
if name:
|
|
4008
|
+
s += name + ": "
|
|
4009
|
+
type_str = t.arg_types[i].accept(self)
|
|
4010
|
+
if t.arg_kinds[i] == ARG_STAR2 and t.unpack_kwargs:
|
|
4011
|
+
if not self.options.reveal_verbose_types:
|
|
4012
|
+
type_str = f"**{type_str}"
|
|
4013
|
+
else:
|
|
4014
|
+
type_str = f"Unpack[{type_str}]"
|
|
4015
|
+
s += type_str
|
|
4016
|
+
if t.arg_kinds[i].is_optional():
|
|
4017
|
+
s += " ="
|
|
4018
|
+
|
|
4019
|
+
if param_spec is not None:
|
|
4020
|
+
n = param_spec.name
|
|
4021
|
+
if s:
|
|
4022
|
+
s += ", "
|
|
4023
|
+
s += f"*{n}.args, **{n}.kwargs"
|
|
4024
|
+
if param_spec.has_default():
|
|
4025
|
+
s += f" = {param_spec.default.accept(self)}"
|
|
4026
|
+
|
|
4027
|
+
s = f"({s})"
|
|
4028
|
+
|
|
4029
|
+
if not isinstance(get_proper_type(t.ret_type), NoneType):
|
|
4030
|
+
if t.type_guard is not None:
|
|
4031
|
+
s += f" -> TypeGuard[{t.type_guard.accept(self)}]"
|
|
4032
|
+
elif t.type_is is not None:
|
|
4033
|
+
s += f" -> TypeIs[{t.type_is.accept(self)}]"
|
|
4034
|
+
else:
|
|
4035
|
+
s += f" -> {t.ret_type.accept(self)}"
|
|
4036
|
+
|
|
4037
|
+
if t.variables:
|
|
4038
|
+
vs = []
|
|
4039
|
+
for var in t.variables:
|
|
4040
|
+
if isinstance(var, TypeVarType):
|
|
4041
|
+
if var.values:
|
|
4042
|
+
vals = f"({', '.join(val.accept(self) for val in var.values)})"
|
|
4043
|
+
vs.append(f"{var.name} in {vals}")
|
|
4044
|
+
elif not is_named_instance(var.upper_bound, "builtins.object"):
|
|
4045
|
+
vs.append(
|
|
4046
|
+
f"{var.name} <: {var.upper_bound.accept(self)}{f' = {var.default.accept(self)}' if var.has_default() else ''}"
|
|
4047
|
+
)
|
|
4048
|
+
else:
|
|
4049
|
+
vs.append(
|
|
4050
|
+
f"{var.name}{f' = {var.default.accept(self)}' if var.has_default() else ''}"
|
|
4051
|
+
)
|
|
4052
|
+
else:
|
|
4053
|
+
# For other TypeVarLikeTypes, use the name and default
|
|
4054
|
+
vs.append(
|
|
4055
|
+
f"{var.name}{f' = {var.default.accept(self)}' if var.has_default() else ''}"
|
|
4056
|
+
)
|
|
4057
|
+
s = f"[{', '.join(vs)}] {s}"
|
|
4058
|
+
|
|
4059
|
+
return f"def {s}"
|
|
4060
|
+
|
|
4061
|
+
def visit_overloaded(self, t: Overloaded, /) -> str:
|
|
4062
|
+
a = []
|
|
4063
|
+
for i in t.items:
|
|
4064
|
+
a.append(i.accept(self))
|
|
4065
|
+
return f"Overload({', '.join(a)})"
|
|
4066
|
+
|
|
4067
|
+
def visit_tuple_type(self, t: TupleType, /) -> str:
|
|
4068
|
+
s = self.list_str(t.items) or "()"
|
|
4069
|
+
if t.partial_fallback and t.partial_fallback.type:
|
|
4070
|
+
fallback_name = t.partial_fallback.type.fullname
|
|
4071
|
+
if fallback_name != "builtins.tuple":
|
|
4072
|
+
return f"tuple[{s}, fallback={t.partial_fallback.accept(self)}]"
|
|
4073
|
+
return f"tuple[{s}]"
|
|
4074
|
+
|
|
4075
|
+
def visit_typeddict_type(self, t: TypedDictType, /) -> str:
|
|
4076
|
+
def item_str(name: str, typ: str) -> str:
|
|
4077
|
+
modifier = ""
|
|
4078
|
+
if name not in t.required_keys:
|
|
4079
|
+
modifier += "?"
|
|
4080
|
+
if name in t.readonly_keys:
|
|
4081
|
+
modifier += "="
|
|
4082
|
+
return f"{name!r}{modifier}: {typ}"
|
|
4083
|
+
|
|
4084
|
+
s = (
|
|
4085
|
+
"{"
|
|
4086
|
+
+ ", ".join(item_str(name, typ.accept(self)) for name, typ in t.items.items())
|
|
4087
|
+
+ "}"
|
|
4088
|
+
)
|
|
4089
|
+
if t.is_closed:
|
|
4090
|
+
s += ", closed=True"
|
|
4091
|
+
prefix = ""
|
|
4092
|
+
if t.fallback and t.fallback.type:
|
|
4093
|
+
if t.fallback.type.fullname not in TPDICT_FB_NAMES:
|
|
4094
|
+
if not self.options.reveal_verbose_types:
|
|
4095
|
+
prefix = t.fallback.type.fullname + ", "
|
|
4096
|
+
else:
|
|
4097
|
+
prefix = repr(t.fallback.type.fullname) + ", "
|
|
4098
|
+
return f"TypedDict({prefix}{s})"
|
|
4099
|
+
|
|
4100
|
+
def visit_raw_expression_type(self, t: RawExpressionType, /) -> str:
|
|
4101
|
+
# For bytes literals, the value is already escaped, just add quotes and b prefix
|
|
4102
|
+
if t.base_type_name == "builtins.bytes":
|
|
4103
|
+
# The value is already escaped (e.g., "foo" or "hello\\nworld")
|
|
4104
|
+
# Just add quotes and b prefix
|
|
4105
|
+
return f"b'{t.literal_value}'"
|
|
4106
|
+
return repr(t.literal_value)
|
|
4107
|
+
|
|
4108
|
+
def visit_literal_type(self, t: LiteralType, /) -> str:
|
|
4109
|
+
if isinstance(t.value, SentinelValue):
|
|
4110
|
+
return t.value_repr()
|
|
4111
|
+
return f"Literal[{t.value_repr()}]"
|
|
4112
|
+
|
|
4113
|
+
def visit_union_type(self, t: UnionType, /) -> str:
|
|
4114
|
+
return self.list_str(t.items, use_or_syntax=True)
|
|
4115
|
+
|
|
4116
|
+
def visit_partial_type(self, t: PartialType, /) -> str:
|
|
4117
|
+
if t.type is None:
|
|
4118
|
+
return "<partial None>"
|
|
4119
|
+
else:
|
|
4120
|
+
return "<partial {}[{}]>".format(t.type.name, ", ".join(["?"] * len(t.type.type_vars)))
|
|
4121
|
+
|
|
4122
|
+
def visit_ellipsis_type(self, t: EllipsisType, /) -> str:
|
|
4123
|
+
return "..."
|
|
4124
|
+
|
|
4125
|
+
def visit_type_type(self, t: TypeType, /) -> str:
|
|
4126
|
+
if t.is_type_form:
|
|
4127
|
+
type_name = "TypeForm"
|
|
4128
|
+
else:
|
|
4129
|
+
type_name = "type"
|
|
4130
|
+
return f"{type_name}[{t.item.accept(self)}]"
|
|
4131
|
+
|
|
4132
|
+
def visit_placeholder_type(self, t: PlaceholderType, /) -> str:
|
|
4133
|
+
return f"<placeholder {t.fullname}>"
|
|
4134
|
+
|
|
4135
|
+
def visit_type_alias_type(self, t: TypeAliasType, /) -> str:
|
|
4136
|
+
if t.alias is None:
|
|
4137
|
+
return "<alias (unfixed)>"
|
|
4138
|
+
if not t.is_recursive:
|
|
4139
|
+
return get_proper_type(t).accept(self)
|
|
4140
|
+
if self.dotted_aliases is None:
|
|
4141
|
+
self.dotted_aliases = set()
|
|
4142
|
+
elif t in self.dotted_aliases:
|
|
4143
|
+
return "..."
|
|
4144
|
+
self.dotted_aliases.add(t)
|
|
4145
|
+
type_str = get_proper_type(t).accept(self)
|
|
4146
|
+
self.dotted_aliases.discard(t)
|
|
4147
|
+
return type_str
|
|
4148
|
+
|
|
4149
|
+
def visit_unpack_type(self, t: UnpackType, /) -> str:
|
|
4150
|
+
if not self.options.reveal_verbose_types:
|
|
4151
|
+
return f"*{t.type.accept(self)}"
|
|
4152
|
+
return f"Unpack[{t.type.accept(self)}]"
|
|
4153
|
+
|
|
4154
|
+
def list_str(self, a: Iterable[Type], *, use_or_syntax: bool = False) -> str:
|
|
4155
|
+
"""Convert items of an array to strings (pretty-print types)
|
|
4156
|
+
and join the results with commas.
|
|
4157
|
+
"""
|
|
4158
|
+
res = []
|
|
4159
|
+
for t in a:
|
|
4160
|
+
s = t.accept(self)
|
|
4161
|
+
if use_or_syntax and isinstance(get_proper_type(t), CallableType):
|
|
4162
|
+
res.append(f"({s})")
|
|
4163
|
+
else:
|
|
4164
|
+
res.append(s)
|
|
4165
|
+
sep = ", " if not use_or_syntax else " | "
|
|
4166
|
+
return sep.join(res)
|
|
4167
|
+
|
|
4168
|
+
|
|
4169
|
+
class TrivialSyntheticTypeTranslator(TypeTranslator, SyntheticTypeVisitor[Type]):
|
|
4170
|
+
"""A base class for type translators that need to be run during semantic analysis."""
|
|
4171
|
+
|
|
4172
|
+
def visit_placeholder_type(self, t: PlaceholderType, /) -> Type:
|
|
4173
|
+
return t
|
|
4174
|
+
|
|
4175
|
+
def visit_callable_argument(self, t: CallableArgument, /) -> Type:
|
|
4176
|
+
return t
|
|
4177
|
+
|
|
4178
|
+
def visit_ellipsis_type(self, t: EllipsisType, /) -> Type:
|
|
4179
|
+
return t
|
|
4180
|
+
|
|
4181
|
+
def visit_raw_expression_type(self, t: RawExpressionType, /) -> Type:
|
|
4182
|
+
return t
|
|
4183
|
+
|
|
4184
|
+
def visit_type_list(self, t: TypeList, /) -> Type:
|
|
4185
|
+
return t
|
|
4186
|
+
|
|
4187
|
+
|
|
4188
|
+
class CollectAliasesVisitor(TypeQuery[list[mypy.nodes.TypeAlias]]):
|
|
4189
|
+
def __init__(self) -> None:
|
|
4190
|
+
super().__init__()
|
|
4191
|
+
self.seen_alias_nodes: set[mypy.nodes.TypeAlias] = set()
|
|
4192
|
+
|
|
4193
|
+
def strategy(self, items: list[list[mypy.nodes.TypeAlias]]) -> list[mypy.nodes.TypeAlias]:
|
|
4194
|
+
out = []
|
|
4195
|
+
for item in items:
|
|
4196
|
+
out.extend(item)
|
|
4197
|
+
return out
|
|
4198
|
+
|
|
4199
|
+
def visit_type_alias_type(self, t: TypeAliasType, /) -> list[mypy.nodes.TypeAlias]:
|
|
4200
|
+
assert t.alias is not None
|
|
4201
|
+
if t.alias not in self.seen_alias_nodes:
|
|
4202
|
+
self.seen_alias_nodes.add(t.alias)
|
|
4203
|
+
res = [t.alias] + t.alias.target.accept(self)
|
|
4204
|
+
else:
|
|
4205
|
+
res = []
|
|
4206
|
+
for arg in t.args:
|
|
4207
|
+
res.extend(arg.accept(self))
|
|
4208
|
+
return res
|
|
4209
|
+
|
|
4210
|
+
|
|
4211
|
+
def is_named_instance(t: Type, fullnames: str | tuple[str, ...]) -> TypeGuard[Instance]:
|
|
4212
|
+
if not isinstance(fullnames, tuple):
|
|
4213
|
+
fullnames = (fullnames,)
|
|
4214
|
+
|
|
4215
|
+
t = get_proper_type(t)
|
|
4216
|
+
return isinstance(t, Instance) and t.type.fullname in fullnames
|
|
4217
|
+
|
|
4218
|
+
|
|
4219
|
+
class HasTypeVars(BoolTypeQuery):
|
|
4220
|
+
"""Visitor for querying whether a type has a type variable component."""
|
|
4221
|
+
|
|
4222
|
+
def __init__(self) -> None:
|
|
4223
|
+
super().__init__(ANY_STRATEGY)
|
|
4224
|
+
self.skip_alias_target = True
|
|
4225
|
+
|
|
4226
|
+
def visit_type_var(self, t: TypeVarType) -> bool:
|
|
4227
|
+
return True
|
|
4228
|
+
|
|
4229
|
+
def visit_type_var_tuple(self, t: TypeVarTupleType) -> bool:
|
|
4230
|
+
return True
|
|
4231
|
+
|
|
4232
|
+
def visit_param_spec(self, t: ParamSpecType) -> bool:
|
|
4233
|
+
return True
|
|
4234
|
+
|
|
4235
|
+
|
|
4236
|
+
def has_type_vars(typ: Type) -> bool:
|
|
4237
|
+
"""Check if a type contains any type variables (recursively)."""
|
|
4238
|
+
return typ.accept(HasTypeVars())
|
|
4239
|
+
|
|
4240
|
+
|
|
4241
|
+
class HasRecursiveType(BoolTypeQuery):
|
|
4242
|
+
def __init__(self) -> None:
|
|
4243
|
+
super().__init__(ANY_STRATEGY)
|
|
4244
|
+
|
|
4245
|
+
def visit_type_alias_type(self, t: TypeAliasType) -> bool:
|
|
4246
|
+
return t.is_recursive or self.query_types(t.args)
|
|
4247
|
+
|
|
4248
|
+
|
|
4249
|
+
# Use singleton since this is hot (note: call reset() before using)
|
|
4250
|
+
_has_recursive_type: Final = HasRecursiveType()
|
|
4251
|
+
|
|
4252
|
+
|
|
4253
|
+
def has_recursive_types(typ: Type) -> bool:
|
|
4254
|
+
"""Check if a type contains any recursive aliases (recursively)."""
|
|
4255
|
+
_has_recursive_type.reset()
|
|
4256
|
+
return typ.accept(_has_recursive_type)
|
|
4257
|
+
|
|
4258
|
+
|
|
4259
|
+
def split_with_prefix_and_suffix(
|
|
4260
|
+
types: tuple[Type, ...], prefix: int, suffix: int
|
|
4261
|
+
) -> tuple[tuple[Type, ...], tuple[Type, ...], tuple[Type, ...]]:
|
|
4262
|
+
# The caller must validate that the split can be satisfied, i.e. there is
|
|
4263
|
+
# enough capacity in either initial type list or there is a variadic unpack.
|
|
4264
|
+
# Otherwise, this function may return nonsensical result.
|
|
4265
|
+
# TODO: should we add an assert here?
|
|
4266
|
+
needs_extend = False
|
|
4267
|
+
index = find_unpack_in_list(types)
|
|
4268
|
+
if index is not None:
|
|
4269
|
+
needs_extend = index < prefix or len(types) - index - 1 < suffix
|
|
4270
|
+
if needs_extend:
|
|
4271
|
+
types = extend_args_for_prefix_and_suffix(types, prefix, suffix)
|
|
4272
|
+
if suffix:
|
|
4273
|
+
return types[:prefix], types[prefix:-suffix], types[-suffix:]
|
|
4274
|
+
else:
|
|
4275
|
+
return types[:prefix], types[prefix:], ()
|
|
4276
|
+
|
|
4277
|
+
|
|
4278
|
+
def extend_args_for_prefix_and_suffix(
|
|
4279
|
+
types: tuple[Type, ...], prefix: int, suffix: int
|
|
4280
|
+
) -> tuple[Type, ...]:
|
|
4281
|
+
"""Extend list of types by eating out from variadic tuple to satisfy prefix and suffix."""
|
|
4282
|
+
idx = None
|
|
4283
|
+
item = None
|
|
4284
|
+
for i, t in enumerate(types):
|
|
4285
|
+
if isinstance(t, UnpackType):
|
|
4286
|
+
p_type = get_proper_type(t.type)
|
|
4287
|
+
if isinstance(p_type, Instance) and p_type.type.fullname == "builtins.tuple":
|
|
4288
|
+
item = p_type.args[0]
|
|
4289
|
+
idx = i
|
|
4290
|
+
break
|
|
4291
|
+
|
|
4292
|
+
if idx is None:
|
|
4293
|
+
return types
|
|
4294
|
+
assert item is not None
|
|
4295
|
+
if idx < prefix:
|
|
4296
|
+
start = (item,) * (prefix - idx)
|
|
4297
|
+
else:
|
|
4298
|
+
start = ()
|
|
4299
|
+
if len(types) - idx - 1 < suffix:
|
|
4300
|
+
end = (item,) * (suffix - len(types) + idx + 1)
|
|
4301
|
+
else:
|
|
4302
|
+
end = ()
|
|
4303
|
+
return types[:idx] + start + (types[idx],) + end + types[idx + 1 :]
|
|
4304
|
+
|
|
4305
|
+
|
|
4306
|
+
def flatten_nested_unions(
|
|
4307
|
+
types: Sequence[Type], *, handle_type_alias_type: bool = True, handle_recursive: bool = True
|
|
4308
|
+
) -> list[Type]:
|
|
4309
|
+
"""Flatten nested unions in a type list."""
|
|
4310
|
+
if not isinstance(types, list):
|
|
4311
|
+
typelist = list(types)
|
|
4312
|
+
else:
|
|
4313
|
+
typelist = cast("list[Type]", types)
|
|
4314
|
+
|
|
4315
|
+
# Fast path: most of the time there is nothing to flatten
|
|
4316
|
+
if not any(isinstance(t, (TypeAliasType, UnionType)) for t in typelist): # type: ignore[misc]
|
|
4317
|
+
return typelist
|
|
4318
|
+
|
|
4319
|
+
flat_items: list[Type] = []
|
|
4320
|
+
for t in typelist:
|
|
4321
|
+
if handle_type_alias_type and isinstance(t, TypeAliasType):
|
|
4322
|
+
if not handle_recursive and t.is_recursive:
|
|
4323
|
+
tp: Type = t
|
|
4324
|
+
else:
|
|
4325
|
+
tp = get_proper_type(t)
|
|
4326
|
+
else:
|
|
4327
|
+
tp = t
|
|
4328
|
+
if isinstance(tp, ProperType) and isinstance(tp, UnionType):
|
|
4329
|
+
flat_items.extend(
|
|
4330
|
+
flatten_nested_unions(
|
|
4331
|
+
tp.items,
|
|
4332
|
+
handle_type_alias_type=handle_type_alias_type,
|
|
4333
|
+
handle_recursive=handle_recursive,
|
|
4334
|
+
)
|
|
4335
|
+
)
|
|
4336
|
+
else:
|
|
4337
|
+
# Must preserve original aliases when possible.
|
|
4338
|
+
flat_items.append(t)
|
|
4339
|
+
return flat_items
|
|
4340
|
+
|
|
4341
|
+
|
|
4342
|
+
def find_unpack_in_list(items: Sequence[Type]) -> int | None:
|
|
4343
|
+
unpack_index: int | None = None
|
|
4344
|
+
for i, item in enumerate(items):
|
|
4345
|
+
if isinstance(item, UnpackType):
|
|
4346
|
+
# We cannot fail here, so we must check this in an earlier
|
|
4347
|
+
# semanal phase.
|
|
4348
|
+
# Funky code here avoids mypyc narrowing the type of unpack_index.
|
|
4349
|
+
old_index = unpack_index
|
|
4350
|
+
assert old_index is None
|
|
4351
|
+
# Don't return so that we can also sanity-check there is only one.
|
|
4352
|
+
unpack_index = i
|
|
4353
|
+
return unpack_index
|
|
4354
|
+
|
|
4355
|
+
|
|
4356
|
+
def flatten_nested_tuples(types: Iterable[Type], handle_recursive: bool = True) -> list[Type]:
|
|
4357
|
+
"""Recursively flatten TupleTypes nested with Unpack.
|
|
4358
|
+
|
|
4359
|
+
For example this will transform
|
|
4360
|
+
Tuple[A, Unpack[Tuple[B, Unpack[Tuple[C, D]]]]]
|
|
4361
|
+
into
|
|
4362
|
+
Tuple[A, B, C, D]
|
|
4363
|
+
"""
|
|
4364
|
+
res = []
|
|
4365
|
+
for typ in types:
|
|
4366
|
+
if not isinstance(typ, UnpackType):
|
|
4367
|
+
res.append(typ)
|
|
4368
|
+
continue
|
|
4369
|
+
p_type = get_proper_type(typ.type)
|
|
4370
|
+
if (
|
|
4371
|
+
not isinstance(p_type, TupleType)
|
|
4372
|
+
or not handle_recursive
|
|
4373
|
+
and isinstance(typ.type, TypeAliasType)
|
|
4374
|
+
and typ.type.is_recursive
|
|
4375
|
+
):
|
|
4376
|
+
res.append(typ)
|
|
4377
|
+
continue
|
|
4378
|
+
if isinstance(typ.type, TypeAliasType):
|
|
4379
|
+
items = []
|
|
4380
|
+
for item in p_type.items:
|
|
4381
|
+
if (
|
|
4382
|
+
isinstance(item, ProperType)
|
|
4383
|
+
and isinstance(item, Instance)
|
|
4384
|
+
or isinstance(item, TypeAliasType)
|
|
4385
|
+
):
|
|
4386
|
+
if len(item.args) == 0:
|
|
4387
|
+
item = item.copy_modified()
|
|
4388
|
+
item.set_line(typ)
|
|
4389
|
+
items.append(item)
|
|
4390
|
+
else:
|
|
4391
|
+
items = p_type.items
|
|
4392
|
+
res.extend(flatten_nested_tuples(items))
|
|
4393
|
+
return res
|
|
4394
|
+
|
|
4395
|
+
|
|
4396
|
+
def is_literal_type(typ: ProperType, fallback_fullname: str, value: LiteralValue) -> bool:
|
|
4397
|
+
"""Check if this type is a LiteralType with the given fallback type and value."""
|
|
4398
|
+
if isinstance(typ, Instance) and typ.last_known_value:
|
|
4399
|
+
typ = typ.last_known_value
|
|
4400
|
+
return (
|
|
4401
|
+
isinstance(typ, LiteralType)
|
|
4402
|
+
and typ.fallback.type.fullname == fallback_fullname
|
|
4403
|
+
and typ.value == value
|
|
4404
|
+
)
|
|
4405
|
+
|
|
4406
|
+
|
|
4407
|
+
def is_unannotated_any(t: Type) -> bool:
|
|
4408
|
+
"""Check if type represents an implicit (unannotated) Any.
|
|
4409
|
+
|
|
4410
|
+
This is used to check for functions with unspecified/not fully specified types.
|
|
4411
|
+
"""
|
|
4412
|
+
if not isinstance(t, ProperType):
|
|
4413
|
+
return False
|
|
4414
|
+
return isinstance(t, AnyType) and t.type_of_any == TypeOfAny.unannotated
|
|
4415
|
+
|
|
4416
|
+
|
|
4417
|
+
names: Final = globals().copy()
|
|
4418
|
+
names.pop("NOT_READY", None)
|
|
4419
|
+
deserialize_map: Final = {
|
|
4420
|
+
key: obj.deserialize
|
|
4421
|
+
for key, obj in names.items()
|
|
4422
|
+
if isinstance(obj, type) and issubclass(obj, Type) and obj is not Type
|
|
4423
|
+
}
|
|
4424
|
+
|
|
4425
|
+
|
|
4426
|
+
def callable_with_ellipsis(any_type: AnyType, ret_type: Type, fallback: Instance) -> CallableType:
|
|
4427
|
+
"""Construct type Callable[..., ret_type]."""
|
|
4428
|
+
return CallableType(
|
|
4429
|
+
[any_type, any_type],
|
|
4430
|
+
[ARG_STAR, ARG_STAR2],
|
|
4431
|
+
[None, None],
|
|
4432
|
+
ret_type=ret_type,
|
|
4433
|
+
fallback=fallback,
|
|
4434
|
+
is_ellipsis_args=True,
|
|
4435
|
+
)
|
|
4436
|
+
|
|
4437
|
+
|
|
4438
|
+
def remove_dups(types: list[T]) -> list[T]:
|
|
4439
|
+
if len(types) <= 1:
|
|
4440
|
+
return types
|
|
4441
|
+
# Get unique elements in order of appearance
|
|
4442
|
+
all_types: set[T] = set()
|
|
4443
|
+
new_types: list[T] = []
|
|
4444
|
+
for t in types:
|
|
4445
|
+
if t not in all_types:
|
|
4446
|
+
new_types.append(t)
|
|
4447
|
+
all_types.add(t)
|
|
4448
|
+
return new_types
|
|
4449
|
+
|
|
4450
|
+
|
|
4451
|
+
def type_vars_as_args(type_vars: Sequence[TypeVarLikeType]) -> tuple[Type, ...]:
|
|
4452
|
+
"""Represent type variables as they would appear in a type argument list."""
|
|
4453
|
+
args: list[Type] = []
|
|
4454
|
+
for tv in type_vars:
|
|
4455
|
+
if isinstance(tv, TypeVarTupleType):
|
|
4456
|
+
args.append(UnpackType(tv))
|
|
4457
|
+
else:
|
|
4458
|
+
args.append(tv)
|
|
4459
|
+
return tuple(args)
|
|
4460
|
+
|
|
4461
|
+
|
|
4462
|
+
def get_variadic_item(tup: TupleType) -> tuple[int, Type] | None:
|
|
4463
|
+
"""If this is tuple[X, *tuple[Y, ...], Z], return Y, otherwise None."""
|
|
4464
|
+
unpack_index = find_unpack_in_list(tup.items)
|
|
4465
|
+
if unpack_index is None:
|
|
4466
|
+
return None
|
|
4467
|
+
unpack = tup.items[unpack_index]
|
|
4468
|
+
assert isinstance(unpack, UnpackType)
|
|
4469
|
+
unpacked = get_proper_type(unpack.type)
|
|
4470
|
+
if not isinstance(unpacked, Instance):
|
|
4471
|
+
return None
|
|
4472
|
+
assert unpacked.type.fullname == "builtins.tuple"
|
|
4473
|
+
return unpack_index, unpacked.args[0]
|
|
4474
|
+
|
|
4475
|
+
|
|
4476
|
+
# See docstring for mypy/cache.py for reserved tag ranges.
|
|
4477
|
+
# Instance-related tags.
|
|
4478
|
+
INSTANCE: Final[Tag] = 80
|
|
4479
|
+
INSTANCE_SIMPLE: Final[Tag] = 81
|
|
4480
|
+
INSTANCE_GENERIC: Final[Tag] = 82
|
|
4481
|
+
INSTANCE_STR: Final[Tag] = 83
|
|
4482
|
+
INSTANCE_FUNCTION: Final[Tag] = 84
|
|
4483
|
+
INSTANCE_INT: Final[Tag] = 85
|
|
4484
|
+
INSTANCE_BOOL: Final[Tag] = 86
|
|
4485
|
+
INSTANCE_OBJECT: Final[Tag] = 87
|
|
4486
|
+
|
|
4487
|
+
# Other type tags.
|
|
4488
|
+
TYPE_ALIAS_TYPE: Final[Tag] = 100
|
|
4489
|
+
TYPE_VAR_TYPE: Final[Tag] = 101
|
|
4490
|
+
PARAM_SPEC_TYPE: Final[Tag] = 102
|
|
4491
|
+
TYPE_VAR_TUPLE_TYPE: Final[Tag] = 103
|
|
4492
|
+
UNBOUND_TYPE: Final[Tag] = 104
|
|
4493
|
+
UNPACK_TYPE: Final[Tag] = 105
|
|
4494
|
+
ANY_TYPE: Final[Tag] = 106
|
|
4495
|
+
UNINHABITED_TYPE: Final[Tag] = 107
|
|
4496
|
+
NONE_TYPE: Final[Tag] = 108
|
|
4497
|
+
DELETED_TYPE: Final[Tag] = 109
|
|
4498
|
+
CALLABLE_TYPE: Final[Tag] = 110
|
|
4499
|
+
OVERLOADED: Final[Tag] = 111
|
|
4500
|
+
TUPLE_TYPE: Final[Tag] = 112
|
|
4501
|
+
TYPED_DICT_TYPE: Final[Tag] = 113
|
|
4502
|
+
LITERAL_TYPE: Final[Tag] = 114
|
|
4503
|
+
UNION_TYPE: Final[Tag] = 115
|
|
4504
|
+
TYPE_TYPE: Final[Tag] = 116
|
|
4505
|
+
PARAMETERS: Final[Tag] = 117
|
|
4506
|
+
LIST_TYPE: Final[Tag] = 118 # Only valid in serialized ASTs
|
|
4507
|
+
ELLIPSIS_TYPE: Final[Tag] = 119 # Only valid in serialized ASTs
|
|
4508
|
+
RAW_EXPRESSION_TYPE: Final[Tag] = 120 # Only valid in serialized ASTs
|
|
4509
|
+
CALL_TYPE: Final[Tag] = 121 # Only valid in serialized ASTs
|
|
4510
|
+
|
|
4511
|
+
|
|
4512
|
+
def read_type(data: ReadBuffer, tag: Tag | None = None) -> Type:
|
|
4513
|
+
if tag is None:
|
|
4514
|
+
tag = read_tag(data)
|
|
4515
|
+
# The branches here are ordered manually by type "popularity".
|
|
4516
|
+
if tag == INSTANCE:
|
|
4517
|
+
return Instance.read(data)
|
|
4518
|
+
if tag == ANY_TYPE:
|
|
4519
|
+
return AnyType.read(data)
|
|
4520
|
+
if tag == TYPE_VAR_TYPE:
|
|
4521
|
+
return TypeVarType.read(data)
|
|
4522
|
+
if tag == CALLABLE_TYPE:
|
|
4523
|
+
return CallableType.read(data)
|
|
4524
|
+
if tag == NONE_TYPE:
|
|
4525
|
+
return NoneType.read(data)
|
|
4526
|
+
if tag == UNION_TYPE:
|
|
4527
|
+
return UnionType.read(data)
|
|
4528
|
+
if tag == LITERAL_TYPE:
|
|
4529
|
+
return LiteralType.read(data)
|
|
4530
|
+
if tag == TYPE_ALIAS_TYPE:
|
|
4531
|
+
return TypeAliasType.read(data)
|
|
4532
|
+
if tag == TUPLE_TYPE:
|
|
4533
|
+
return TupleType.read(data)
|
|
4534
|
+
if tag == TYPED_DICT_TYPE:
|
|
4535
|
+
return TypedDictType.read(data)
|
|
4536
|
+
if tag == TYPE_TYPE:
|
|
4537
|
+
return TypeType.read(data)
|
|
4538
|
+
if tag == OVERLOADED:
|
|
4539
|
+
return Overloaded.read(data)
|
|
4540
|
+
if tag == PARAM_SPEC_TYPE:
|
|
4541
|
+
return ParamSpecType.read(data)
|
|
4542
|
+
if tag == TYPE_VAR_TUPLE_TYPE:
|
|
4543
|
+
return TypeVarTupleType.read(data)
|
|
4544
|
+
if tag == UNPACK_TYPE:
|
|
4545
|
+
return UnpackType.read(data)
|
|
4546
|
+
if tag == PARAMETERS:
|
|
4547
|
+
return Parameters.read(data)
|
|
4548
|
+
if tag == UNINHABITED_TYPE:
|
|
4549
|
+
return UninhabitedType.read(data)
|
|
4550
|
+
if tag == UNBOUND_TYPE:
|
|
4551
|
+
return UnboundType.read(data)
|
|
4552
|
+
if tag == DELETED_TYPE:
|
|
4553
|
+
return DeletedType.read(data)
|
|
4554
|
+
assert False, f"Unknown type tag {tag}"
|
|
4555
|
+
|
|
4556
|
+
|
|
4557
|
+
def read_function_like(data: ReadBuffer, tag: Tag) -> FunctionLike:
|
|
4558
|
+
if tag == CALLABLE_TYPE:
|
|
4559
|
+
return CallableType.read(data)
|
|
4560
|
+
if tag == OVERLOADED:
|
|
4561
|
+
return Overloaded.read(data)
|
|
4562
|
+
assert False, f"Invalid type tag for FunctionLike {tag}"
|
|
4563
|
+
|
|
4564
|
+
|
|
4565
|
+
def read_type_var_likes(data: ReadBuffer) -> list[TypeVarLikeType]:
|
|
4566
|
+
"""Specialized version of read_type_list() for lists of type variables."""
|
|
4567
|
+
assert read_tag(data) == LIST_GEN
|
|
4568
|
+
ret: list[TypeVarLikeType] = []
|
|
4569
|
+
for _ in range(read_int_bare(data)):
|
|
4570
|
+
tag = read_tag(data)
|
|
4571
|
+
if tag == TYPE_VAR_TYPE:
|
|
4572
|
+
ret.append(TypeVarType.read(data))
|
|
4573
|
+
elif tag == PARAM_SPEC_TYPE:
|
|
4574
|
+
ret.append(ParamSpecType.read(data))
|
|
4575
|
+
elif tag == TYPE_VAR_TUPLE_TYPE:
|
|
4576
|
+
ret.append(TypeVarTupleType.read(data))
|
|
4577
|
+
else:
|
|
4578
|
+
assert False, f"Invalid type tag for TypeVarLikeType {tag}"
|
|
4579
|
+
return ret
|
|
4580
|
+
|
|
4581
|
+
|
|
4582
|
+
def read_type_opt(data: ReadBuffer) -> Type | None:
|
|
4583
|
+
tag = read_tag(data)
|
|
4584
|
+
if tag == LITERAL_NONE:
|
|
4585
|
+
return None
|
|
4586
|
+
return read_type(data, tag)
|
|
4587
|
+
|
|
4588
|
+
|
|
4589
|
+
def write_type_opt(data: WriteBuffer, value: Type | None) -> None:
|
|
4590
|
+
if value is not None:
|
|
4591
|
+
value.write(data)
|
|
4592
|
+
else:
|
|
4593
|
+
write_tag(data, LITERAL_NONE)
|
|
4594
|
+
|
|
4595
|
+
|
|
4596
|
+
def read_type_list(data: ReadBuffer) -> list[Type]:
|
|
4597
|
+
assert read_tag(data) == LIST_GEN
|
|
4598
|
+
size = read_int_bare(data)
|
|
4599
|
+
return [read_type(data) for _ in range(size)]
|
|
4600
|
+
|
|
4601
|
+
|
|
4602
|
+
def write_type_list(data: WriteBuffer, value: Sequence[Type]) -> None:
|
|
4603
|
+
write_tag(data, LIST_GEN)
|
|
4604
|
+
write_int_bare(data, len(value))
|
|
4605
|
+
for item in value:
|
|
4606
|
+
item.write(data)
|
|
4607
|
+
|
|
4608
|
+
|
|
4609
|
+
def read_type_map(data: ReadBuffer) -> dict[str, Type]:
|
|
4610
|
+
assert read_tag(data) == DICT_STR_GEN
|
|
4611
|
+
size = read_int_bare(data)
|
|
4612
|
+
return {read_str_bare(data): read_type(data) for _ in range(size)}
|
|
4613
|
+
|
|
4614
|
+
|
|
4615
|
+
def write_type_map(data: WriteBuffer, value: dict[str, Type]) -> None:
|
|
4616
|
+
write_tag(data, DICT_STR_GEN)
|
|
4617
|
+
write_int_bare(data, len(value))
|
|
4618
|
+
for key in sorted(value):
|
|
4619
|
+
write_str_bare(data, key)
|
|
4620
|
+
value[key].write(data)
|
|
4621
|
+
|
|
4622
|
+
|
|
4623
|
+
# This cyclic import is unfortunate, but to avoid it we would need to move away all uses
|
|
4624
|
+
# of get_proper_type() from types.py. Majority of them have been removed, but few remaining
|
|
4625
|
+
# are quite tricky to get rid of, but ultimately we want to do it at some point.
|
|
4626
|
+
from mypy.expandtype import ExpandTypeVisitor
|
|
4627
|
+
|
|
4628
|
+
|
|
4629
|
+
class InstantiateAliasVisitor(ExpandTypeVisitor):
|
|
4630
|
+
def visit_union_type(self, t: UnionType) -> Type:
|
|
4631
|
+
# Unlike regular expand_type(), we don't do any simplification for unions,
|
|
4632
|
+
# not even removing strict duplicates. There are three reasons for this:
|
|
4633
|
+
# * get_proper_type() is a very hot function, even slightest slow down will
|
|
4634
|
+
# cause a perf regression
|
|
4635
|
+
# * We want to preserve this historical behaviour, to avoid possible
|
|
4636
|
+
# regressions
|
|
4637
|
+
# * Simplifying unions may (indirectly) call get_proper_type(), causing
|
|
4638
|
+
# infinite recursion.
|
|
4639
|
+
return TypeTranslator.visit_union_type(self, t)
|