Compare commits
3 Commits
cjm/panic-
...
cjm/nomrof
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59dedb5d3c | ||
|
|
46a1fd3b3e | ||
|
|
327b913d68 |
4
.github/workflows/build-docker.yml
vendored
4
.github/workflows/build-docker.yml
vendored
@@ -79,7 +79,7 @@ jobs:
|
||||
# Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/
|
||||
- name: Build and push by digest
|
||||
id: build
|
||||
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6
|
||||
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6
|
||||
with:
|
||||
context: .
|
||||
platforms: ${{ matrix.platform }}
|
||||
@@ -231,7 +231,7 @@ jobs:
|
||||
${{ env.TAG_PATTERNS }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6
|
||||
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
||||
16
.github/workflows/ci.yaml
vendored
16
.github/workflows/ci.yaml
vendored
@@ -239,11 +239,11 @@ jobs:
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18 # v2
|
||||
uses: taiki-e/install-action@09dc018eee06ae1c9e0409786563f534210ceb83 # v2
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Install cargo insta"
|
||||
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18 # v2
|
||||
uses: taiki-e/install-action@09dc018eee06ae1c9e0409786563f534210ceb83 # v2
|
||||
with:
|
||||
tool: cargo-insta
|
||||
- name: Red-knot mdtests (GitHub annotations)
|
||||
@@ -293,11 +293,11 @@ jobs:
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18 # v2
|
||||
uses: taiki-e/install-action@09dc018eee06ae1c9e0409786563f534210ceb83 # v2
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Install cargo insta"
|
||||
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18 # v2
|
||||
uses: taiki-e/install-action@09dc018eee06ae1c9e0409786563f534210ceb83 # v2
|
||||
with:
|
||||
tool: cargo-insta
|
||||
- name: "Run tests"
|
||||
@@ -320,7 +320,7 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18 # v2
|
||||
uses: taiki-e/install-action@09dc018eee06ae1c9e0409786563f534210ceb83 # v2
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Run tests"
|
||||
@@ -403,11 +403,11 @@ jobs:
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18 # v2
|
||||
uses: taiki-e/install-action@09dc018eee06ae1c9e0409786563f534210ceb83 # v2
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Install cargo insta"
|
||||
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18 # v2
|
||||
uses: taiki-e/install-action@09dc018eee06ae1c9e0409786563f534210ceb83 # v2
|
||||
with:
|
||||
tool: cargo-insta
|
||||
- name: "Run tests"
|
||||
@@ -857,7 +857,7 @@ jobs:
|
||||
run: rustup show
|
||||
|
||||
- name: "Install codspeed"
|
||||
uses: taiki-e/install-action@ab3728c7ba6948b9b429627f4d55a68842b27f18 # v2
|
||||
uses: taiki-e/install-action@09dc018eee06ae1c9e0409786563f534210ceb83 # v2
|
||||
with:
|
||||
tool: cargo-codspeed
|
||||
|
||||
|
||||
10
.github/workflows/release.yml
vendored
10
.github/workflows/release.yml
vendored
@@ -129,14 +129,14 @@ jobs:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
- name: Install cached dist
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
with:
|
||||
name: cargo-dist-cache
|
||||
path: ~/.cargo/bin/
|
||||
- run: chmod +x ~/.cargo/bin/dist
|
||||
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
|
||||
- name: Fetch local artifacts
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
with:
|
||||
pattern: artifacts-*
|
||||
path: target/distrib/
|
||||
@@ -180,14 +180,14 @@ jobs:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
- name: Install cached dist
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
with:
|
||||
name: cargo-dist-cache
|
||||
path: ~/.cargo/bin/
|
||||
- run: chmod +x ~/.cargo/bin/dist
|
||||
# Fetch artifacts from scratch-storage
|
||||
- name: Fetch artifacts
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
with:
|
||||
pattern: artifacts-*
|
||||
path: target/distrib/
|
||||
@@ -257,7 +257,7 @@ jobs:
|
||||
submodules: recursive
|
||||
# Create a GitHub Release while uploading all files to it
|
||||
- name: "Download GitHub Artifacts"
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
with:
|
||||
pattern: artifacts-*
|
||||
path: artifacts
|
||||
|
||||
@@ -79,7 +79,7 @@ repos:
|
||||
pass_filenames: false # This makes it a lot faster
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.11.7
|
||||
rev: v0.11.6
|
||||
hooks:
|
||||
- id: ruff-format
|
||||
- id: ruff
|
||||
|
||||
119
Cargo.lock
generated
119
Cargo.lock
generated
@@ -394,7 +394,7 @@ dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -490,6 +490,20 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "compact_str"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32"
|
||||
dependencies = [
|
||||
"castaway",
|
||||
"cfg-if",
|
||||
"itoa",
|
||||
"rustversion",
|
||||
"ryu",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "compact_str"
|
||||
version = "0.9.0"
|
||||
@@ -710,7 +724,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -721,7 +735,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -791,7 +805,7 @@ dependencies = [
|
||||
"glob",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -823,7 +837,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1309,7 +1323,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1474,7 +1488,7 @@ dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1539,9 +1553,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.10"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a064218214dc6a10fbae5ec5fa888d80c45d611aba169222fc272072bf7aef6"
|
||||
checksum = "59ec30f7142be6fe14e1b021f50b85db8df2d4324ea6e91ec3e5dcde092021d0"
|
||||
dependencies = [
|
||||
"jiff-static",
|
||||
"jiff-tzdb-platform",
|
||||
@@ -1549,18 +1563,18 @@ dependencies = [
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"serde",
|
||||
"windows-sys 0.52.0",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jiff-static"
|
||||
version = "0.2.10"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "199b7932d97e325aff3a7030e141eafe7f2c6268e1d1b24859b753a627f45254"
|
||||
checksum = "526b834d727fd59d37b076b0c3236d9adde1b1729a4361e20b2026f738cc1dbe"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1657,7 +1671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfa96ed35d0dccc67cf7ba49350cb86de3dcb1d072a7ab28f99117f19d874953"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2166,7 +2180,7 @@ dependencies = [
|
||||
"pest_meta",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2235,7 +2249,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2558,7 +2572,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"bitflags 2.9.0",
|
||||
"camino",
|
||||
"compact_str",
|
||||
"compact_str 0.9.0",
|
||||
"countme",
|
||||
"dir-test",
|
||||
"drop_bomb",
|
||||
@@ -2647,7 +2661,6 @@ dependencies = [
|
||||
"tempfile",
|
||||
"thiserror 2.0.12",
|
||||
"toml",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3061,7 +3074,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"ruff_python_trivia",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3088,7 +3101,7 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"bitflags 2.9.0",
|
||||
"compact_str",
|
||||
"compact_str 0.9.0",
|
||||
"is-macro",
|
||||
"itertools 0.14.0",
|
||||
"memchr",
|
||||
@@ -3186,7 +3199,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"bitflags 2.9.0",
|
||||
"bstr",
|
||||
"compact_str",
|
||||
"compact_str 0.9.0",
|
||||
"insta",
|
||||
"memchr",
|
||||
"ruff_annotate_snippets",
|
||||
@@ -3444,11 +3457,11 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "salsa"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=c75b0161aba55965ab6ad8cc9aaee7dc177967f1#c75b0161aba55965ab6ad8cc9aaee7dc177967f1"
|
||||
version = "0.19.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=87bf6b6c2d5f6479741271da73bd9d30c2580c26#87bf6b6c2d5f6479741271da73bd9d30c2580c26"
|
||||
dependencies = [
|
||||
"boxcar",
|
||||
"compact_str",
|
||||
"compact_str 0.8.1",
|
||||
"crossbeam-queue",
|
||||
"dashmap 6.1.0",
|
||||
"hashbrown 0.15.2",
|
||||
@@ -3467,18 +3480,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "salsa-macro-rules"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=c75b0161aba55965ab6ad8cc9aaee7dc177967f1#c75b0161aba55965ab6ad8cc9aaee7dc177967f1"
|
||||
version = "0.19.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=87bf6b6c2d5f6479741271da73bd9d30c2580c26#87bf6b6c2d5f6479741271da73bd9d30c2580c26"
|
||||
|
||||
[[package]]
|
||||
name = "salsa-macros"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=c75b0161aba55965ab6ad8cc9aaee7dc177967f1#c75b0161aba55965ab6ad8cc9aaee7dc177967f1"
|
||||
version = "0.19.0"
|
||||
source = "git+https://github.com/salsa-rs/salsa.git?rev=87bf6b6c2d5f6479741271da73bd9d30c2580c26#87bf6b6c2d5f6479741271da73bd9d30c2580c26"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
@@ -3512,7 +3525,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde_derive_internals",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3561,7 +3574,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3572,7 +3585,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3595,7 +3608,7 @@ checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3636,7 +3649,7 @@ dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3767,7 +3780,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3783,9 +3796,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.101"
|
||||
version = "2.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
|
||||
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3800,7 +3813,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3871,7 +3884,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3882,7 +3895,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
"test-case-core",
|
||||
]
|
||||
|
||||
@@ -3918,7 +3931,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3929,7 +3942,7 @@ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4060,7 +4073,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4327,7 +4340,7 @@ checksum = "72dcd78c4f979627a754f5522cea6e6a25e55139056535fe6e69c506cd64a862"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4449,7 +4462,7 @@ dependencies = [
|
||||
"log",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@@ -4484,7 +4497,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
@@ -4519,7 +4532,7 @@ checksum = "17d5042cc5fa009658f9a7333ef24291b1291a25b6382dd68862a7f3b969f69b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4634,7 +4647,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4645,7 +4658,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4883,7 +4896,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
@@ -4904,7 +4917,7 @@ checksum = "6352c01d0edd5db859a63e2605f4ea3183ddbd15e2c4a9e7d32184df75e4f154"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4924,7 +4937,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
@@ -4947,7 +4960,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.101",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -124,7 +124,7 @@ rayon = { version = "1.10.0" }
|
||||
regex = { version = "1.10.2" }
|
||||
rustc-hash = { version = "2.0.0" }
|
||||
# When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml`
|
||||
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "c75b0161aba55965ab6ad8cc9aaee7dc177967f1" }
|
||||
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "87bf6b6c2d5f6479741271da73bd9d30c2580c26" }
|
||||
schemars = { version = "0.8.16" }
|
||||
seahash = { version = "4.1.0" }
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
@@ -342,5 +342,5 @@ global = "depot-ubuntu-latest-4"
|
||||
[workspace.metadata.dist.github-action-commits]
|
||||
"actions/checkout" = "85e6279cec87321a52edac9c87bce653a07cf6c2" # v4
|
||||
"actions/upload-artifact" = "6027e3dd177782cd8ab9af838c04fd81a07f1d47" # v4.6.2
|
||||
"actions/download-artifact" = "d3f86a106a0bac45b974a628896c90dbdf5c8093" # v4.3.0
|
||||
"actions/download-artifact" = "95815c38cf2ff2164869cbab79da8d1f422bc89e" # v4.2.1
|
||||
"actions/attest-build-provenance" = "c074443f1aee8d4aeeae555aebba3282517141b2" #v2.2.3
|
||||
|
||||
@@ -105,19 +105,6 @@ pub(crate) struct CheckCommand {
|
||||
/// Watch files for changes and recheck files related to the changed files.
|
||||
#[arg(long, short = 'W')]
|
||||
pub(crate) watch: bool,
|
||||
|
||||
/// Respect file exclusions via `.gitignore` and other standard ignore files.
|
||||
/// Use `--no-respect-gitignore` to disable.
|
||||
#[arg(
|
||||
long,
|
||||
overrides_with("no_respect_ignore_files"),
|
||||
help_heading = "File selection",
|
||||
default_missing_value = "true",
|
||||
num_args = 0..1
|
||||
)]
|
||||
respect_ignore_files: Option<bool>,
|
||||
#[clap(long, overrides_with("respect_ignore_files"), hide = true)]
|
||||
no_respect_ignore_files: bool,
|
||||
}
|
||||
|
||||
impl CheckCommand {
|
||||
@@ -133,13 +120,6 @@ impl CheckCommand {
|
||||
)
|
||||
};
|
||||
|
||||
// --no-respect-gitignore defaults to false and is set true by CLI flag. If passed, override config file
|
||||
// Otherwise, only pass this through if explicitly set (don't default to anything here to
|
||||
// make sure that doesn't take precedence over an explicitly-set config file value)
|
||||
let respect_ignore_files = self
|
||||
.no_respect_ignore_files
|
||||
.then_some(false)
|
||||
.or(self.respect_ignore_files);
|
||||
Options {
|
||||
environment: Some(EnvironmentOptions {
|
||||
python_version: self
|
||||
@@ -164,7 +144,6 @@ impl CheckCommand {
|
||||
error_on_warning: self.error_on_warning,
|
||||
}),
|
||||
rules,
|
||||
respect_ignore_files,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,12 +169,8 @@ pub enum ExitStatus {
|
||||
/// Checking was successful but there were errors.
|
||||
Failure = 1,
|
||||
|
||||
/// Checking failed due to an invocation error (e.g. the current directory no longer exists, incorrect CLI arguments, ...)
|
||||
/// Checking failed.
|
||||
Error = 2,
|
||||
|
||||
/// Internal Red Knot error (panic, or any other error that isn't due to the user using the
|
||||
/// program incorrectly or transient environment errors).
|
||||
InternalError = 101,
|
||||
}
|
||||
|
||||
impl Termination for ExitStatus {
|
||||
@@ -250,16 +246,11 @@ impl MainLoop {
|
||||
// Spawn a new task that checks the project. This needs to be done in a separate thread
|
||||
// to prevent blocking the main loop here.
|
||||
rayon::spawn(move || {
|
||||
match db.check() {
|
||||
Ok(result) => {
|
||||
// Send the result back to the main loop for printing.
|
||||
sender
|
||||
.send(MainLoopMessage::CheckCompleted { result, revision })
|
||||
.unwrap();
|
||||
}
|
||||
Err(cancelled) => {
|
||||
tracing::debug!("Check has been cancelled: {cancelled:?}");
|
||||
}
|
||||
if let Ok(result) = db.check() {
|
||||
// Send the result back to the main loop for printing.
|
||||
sender
|
||||
.send(MainLoopMessage::CheckCompleted { result, revision })
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -273,6 +264,12 @@ impl MainLoop {
|
||||
.format(terminal_settings.output_format)
|
||||
.color(colored::control::SHOULD_COLORIZE.should_colorize());
|
||||
|
||||
let min_error_severity = if terminal_settings.error_on_warning {
|
||||
Severity::Warning
|
||||
} else {
|
||||
Severity::Error
|
||||
};
|
||||
|
||||
if check_revision == revision {
|
||||
if db.project().files(db).is_empty() {
|
||||
tracing::warn!("No python files found under the given path(s)");
|
||||
@@ -287,13 +284,13 @@ impl MainLoop {
|
||||
return Ok(ExitStatus::Success);
|
||||
}
|
||||
} else {
|
||||
let mut max_severity = Severity::Info;
|
||||
let mut failed = false;
|
||||
let diagnostics_count = result.len();
|
||||
|
||||
for diagnostic in result {
|
||||
write!(stdout, "{}", diagnostic.display(db, &display_config))?;
|
||||
|
||||
max_severity = max_severity.max(diagnostic.severity());
|
||||
failed |= diagnostic.severity() >= min_error_severity;
|
||||
}
|
||||
|
||||
writeln!(
|
||||
@@ -304,17 +301,10 @@ impl MainLoop {
|
||||
)?;
|
||||
|
||||
if self.watcher.is_none() {
|
||||
return Ok(match max_severity {
|
||||
Severity::Info => ExitStatus::Success,
|
||||
Severity::Warning => {
|
||||
if terminal_settings.error_on_warning {
|
||||
ExitStatus::Failure
|
||||
} else {
|
||||
ExitStatus::Success
|
||||
}
|
||||
}
|
||||
Severity::Error => ExitStatus::Failure,
|
||||
Severity::Fatal => ExitStatus::InternalError,
|
||||
return Ok(if failed {
|
||||
ExitStatus::Failure
|
||||
} else {
|
||||
ExitStatus::Success
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,94 +5,6 @@ use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn test_include_hidden_files_by_default() -> anyhow::Result<()> {
|
||||
let case = TestCase::with_files([(".test.py", "~")])?;
|
||||
assert_cmd_snapshot!(case.command(), @r"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
error: invalid-syntax
|
||||
--> <temp_dir>/.test.py:1:2
|
||||
|
|
||||
1 | ~
|
||||
| ^ Expected an expression
|
||||
|
|
||||
|
||||
Found 1 diagnostic
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
Ok(())
|
||||
}
|
||||
#[test]
|
||||
fn test_respect_ignore_files() -> anyhow::Result<()> {
|
||||
// First test that the default option works correctly (the file is skipped)
|
||||
let case = TestCase::with_files([(".ignore", "test.py"), ("test.py", "~")])?;
|
||||
assert_cmd_snapshot!(case.command(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
All checks passed!
|
||||
|
||||
----- stderr -----
|
||||
WARN No python files found under the given path(s)
|
||||
");
|
||||
|
||||
// Test that we can set to false via CLI
|
||||
assert_cmd_snapshot!(case.command().arg("--no-respect-ignore-files"), @r"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
error: invalid-syntax
|
||||
--> <temp_dir>/test.py:1:2
|
||||
|
|
||||
1 | ~
|
||||
| ^ Expected an expression
|
||||
|
|
||||
|
||||
Found 1 diagnostic
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Test that we can set to false via config file
|
||||
case.write_file("knot.toml", "respect-ignore-files = false")?;
|
||||
assert_cmd_snapshot!(case.command(), @r"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
error: invalid-syntax
|
||||
--> <temp_dir>/test.py:1:2
|
||||
|
|
||||
1 | ~
|
||||
| ^ Expected an expression
|
||||
|
|
||||
|
||||
Found 1 diagnostic
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Ensure CLI takes precedence
|
||||
case.write_file("knot.toml", "respect-ignore-files = true")?;
|
||||
assert_cmd_snapshot!(case.command().arg("--no-respect-ignore-files"), @r"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
error: invalid-syntax
|
||||
--> <temp_dir>/test.py:1:2
|
||||
|
|
||||
1 | ~
|
||||
| ^ Expected an expression
|
||||
|
|
||||
|
||||
Found 1 diagnostic
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
Ok(())
|
||||
}
|
||||
/// Specifying an option on the CLI should take precedence over the same setting in the
|
||||
/// project's configuration. Here, this is tested for the Python version.
|
||||
#[test]
|
||||
@@ -1023,6 +935,13 @@ fn check_specific_paths() -> anyhow::Result<()> {
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
|
||||
--> <temp_dir>/project/tests/test_main.py:2:8
|
||||
|
|
||||
2 | import does_not_exist # error: unresolved-import
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
|
||||
--> <temp_dir>/project/main.py:2:5
|
||||
|
|
||||
@@ -1039,13 +958,6 @@ fn check_specific_paths() -> anyhow::Result<()> {
|
||||
4 | print(z)
|
||||
|
|
||||
|
||||
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
|
||||
--> <temp_dir>/project/tests/test_main.py:2:8
|
||||
|
|
||||
2 | import does_not_exist # error: unresolved-import
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
Found 3 diagnostics
|
||||
|
||||
----- stderr -----
|
||||
@@ -1060,6 +972,13 @@ fn check_specific_paths() -> anyhow::Result<()> {
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
|
||||
--> <temp_dir>/project/tests/test_main.py:2:8
|
||||
|
|
||||
2 | import does_not_exist # error: unresolved-import
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: lint:unresolved-import: Cannot resolve import `main2`
|
||||
--> <temp_dir>/project/other.py:2:6
|
||||
|
|
||||
@@ -1069,13 +988,6 @@ fn check_specific_paths() -> anyhow::Result<()> {
|
||||
4 | print(z)
|
||||
|
|
||||
|
||||
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
|
||||
--> <temp_dir>/project/tests/test_main.py:2:8
|
||||
|
|
||||
2 | import does_not_exist # error: unresolved-import
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
Found 2 diagnostics
|
||||
|
||||
----- stderr -----
|
||||
|
||||
@@ -11,7 +11,7 @@ use red_knot_python_semantic::register_lints;
|
||||
use red_knot_python_semantic::types::check_types;
|
||||
use ruff_db::diagnostic::{
|
||||
create_parse_diagnostic, create_unsupported_syntax_diagnostic, Annotation, Diagnostic,
|
||||
DiagnosticId, Severity, Span, SubDiagnostic,
|
||||
DiagnosticId, Severity, Span,
|
||||
};
|
||||
use ruff_db::files::File;
|
||||
use ruff_db::parsed::parsed_module;
|
||||
@@ -20,10 +20,8 @@ use ruff_db::system::{SystemPath, SystemPathBuf};
|
||||
use rustc_hash::FxHashSet;
|
||||
use salsa::Durability;
|
||||
use salsa::Setter;
|
||||
use std::panic::{catch_unwind, AssertUnwindSafe, UnwindSafe};
|
||||
use std::sync::Arc;
|
||||
use thiserror::Error;
|
||||
use tracing::error;
|
||||
|
||||
pub mod combine;
|
||||
|
||||
@@ -189,66 +187,30 @@ impl Project {
|
||||
.map(IOErrorDiagnostic::to_diagnostic),
|
||||
);
|
||||
|
||||
let file_diagnostics = Arc::new(std::sync::Mutex::new(vec![]));
|
||||
let result = Arc::new(std::sync::Mutex::new(diagnostics));
|
||||
let inner_result = Arc::clone(&result);
|
||||
|
||||
{
|
||||
let file_diagnostics = Arc::clone(&file_diagnostics);
|
||||
let db = db.clone();
|
||||
let project_span = project_span.clone();
|
||||
let db = db.clone();
|
||||
let project_span = project_span.clone();
|
||||
|
||||
rayon::scope(move |scope| {
|
||||
for file in &files {
|
||||
let result = Arc::clone(&file_diagnostics);
|
||||
let db = db.clone();
|
||||
let project_span = project_span.clone();
|
||||
rayon::scope(move |scope| {
|
||||
for file in &files {
|
||||
let result = inner_result.clone();
|
||||
let db = db.clone();
|
||||
let project_span = project_span.clone();
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let check_file_span =
|
||||
tracing::debug_span!(parent: &project_span, "check_file", ?file);
|
||||
let _entered = check_file_span.entered();
|
||||
scope.spawn(move |_| {
|
||||
let check_file_span =
|
||||
tracing::debug_span!(parent: &project_span, "check_file", ?file);
|
||||
let _entered = check_file_span.entered();
|
||||
|
||||
let file_diagnostics = check_file_impl(&db, file);
|
||||
result.lock().unwrap().extend(file_diagnostics);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut file_diagnostics = Arc::into_inner(file_diagnostics)
|
||||
.unwrap()
|
||||
.into_inner()
|
||||
.unwrap();
|
||||
// We sort diagnostics in a way that keeps them in source order
|
||||
// and grouped by file. After that, we fall back to severity
|
||||
// (with fatal messages sorting before info messages) and then
|
||||
// finally the diagnostic ID.
|
||||
file_diagnostics.sort_by(|d1, d2| {
|
||||
if let (Some(span1), Some(span2)) = (d1.primary_span(), d2.primary_span()) {
|
||||
let order = span1
|
||||
.file()
|
||||
.path(db)
|
||||
.as_str()
|
||||
.cmp(span2.file().path(db).as_str());
|
||||
if order.is_ne() {
|
||||
return order;
|
||||
}
|
||||
|
||||
if let (Some(range1), Some(range2)) = (span1.range(), span2.range()) {
|
||||
let order = range1.start().cmp(&range2.start());
|
||||
if order.is_ne() {
|
||||
return order;
|
||||
}
|
||||
}
|
||||
let file_diagnostics = check_file_impl(&db, file);
|
||||
result.lock().unwrap().extend(file_diagnostics);
|
||||
});
|
||||
}
|
||||
// Reverse so that, e.g., Fatal sorts before Info.
|
||||
let order = d1.severity().cmp(&d2.severity()).reverse();
|
||||
if order.is_ne() {
|
||||
return order;
|
||||
}
|
||||
d1.id().cmp(&d2.id())
|
||||
});
|
||||
diagnostics.extend(file_diagnostics);
|
||||
diagnostics
|
||||
|
||||
Arc::into_inner(result).unwrap().into_inner().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn check_file(self, db: &dyn Db, file: File) -> Vec<Diagnostic> {
|
||||
@@ -473,16 +435,7 @@ fn check_file_impl(db: &dyn Db, file: File) -> Vec<Diagnostic> {
|
||||
.map(|error| create_unsupported_syntax_diagnostic(file, error)),
|
||||
);
|
||||
|
||||
{
|
||||
let db = AssertUnwindSafe(db);
|
||||
match catch(&**db, file, || check_types(db.upcast(), file)) {
|
||||
Ok(Some(type_check_diagnostics)) => {
|
||||
diagnostics.extend(type_check_diagnostics.into_iter().cloned());
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(diagnostic) => diagnostics.push(diagnostic),
|
||||
}
|
||||
}
|
||||
diagnostics.extend(check_types(db.upcast(), file).into_iter().cloned());
|
||||
|
||||
diagnostics.sort_unstable_by_key(|diagnostic| {
|
||||
diagnostic
|
||||
@@ -573,45 +526,6 @@ enum IOErrorKind {
|
||||
SourceText(#[from] SourceTextError),
|
||||
}
|
||||
|
||||
fn catch<F, R>(db: &dyn Db, file: File, f: F) -> Result<Option<R>, Diagnostic>
|
||||
where
|
||||
F: FnOnce() -> R + UnwindSafe,
|
||||
{
|
||||
match catch_unwind(|| {
|
||||
// Ignore salsa errors
|
||||
salsa::Cancelled::catch(f).ok()
|
||||
}) {
|
||||
Ok(result) => Ok(result),
|
||||
Err(error) => {
|
||||
let payload = if let Some(s) = error.downcast_ref::<&str>() {
|
||||
Some((*s).to_string())
|
||||
} else {
|
||||
error.downcast_ref::<String>().cloned()
|
||||
};
|
||||
|
||||
let message = if let Some(payload) = payload {
|
||||
format!(
|
||||
"Panicked while checking `{file}`: `{payload}`",
|
||||
file = file.path(db)
|
||||
)
|
||||
} else {
|
||||
format!("Panicked while checking `{file}`", file = { file.path(db) })
|
||||
};
|
||||
|
||||
let mut diagnostic = Diagnostic::new(DiagnosticId::Panic, Severity::Fatal, message);
|
||||
diagnostic.sub(SubDiagnostic::new(
|
||||
Severity::Info,
|
||||
"This indicates a bug in Red Knot.",
|
||||
));
|
||||
|
||||
let report_message = "If you could open an issue at https://github.com/astral-sh/ruff/issues/new?title=%5Bred-knot%5D:%20panic we'd be very appreciative!";
|
||||
diagnostic.sub(SubDiagnostic::new(Severity::Info, report_message));
|
||||
|
||||
Err(diagnostic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::db::tests::TestDb;
|
||||
|
||||
@@ -32,9 +32,6 @@ pub struct Options {
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub terminal: Option<TerminalOptions>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub respect_ignore_files: Option<bool>,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
@@ -136,7 +133,7 @@ impl Options {
|
||||
pub(crate) fn to_settings(&self, db: &dyn Db) -> (Settings, Vec<OptionDiagnostic>) {
|
||||
let (rules, diagnostics) = self.to_rule_selection(db);
|
||||
|
||||
let mut settings = Settings::new(rules, self.respect_ignore_files);
|
||||
let mut settings = Settings::new(rules);
|
||||
|
||||
if let Some(terminal) = self.terminal.as_ref() {
|
||||
settings.set_terminal(TerminalSettings {
|
||||
|
||||
@@ -21,16 +21,13 @@ pub struct Settings {
|
||||
rules: Arc<RuleSelection>,
|
||||
|
||||
terminal: TerminalSettings,
|
||||
|
||||
respect_ignore_files: bool,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn new(rules: RuleSelection, respect_ignore_files: Option<bool>) -> Self {
|
||||
pub fn new(rules: RuleSelection) -> Self {
|
||||
Self {
|
||||
rules: Arc::new(rules),
|
||||
terminal: TerminalSettings::default(),
|
||||
respect_ignore_files: respect_ignore_files.unwrap_or(true),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +35,6 @@ impl Settings {
|
||||
&self.rules
|
||||
}
|
||||
|
||||
pub fn respect_ignore_files(&self) -> bool {
|
||||
self.respect_ignore_files
|
||||
}
|
||||
|
||||
pub fn to_rules(&self) -> Arc<RuleSelection> {
|
||||
self.rules.clone()
|
||||
}
|
||||
|
||||
@@ -129,11 +129,7 @@ impl<'a> ProjectFilesWalker<'a> {
|
||||
{
|
||||
let mut paths = paths.into_iter();
|
||||
|
||||
let mut walker = db
|
||||
.system()
|
||||
.walk_directory(paths.next()?.as_ref())
|
||||
.standard_filters(db.project().settings(db).respect_ignore_files())
|
||||
.ignore_hidden(false);
|
||||
let mut walker = db.system().walk_directory(paths.next()?.as_ref());
|
||||
|
||||
for path in paths {
|
||||
walker = walker.add(path);
|
||||
|
||||
@@ -38,12 +38,8 @@ bad_nesting: Literal[LiteralString] # error: [invalid-type-form]
|
||||
```py
|
||||
from typing_extensions import LiteralString
|
||||
|
||||
# error: [invalid-type-form]
|
||||
a: LiteralString[str]
|
||||
|
||||
# error: [invalid-type-form]
|
||||
# error: [unresolved-reference] "Name `foo` used when not defined"
|
||||
b: LiteralString["foo"]
|
||||
a: LiteralString[str] # error: [invalid-type-form]
|
||||
b: LiteralString["foo"] # error: [invalid-type-form]
|
||||
```
|
||||
|
||||
### As a base class
|
||||
|
||||
@@ -89,12 +89,9 @@ python-version = "3.12"
|
||||
Some of these are not subscriptable:
|
||||
|
||||
```py
|
||||
from typing_extensions import Self, TypeAlias, TypeVar
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
# error: [invalid-type-form] "Special form `typing.TypeAlias` expected no type parameter"
|
||||
X: TypeAlias[T] = int
|
||||
X: TypeAlias[T] = int # error: [invalid-type-form]
|
||||
|
||||
class Foo[T]:
|
||||
# error: [invalid-type-form] "Special form `typing.Self` expected no type parameter"
|
||||
|
||||
@@ -11,6 +11,8 @@ from typing_extensions import Final, Required, NotRequired, ReadOnly, TypedDict
|
||||
X: Final = 42
|
||||
Y: Final[int] = 42
|
||||
|
||||
# TODO: `TypedDict` is actually valid as a base
|
||||
# error: [invalid-base]
|
||||
class Bar(TypedDict):
|
||||
x: Required[int]
|
||||
y: NotRequired[str]
|
||||
|
||||
@@ -7,7 +7,7 @@ Builtin symbols can be explicitly imported:
|
||||
```py
|
||||
import builtins
|
||||
|
||||
reveal_type(builtins.chr) # revealed: def chr(i: SupportsIndex, /) -> str
|
||||
reveal_type(builtins.chr) # revealed: def chr(i: int | SupportsIndex, /) -> str
|
||||
```
|
||||
|
||||
## Implicit use of builtin
|
||||
@@ -15,7 +15,7 @@ reveal_type(builtins.chr) # revealed: def chr(i: SupportsIndex, /) -> str
|
||||
Or used implicitly:
|
||||
|
||||
```py
|
||||
reveal_type(chr) # revealed: def chr(i: SupportsIndex, /) -> str
|
||||
reveal_type(chr) # revealed: def chr(i: int | SupportsIndex, /) -> str
|
||||
reveal_type(str) # revealed: Literal[str]
|
||||
```
|
||||
|
||||
|
||||
@@ -191,8 +191,8 @@ reveal_type(AA.__mro__) # revealed: tuple[Literal[AA], Literal[Z], Unknown, Lit
|
||||
|
||||
## `__bases__` includes a `Union`
|
||||
|
||||
We don't support union types in a class's bases; a base must resolve to a single `ClassType`. If we
|
||||
find a union type in a class's bases, we infer the class's `__mro__` as being
|
||||
We don't support union types in a class's bases; a base must resolve to a single `ClassLiteralType`.
|
||||
If we find a union type in a class's bases, we infer the class's `__mro__` as being
|
||||
`[<class>, Unknown, object]`, the same as for MROs that cause errors at runtime.
|
||||
|
||||
```py
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# repro interned panic
|
||||
|
||||
## before
|
||||
|
||||
```toml
|
||||
log = "salsa=trace,red_knot_test,ruff_db=trace,red_knot_ide=trace,red_knot_project=trace"
|
||||
[environment]
|
||||
python-version = "3.9"
|
||||
```
|
||||
|
||||
```py
|
||||
None
|
||||
```
|
||||
|
||||
## after
|
||||
|
||||
```toml
|
||||
log = "salsa=trace,red_knot_test,ruff_db=trace,red_knot_ide=trace,red_knot_project=trace"
|
||||
[environment]
|
||||
python-version = "3.10"
|
||||
```
|
||||
|
||||
```py
|
||||
None
|
||||
```
|
||||
@@ -230,7 +230,7 @@ And it is also an error to use `Protocol` in type expressions:
|
||||
def f(
|
||||
x: Protocol, # error: [invalid-type-form] "`typing.Protocol` is not allowed in type expressions"
|
||||
y: type[Protocol], # TODO: should emit `[invalid-type-form]` here too
|
||||
):
|
||||
) -> None:
|
||||
reveal_type(x) # revealed: Unknown
|
||||
|
||||
# TODO: should be `type[Unknown]`
|
||||
@@ -266,7 +266,9 @@ class Bar(typing_extensions.Protocol):
|
||||
|
||||
static_assert(typing_extensions.is_protocol(Foo))
|
||||
static_assert(typing_extensions.is_protocol(Bar))
|
||||
static_assert(is_equivalent_to(Foo, Bar))
|
||||
|
||||
# TODO: should pass
|
||||
static_assert(is_equivalent_to(Foo, Bar)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
The same goes for `typing.runtime_checkable` and `typing_extensions.runtime_checkable`:
|
||||
@@ -282,7 +284,9 @@ class RuntimeCheckableBar(typing_extensions.Protocol):
|
||||
|
||||
static_assert(typing_extensions.is_protocol(RuntimeCheckableFoo))
|
||||
static_assert(typing_extensions.is_protocol(RuntimeCheckableBar))
|
||||
static_assert(is_equivalent_to(RuntimeCheckableFoo, RuntimeCheckableBar))
|
||||
|
||||
# TODO: should pass
|
||||
static_assert(is_equivalent_to(RuntimeCheckableFoo, RuntimeCheckableBar)) # error: [static-assert-error]
|
||||
|
||||
# These should not error because the protocols are decorated with `@runtime_checkable`
|
||||
isinstance(object(), RuntimeCheckableFoo)
|
||||
@@ -484,20 +488,21 @@ class HasX(Protocol):
|
||||
class Foo:
|
||||
x: int
|
||||
|
||||
static_assert(is_subtype_of(Foo, HasX))
|
||||
static_assert(is_assignable_to(Foo, HasX))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(Foo, HasX)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(Foo, HasX)) # error: [static-assert-error]
|
||||
|
||||
class FooSub(Foo): ...
|
||||
|
||||
static_assert(is_subtype_of(FooSub, HasX))
|
||||
static_assert(is_assignable_to(FooSub, HasX))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(FooSub, HasX)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(FooSub, HasX)) # error: [static-assert-error]
|
||||
|
||||
class Bar:
|
||||
x: str
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(Bar, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(Bar, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(Bar, HasX))
|
||||
static_assert(not is_assignable_to(Bar, HasX))
|
||||
|
||||
class Baz:
|
||||
y: int
|
||||
@@ -519,16 +524,14 @@ class A:
|
||||
def x(self) -> int:
|
||||
return 42
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(A, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(A, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(A, HasX))
|
||||
static_assert(not is_assignable_to(A, HasX))
|
||||
|
||||
class B:
|
||||
x: Final = 42
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(A, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(A, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(A, HasX))
|
||||
static_assert(not is_assignable_to(A, HasX))
|
||||
|
||||
class IntSub(int): ...
|
||||
|
||||
@@ -538,10 +541,8 @@ class C:
|
||||
# due to invariance, a type is only a subtype of `HasX`
|
||||
# if its `x` attribute is of type *exactly* `int`:
|
||||
# a subclass of `int` does not satisfy the interface
|
||||
#
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(C, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(C, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(C, HasX))
|
||||
static_assert(not is_assignable_to(C, HasX))
|
||||
```
|
||||
|
||||
All attributes on frozen dataclasses and namedtuples are immutable, so instances of these classes
|
||||
@@ -555,23 +556,22 @@ from typing import NamedTuple
|
||||
class MutableDataclass:
|
||||
x: int
|
||||
|
||||
static_assert(is_subtype_of(MutableDataclass, HasX))
|
||||
static_assert(is_assignable_to(MutableDataclass, HasX))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(MutableDataclass, HasX)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(MutableDataclass, HasX)) # error: [static-assert-error]
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ImmutableDataclass:
|
||||
x: int
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(ImmutableDataclass, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(ImmutableDataclass, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(ImmutableDataclass, HasX))
|
||||
static_assert(not is_assignable_to(ImmutableDataclass, HasX))
|
||||
|
||||
class NamedTupleWithX(NamedTuple):
|
||||
x: int
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(NamedTupleWithX, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(NamedTupleWithX, HasX)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(NamedTupleWithX, HasX))
|
||||
static_assert(not is_assignable_to(NamedTupleWithX, HasX))
|
||||
```
|
||||
|
||||
However, a type with a read-write property `x` *does* satisfy the `HasX` protocol. The `HasX`
|
||||
@@ -590,8 +590,9 @@ class XProperty:
|
||||
def x(self, x: int) -> None:
|
||||
self._x = x**2
|
||||
|
||||
static_assert(is_subtype_of(XProperty, HasX))
|
||||
static_assert(is_assignable_to(XProperty, HasX))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XProperty, HasX)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XProperty, HasX)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
Attribute members on protocol classes are allowed to have default values, just like instance
|
||||
@@ -716,8 +717,9 @@ from typing import Protocol
|
||||
|
||||
class UniversalSet(Protocol): ...
|
||||
|
||||
static_assert(is_assignable_to(object, UniversalSet))
|
||||
static_assert(is_subtype_of(object, UniversalSet))
|
||||
# TODO: these should pass
|
||||
static_assert(is_assignable_to(object, UniversalSet)) # error: [static-assert-error]
|
||||
static_assert(is_subtype_of(object, UniversalSet)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
Which means that `UniversalSet` here is in fact an equivalent type to `object`:
|
||||
@@ -725,7 +727,8 @@ Which means that `UniversalSet` here is in fact an equivalent type to `object`:
|
||||
```py
|
||||
from knot_extensions import is_equivalent_to
|
||||
|
||||
static_assert(is_equivalent_to(UniversalSet, object))
|
||||
# TODO: this should pass
|
||||
static_assert(is_equivalent_to(UniversalSet, object)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
`object` is a subtype of certain other protocols too. Since all fully static types (whether nominal
|
||||
@@ -736,16 +739,17 @@ means that these protocols are also equivalent to `UniversalSet` and `object`:
|
||||
class SupportsStr(Protocol):
|
||||
def __str__(self) -> str: ...
|
||||
|
||||
static_assert(is_equivalent_to(SupportsStr, UniversalSet))
|
||||
static_assert(is_equivalent_to(SupportsStr, object))
|
||||
# TODO: these should pass
|
||||
static_assert(is_equivalent_to(SupportsStr, UniversalSet)) # error: [static-assert-error]
|
||||
static_assert(is_equivalent_to(SupportsStr, object)) # error: [static-assert-error]
|
||||
|
||||
class SupportsClass(Protocol):
|
||||
@property
|
||||
def __class__(self) -> type: ...
|
||||
__class__: type
|
||||
|
||||
static_assert(is_equivalent_to(SupportsClass, UniversalSet))
|
||||
static_assert(is_equivalent_to(SupportsClass, SupportsStr))
|
||||
static_assert(is_equivalent_to(SupportsClass, object))
|
||||
# TODO: these should pass
|
||||
static_assert(is_equivalent_to(SupportsClass, UniversalSet)) # error: [static-assert-error]
|
||||
static_assert(is_equivalent_to(SupportsClass, SupportsStr)) # error: [static-assert-error]
|
||||
static_assert(is_equivalent_to(SupportsClass, object)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
If a protocol contains members that are not defined on `object`, then that protocol will (like all
|
||||
@@ -782,7 +786,8 @@ class HasX(Protocol):
|
||||
class AlsoHasX(Protocol):
|
||||
x: int
|
||||
|
||||
static_assert(is_equivalent_to(HasX, AlsoHasX))
|
||||
# TODO: this should pass
|
||||
static_assert(is_equivalent_to(HasX, AlsoHasX)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
And unions containing equivalent protocols are recognised as equivalent, even when the order is not
|
||||
@@ -798,7 +803,8 @@ class AlsoHasY(Protocol):
|
||||
class A: ...
|
||||
class B: ...
|
||||
|
||||
static_assert(is_equivalent_to(A | HasX | B | HasY, B | AlsoHasY | AlsoHasX | A))
|
||||
# TODO: this should pass
|
||||
static_assert(is_equivalent_to(A | HasX | B | HasY, B | AlsoHasY | AlsoHasX | A)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
## Intersections of protocols
|
||||
@@ -876,9 +882,9 @@ from knot_extensions import is_subtype_of, is_assignable_to, static_assert, Type
|
||||
class HasX(Protocol):
|
||||
x: int
|
||||
|
||||
# TODO: this should pass
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(TypeOf[module], HasX)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(TypeOf[module], HasX))
|
||||
static_assert(is_assignable_to(TypeOf[module], HasX)) # error: [static-assert-error]
|
||||
|
||||
class ExplicitProtocolSubtype(HasX, Protocol):
|
||||
y: int
|
||||
@@ -890,8 +896,9 @@ class ImplicitProtocolSubtype(Protocol):
|
||||
x: int
|
||||
y: str
|
||||
|
||||
static_assert(is_subtype_of(ImplicitProtocolSubtype, HasX))
|
||||
static_assert(is_assignable_to(ImplicitProtocolSubtype, HasX))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(ImplicitProtocolSubtype, HasX)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(ImplicitProtocolSubtype, HasX)) # error: [static-assert-error]
|
||||
|
||||
class Meta(type):
|
||||
x: int
|
||||
@@ -926,24 +933,23 @@ def f(obj: ClassVarXProto):
|
||||
class InstanceAttrX:
|
||||
x: int
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_assignable_to(InstanceAttrX, ClassVarXProto)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(InstanceAttrX, ClassVarXProto)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(InstanceAttrX, ClassVarXProto))
|
||||
static_assert(not is_subtype_of(InstanceAttrX, ClassVarXProto))
|
||||
|
||||
class PropertyX:
|
||||
@property
|
||||
def x(self) -> int:
|
||||
return 42
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_assignable_to(PropertyX, ClassVarXProto)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(PropertyX, ClassVarXProto)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(PropertyX, ClassVarXProto))
|
||||
static_assert(not is_subtype_of(PropertyX, ClassVarXProto))
|
||||
|
||||
class ClassVarX:
|
||||
x: ClassVar[int] = 42
|
||||
|
||||
static_assert(is_assignable_to(ClassVarX, ClassVarXProto))
|
||||
static_assert(is_subtype_of(ClassVarX, ClassVarXProto))
|
||||
# TODO: these should pass
|
||||
static_assert(is_assignable_to(ClassVarX, ClassVarXProto)) # error: [static-assert-error]
|
||||
static_assert(is_subtype_of(ClassVarX, ClassVarXProto)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
This is mentioned by the
|
||||
@@ -970,16 +976,18 @@ class HasXProperty(Protocol):
|
||||
class XAttr:
|
||||
x: int
|
||||
|
||||
static_assert(is_subtype_of(XAttr, HasXProperty))
|
||||
static_assert(is_assignable_to(XAttr, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XAttr, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XAttr, HasXProperty)) # error: [static-assert-error]
|
||||
|
||||
class XReadProperty:
|
||||
@property
|
||||
def x(self) -> int:
|
||||
return 42
|
||||
|
||||
static_assert(is_subtype_of(XReadProperty, HasXProperty))
|
||||
static_assert(is_assignable_to(XReadProperty, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XReadProperty, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XReadProperty, HasXProperty)) # error: [static-assert-error]
|
||||
|
||||
class XReadWriteProperty:
|
||||
@property
|
||||
@@ -989,20 +997,22 @@ class XReadWriteProperty:
|
||||
@x.setter
|
||||
def x(self, val: int) -> None: ...
|
||||
|
||||
static_assert(is_subtype_of(XReadWriteProperty, HasXProperty))
|
||||
static_assert(is_assignable_to(XReadWriteProperty, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XReadWriteProperty, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XReadWriteProperty, HasXProperty)) # error: [static-assert-error]
|
||||
|
||||
class XClassVar:
|
||||
x: ClassVar[int] = 42
|
||||
|
||||
static_assert(is_subtype_of(XClassVar, HasXProperty))
|
||||
static_assert(is_assignable_to(XClassVar, HasXProperty))
|
||||
static_assert(is_subtype_of(XClassVar, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XClassVar, HasXProperty)) # error: [static-assert-error]
|
||||
|
||||
class XFinal:
|
||||
x: Final = 42
|
||||
|
||||
static_assert(is_subtype_of(XFinal, HasXProperty))
|
||||
static_assert(is_assignable_to(XFinal, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XFinal, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XFinal, HasXProperty)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
A read-only property on a protocol, unlike a mutable attribute, is covariant: `XSub` in the below
|
||||
@@ -1015,8 +1025,9 @@ class MyInt(int): ...
|
||||
class XSub:
|
||||
x: MyInt
|
||||
|
||||
static_assert(is_subtype_of(XSub, HasXProperty))
|
||||
static_assert(is_assignable_to(XSub, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XSub, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XSub, HasXProperty)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
A read/write property on a protocol, where the getter returns the same type that the setter takes,
|
||||
@@ -1032,17 +1043,17 @@ class HasMutableXProperty(Protocol):
|
||||
class XAttr:
|
||||
x: int
|
||||
|
||||
static_assert(is_subtype_of(XAttr, HasXProperty))
|
||||
static_assert(is_assignable_to(XAttr, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XAttr, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XAttr, HasXProperty)) # error: [static-assert-error]
|
||||
|
||||
class XReadProperty:
|
||||
@property
|
||||
def x(self) -> int:
|
||||
return 42
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(XReadProperty, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(XReadProperty, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(XReadProperty, HasXProperty))
|
||||
static_assert(not is_assignable_to(XReadProperty, HasXProperty))
|
||||
|
||||
class XReadWriteProperty:
|
||||
@property
|
||||
@@ -1052,15 +1063,15 @@ class XReadWriteProperty:
|
||||
@x.setter
|
||||
def x(self, val: int) -> None: ...
|
||||
|
||||
static_assert(is_subtype_of(XReadWriteProperty, HasXProperty))
|
||||
static_assert(is_assignable_to(XReadWriteProperty, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XReadWriteProperty, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XReadWriteProperty, HasXProperty)) # error: [static-assert-error]
|
||||
|
||||
class XSub:
|
||||
x: MyInt
|
||||
|
||||
# TODO: should pass
|
||||
static_assert(not is_subtype_of(XSub, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(XSub, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(XSub, HasXProperty))
|
||||
static_assert(not is_assignable_to(XSub, HasXProperty))
|
||||
```
|
||||
|
||||
A protocol with a read/write property `x` is exactly equivalent to a protocol with a mutable
|
||||
@@ -1072,13 +1083,16 @@ from knot_extensions import is_equivalent_to
|
||||
class HasMutableXAttr(Protocol):
|
||||
x: int
|
||||
|
||||
static_assert(is_equivalent_to(HasMutableXAttr, HasMutableXProperty))
|
||||
# TODO: this should pass
|
||||
static_assert(is_equivalent_to(HasMutableXAttr, HasMutableXProperty)) # error: [static-assert-error]
|
||||
|
||||
static_assert(is_subtype_of(HasMutableXAttr, HasXProperty))
|
||||
static_assert(is_assignable_to(HasMutableXAttr, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(HasMutableXAttr, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(HasMutableXAttr, HasXProperty)) # error: [static-assert-error]
|
||||
|
||||
static_assert(is_subtype_of(HasMutableXProperty, HasXProperty))
|
||||
static_assert(is_assignable_to(HasMutableXProperty, HasXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(HasMutableXProperty, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(HasMutableXProperty, HasXProperty)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
A read/write property on a protocol, where the setter accepts a subtype of the type returned by the
|
||||
@@ -1105,8 +1119,9 @@ class HasAsymmetricXProperty(Protocol):
|
||||
class XAttr:
|
||||
x: int
|
||||
|
||||
static_assert(is_subtype_of(XAttr, HasAsymmetricXProperty))
|
||||
static_assert(is_assignable_to(XAttr, HasAsymmetricXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XAttr, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XAttr, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
The end conclusion of this is that the getter-returned type of a property is always covariant and
|
||||
@@ -1117,8 +1132,9 @@ regular mutable attribute, where the implied getter-returned and setter-accepted
|
||||
class XAttrSub:
|
||||
x: MyInt
|
||||
|
||||
static_assert(is_subtype_of(XAttrSub, HasAsymmetricXProperty))
|
||||
static_assert(is_assignable_to(XAttrSub, HasAsymmetricXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XAttrSub, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XAttrSub, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
|
||||
class MyIntSub(MyInt):
|
||||
pass
|
||||
@@ -1126,9 +1142,8 @@ class MyIntSub(MyInt):
|
||||
class XAttrSubSub:
|
||||
x: MyIntSub
|
||||
|
||||
# TODO: should pass
|
||||
static_assert(not is_subtype_of(XAttrSubSub, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(XAttrSubSub, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(XAttrSubSub, HasAsymmetricXProperty))
|
||||
static_assert(not is_assignable_to(XAttrSubSub, HasAsymmetricXProperty))
|
||||
```
|
||||
|
||||
An asymmetric property on a protocol can also be satisfied by an asymmetric property on a nominal
|
||||
@@ -1144,8 +1159,9 @@ class XAsymmetricProperty:
|
||||
@x.setter
|
||||
def x(self, x: int) -> None: ...
|
||||
|
||||
static_assert(is_subtype_of(XAsymmetricProperty, HasAsymmetricXProperty))
|
||||
static_assert(is_assignable_to(XAsymmetricProperty, HasAsymmetricXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XAsymmetricProperty, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XAsymmetricProperty, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
A custom descriptor attribute on the nominal class will also suffice:
|
||||
@@ -1160,8 +1176,9 @@ class Descriptor:
|
||||
class XCustomDescriptor:
|
||||
x: Descriptor = Descriptor()
|
||||
|
||||
static_assert(is_subtype_of(XCustomDescriptor, HasAsymmetricXProperty))
|
||||
static_assert(is_assignable_to(XCustomDescriptor, HasAsymmetricXProperty))
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(XCustomDescriptor, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(XCustomDescriptor, HasAsymmetricXProperty)) # error: [static-assert-error]
|
||||
```
|
||||
|
||||
Moreover, a read-only property on a protocol can be satisfied by a nominal class that defines a
|
||||
@@ -1174,20 +1191,19 @@ class HasGetAttr:
|
||||
def __getattr__(self, attr: str) -> int:
|
||||
return 42
|
||||
|
||||
static_assert(is_subtype_of(HasGetAttr, HasXProperty))
|
||||
static_assert(is_assignable_to(HasGetAttr, HasXProperty))
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(HasGetAttr, HasMutableXAttr)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(HasGetAttr, HasMutableXAttr)) # error: [static-assert-error]
|
||||
static_assert(is_subtype_of(HasGetAttr, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(HasGetAttr, HasXProperty)) # error: [static-assert-error]
|
||||
|
||||
static_assert(not is_subtype_of(HasGetAttr, HasMutableXAttr))
|
||||
static_assert(not is_subtype_of(HasGetAttr, HasMutableXAttr))
|
||||
|
||||
class HasGetAttrWithUnsuitableReturn:
|
||||
def __getattr__(self, attr: str) -> tuple[int, int]:
|
||||
return (1, 2)
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(not is_subtype_of(HasGetAttrWithUnsuitableReturn, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(not is_assignable_to(HasGetAttrWithUnsuitableReturn, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(HasGetAttrWithUnsuitableReturn, HasXProperty))
|
||||
static_assert(not is_assignable_to(HasGetAttrWithUnsuitableReturn, HasXProperty))
|
||||
|
||||
class HasGetAttrAndSetAttr:
|
||||
def __getattr__(self, attr: str) -> MyInt:
|
||||
@@ -1195,10 +1211,9 @@ class HasGetAttrAndSetAttr:
|
||||
|
||||
def __setattr__(self, attr: str, value: int) -> None: ...
|
||||
|
||||
static_assert(is_subtype_of(HasGetAttrAndSetAttr, HasXProperty))
|
||||
static_assert(is_assignable_to(HasGetAttrAndSetAttr, HasXProperty))
|
||||
|
||||
# TODO: these should pass
|
||||
static_assert(is_subtype_of(HasGetAttrAndSetAttr, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(HasGetAttrAndSetAttr, HasXProperty)) # error: [static-assert-error]
|
||||
static_assert(is_subtype_of(HasGetAttrAndSetAttr, XAsymmetricProperty)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(HasGetAttrAndSetAttr, XAsymmetricProperty)) # error: [static-assert-error]
|
||||
```
|
||||
@@ -1299,12 +1314,9 @@ class FalsyFooSubclass(FalsyFoo, Protocol):
|
||||
y: str
|
||||
|
||||
def g(a: Truthy, b: FalsyFoo, c: FalsyFooSubclass):
|
||||
# TODO should be `Literal[True]
|
||||
reveal_type(bool(a)) # revealed: bool
|
||||
# TODO should be `Literal[False]
|
||||
reveal_type(bool(b)) # revealed: bool
|
||||
# TODO should be `Literal[False]
|
||||
reveal_type(bool(c)) # revealed: bool
|
||||
reveal_type(bool(a)) # revealed: Literal[True]
|
||||
reveal_type(bool(b)) # revealed: Literal[False]
|
||||
reveal_type(bool(c)) # revealed: Literal[False]
|
||||
```
|
||||
|
||||
It is not sufficient for a protocol to have a callable `__bool__` instance member that returns
|
||||
@@ -1351,12 +1363,12 @@ from knot_extensions import is_subtype_of, is_assignable_to
|
||||
class NominalWithX:
|
||||
x: int = 42
|
||||
|
||||
static_assert(is_assignable_to(NominalWithX, FullyStatic))
|
||||
static_assert(is_assignable_to(NominalWithX, NotFullyStatic))
|
||||
static_assert(is_subtype_of(NominalWithX, FullyStatic))
|
||||
# TODO: these should pass
|
||||
static_assert(is_assignable_to(NominalWithX, FullyStatic)) # error: [static-assert-error]
|
||||
static_assert(is_assignable_to(NominalWithX, NotFullyStatic)) # error: [static-assert-error]
|
||||
static_assert(is_subtype_of(NominalWithX, FullyStatic)) # error: [static-assert-error]
|
||||
|
||||
# TODO: this should pass
|
||||
static_assert(not is_subtype_of(NominalWithX, NotFullyStatic)) # error: [static-assert-error]
|
||||
static_assert(not is_subtype_of(NominalWithX, NotFullyStatic))
|
||||
```
|
||||
|
||||
Empty protocols are fully static; this follows from the fact that an empty protocol is equivalent to
|
||||
|
||||
@@ -13,7 +13,7 @@ if returns_bool():
|
||||
chr: int = 1
|
||||
|
||||
def f():
|
||||
reveal_type(chr) # revealed: int | (def chr(i: SupportsIndex, /) -> str)
|
||||
reveal_type(chr) # revealed: int | (def chr(i: int | SupportsIndex, /) -> str)
|
||||
```
|
||||
|
||||
## Conditionally global or builtin, with annotation
|
||||
@@ -28,5 +28,5 @@ if returns_bool():
|
||||
chr: int = 1
|
||||
|
||||
def f():
|
||||
reveal_type(chr) # revealed: int | (def chr(i: SupportsIndex, /) -> str)
|
||||
reveal_type(chr) # revealed: int | (def chr(i: int | SupportsIndex, /) -> str)
|
||||
```
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
# `TypedDict`
|
||||
|
||||
We do not support `TypedDict`s yet. This test mainly exists to make sure that we do not emit any
|
||||
errors for the definition of a `TypedDict`.
|
||||
|
||||
```py
|
||||
from typing_extensions import TypedDict, Required
|
||||
|
||||
class Person(TypedDict):
|
||||
name: str
|
||||
age: int | None
|
||||
|
||||
# TODO: This should not be an error:
|
||||
# error: [invalid-assignment]
|
||||
alice: Person = {"name": "Alice", "age": 30}
|
||||
|
||||
# Alternative syntax
|
||||
Message = TypedDict("Message", {"id": Required[int], "content": str}, total=False)
|
||||
|
||||
msg = Message(id=1, content="Hello")
|
||||
|
||||
# No errors for yet-unsupported features (`closed`):
|
||||
OtherMessage = TypedDict("OtherMessage", {"id": int, "content": str}, closed=True)
|
||||
|
||||
reveal_type(Person.__required_keys__) # revealed: @Todo(TypedDict)
|
||||
reveal_type(Message.__required_keys__) # revealed: @Todo(TypedDict)
|
||||
```
|
||||
@@ -1114,7 +1114,7 @@ mod tests {
|
||||
fn assert_bound_string_symbol<'db>(db: &'db dyn Db, symbol: Symbol<'db>) {
|
||||
assert!(matches!(
|
||||
symbol,
|
||||
Symbol::Type(Type::NominalInstance(_), Boundness::Bound)
|
||||
Symbol::Type(Type::Instance(_), Boundness::Bound)
|
||||
));
|
||||
assert_eq!(symbol.expect_type(), KnownClass::Str.to_instance(db));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use instance::{Protocol, ProtocolInstanceType};
|
||||
use itertools::Either;
|
||||
|
||||
use std::slice::Iter;
|
||||
@@ -50,8 +49,10 @@ use crate::types::mro::{Mro, MroError, MroIterator};
|
||||
pub(crate) use crate::types::narrow::infer_narrowing_constraint;
|
||||
use crate::types::signatures::{Parameter, ParameterForm, Parameters};
|
||||
use crate::{Db, FxOrderSet, Module, Program};
|
||||
pub(crate) use class::{ClassLiteral, ClassType, GenericAlias, KnownClass};
|
||||
pub(crate) use instance::NominalInstanceType;
|
||||
pub(crate) use class::{
|
||||
Class, ClassLiteralType, ClassType, GenericAlias, GenericClass, KnownClass, NonGenericClass,
|
||||
};
|
||||
pub(crate) use instance::InstanceType;
|
||||
pub(crate) use known_instance::KnownInstanceType;
|
||||
|
||||
mod builder;
|
||||
@@ -469,16 +470,14 @@ pub enum Type<'db> {
|
||||
/// A specific module object
|
||||
ModuleLiteral(ModuleLiteralType<'db>),
|
||||
/// A specific class object
|
||||
ClassLiteral(ClassLiteral<'db>),
|
||||
ClassLiteral(ClassLiteralType<'db>),
|
||||
/// A specialization of a generic class
|
||||
GenericAlias(GenericAlias<'db>),
|
||||
/// The set of all class objects that are subclasses of the given class (C), spelled `type[C]`.
|
||||
SubclassOf(SubclassOfType<'db>),
|
||||
/// The set of Python objects with the given class in their __class__'s method resolution order.
|
||||
/// Construct this variant using the `Type::instance` constructor function.
|
||||
NominalInstance(NominalInstanceType<'db>),
|
||||
/// The set of Python objects that conform to the interface described by a given protocol.
|
||||
ProtocolInstance(ProtocolInstanceType<'db>),
|
||||
Instance(InstanceType<'db>),
|
||||
/// A single Python object that requires special treatment in the type system
|
||||
KnownInstance(KnownInstanceType<'db>),
|
||||
/// An instance of `builtins.property`
|
||||
@@ -513,7 +512,7 @@ pub enum Type<'db> {
|
||||
TypeVar(TypeVarInstance<'db>),
|
||||
// A bound super object like `super()` or `super(A, A())`
|
||||
// This type doesn't handle an unbound super object like `super(A)`; for that we just use
|
||||
// a `Type::NominalInstance` of `builtins.super`.
|
||||
// a `Type::Instance` of `builtins.super`.
|
||||
BoundSuper(BoundSuperType<'db>),
|
||||
// TODO protocols, overloads, generics
|
||||
}
|
||||
@@ -540,23 +539,18 @@ impl<'db> Type<'db> {
|
||||
matches!(self, Type::Never)
|
||||
}
|
||||
|
||||
/// Returns `true` if `self` is [`Type::Callable`].
|
||||
pub const fn is_callable_type(&self) -> bool {
|
||||
matches!(self, Type::Callable(..))
|
||||
}
|
||||
|
||||
fn is_none(&self, db: &'db dyn Db) -> bool {
|
||||
self.into_nominal_instance()
|
||||
self.into_instance()
|
||||
.is_some_and(|instance| instance.class().is_known(db, KnownClass::NoneType))
|
||||
}
|
||||
|
||||
fn is_bool(&self, db: &'db dyn Db) -> bool {
|
||||
self.into_nominal_instance()
|
||||
self.into_instance()
|
||||
.is_some_and(|instance| instance.class().is_known(db, KnownClass::Bool))
|
||||
}
|
||||
|
||||
pub fn is_notimplemented(&self, db: &'db dyn Db) -> bool {
|
||||
self.into_nominal_instance().is_some_and(|instance| {
|
||||
self.into_instance().is_some_and(|instance| {
|
||||
instance
|
||||
.class()
|
||||
.is_known(db, KnownClass::NotImplementedType)
|
||||
@@ -564,7 +558,7 @@ impl<'db> Type<'db> {
|
||||
}
|
||||
|
||||
pub fn is_object(&self, db: &'db dyn Db) -> bool {
|
||||
self.into_nominal_instance()
|
||||
self.into_instance()
|
||||
.is_some_and(|instance| instance.class().is_object(db))
|
||||
}
|
||||
|
||||
@@ -586,7 +580,7 @@ impl<'db> Type<'db> {
|
||||
| Self::BooleanLiteral(_)
|
||||
| Self::BytesLiteral(_)
|
||||
| Self::FunctionLiteral(_)
|
||||
| Self::NominalInstance(_)
|
||||
| Self::Instance(_)
|
||||
| Self::ModuleLiteral(_)
|
||||
| Self::ClassLiteral(_)
|
||||
| Self::KnownInstance(_)
|
||||
@@ -670,12 +664,10 @@ impl<'db> Type<'db> {
|
||||
.iter()
|
||||
.any(|ty| ty.contains_todo(db))
|
||||
}
|
||||
|
||||
Self::ProtocolInstance(protocol) => protocol.contains_todo(),
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn into_class_literal(self) -> Option<ClassLiteral<'db>> {
|
||||
pub const fn into_class_literal(self) -> Option<ClassLiteralType<'db>> {
|
||||
match self {
|
||||
Type::ClassLiteral(class_type) => Some(class_type),
|
||||
_ => None,
|
||||
@@ -683,7 +675,7 @@ impl<'db> Type<'db> {
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn expect_class_literal(self) -> ClassLiteral<'db> {
|
||||
pub fn expect_class_literal(self) -> ClassLiteralType<'db> {
|
||||
self.into_class_literal()
|
||||
.expect("Expected a Type::ClassLiteral variant")
|
||||
}
|
||||
@@ -713,12 +705,11 @@ impl<'db> Type<'db> {
|
||||
.expect("Expected a Type::GenericAlias or Type::ClassLiteral variant")
|
||||
}
|
||||
|
||||
pub fn is_class_type(&self, db: &'db dyn Db) -> bool {
|
||||
match self {
|
||||
Type::ClassLiteral(class) if class.generic_context(db).is_none() => true,
|
||||
Type::GenericAlias(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
pub const fn is_class_type(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Type::ClassLiteral(ClassLiteralType::NonGeneric(_)) | Type::GenericAlias(_)
|
||||
)
|
||||
}
|
||||
|
||||
pub const fn is_property_instance(&self) -> bool {
|
||||
@@ -892,9 +883,8 @@ impl<'db> Type<'db> {
|
||||
Type::Intersection(intersection) => Type::Intersection(intersection.normalized(db)),
|
||||
Type::Tuple(tuple) => Type::Tuple(tuple.normalized(db)),
|
||||
Type::Callable(callable) => Type::Callable(callable.normalized(db)),
|
||||
Type::ProtocolInstance(protocol) => protocol.normalized(db),
|
||||
Type::LiteralString
|
||||
| Type::NominalInstance(_)
|
||||
| Type::Instance(_)
|
||||
| Type::PropertyInstance(_)
|
||||
| Type::AlwaysFalsy
|
||||
| Type::AlwaysTruthy
|
||||
@@ -986,7 +976,7 @@ impl<'db> Type<'db> {
|
||||
(_, Type::Never) => false,
|
||||
|
||||
// Everything is a subtype of `object`.
|
||||
(_, Type::NominalInstance(instance)) if instance.class().is_object(db) => true,
|
||||
(_, Type::Instance(instance)) if instance.class().is_object(db) => true,
|
||||
|
||||
// A fully static typevar is always a subtype of itself, and is never a subtype of any
|
||||
// other typevar, since there is no guarantee that they will be specialized to the same
|
||||
@@ -1156,14 +1146,6 @@ impl<'db> Type<'db> {
|
||||
false
|
||||
}
|
||||
|
||||
(Type::ProtocolInstance(left), Type::ProtocolInstance(right)) => {
|
||||
left.is_subtype_of(db, right)
|
||||
}
|
||||
// A protocol instance can never be a subtype of a nominal type, with the *sole* exception of `object`.
|
||||
// TODO: `Callable` types are also structural types.
|
||||
(Type::ProtocolInstance(_), _) => false,
|
||||
(_, Type::ProtocolInstance(protocol)) => self.satisfies_protocol(db, protocol),
|
||||
|
||||
// A fully static heterogeneous tuple type `A` is a subtype of a fully static heterogeneous tuple type `B`
|
||||
// iff the two tuple types have the same number of elements and each element-type in `A` is a subtype
|
||||
// of the element-type at the same index in `B`. (Now say that 5 times fast.)
|
||||
@@ -1246,7 +1228,7 @@ impl<'db> Type<'db> {
|
||||
metaclass_instance_type.is_subtype_of(db, target)
|
||||
}),
|
||||
|
||||
// For example: `Type::KnownInstance(KnownInstanceType::Type)` is a subtype of `Type::NominalInstance(_SpecialForm)`,
|
||||
// For example: `Type::KnownInstance(KnownInstanceType::Type)` is a subtype of `Type::Instance(_SpecialForm)`,
|
||||
// because `Type::KnownInstance(KnownInstanceType::Type)` is a set with exactly one runtime value in it
|
||||
// (the symbol `typing.Type`), and that symbol is known to be an instance of `typing._SpecialForm` at runtime.
|
||||
(Type::KnownInstance(left), right) => {
|
||||
@@ -1255,11 +1237,11 @@ impl<'db> Type<'db> {
|
||||
|
||||
// `bool` is a subtype of `int`, because `bool` subclasses `int`,
|
||||
// which means that all instances of `bool` are also instances of `int`
|
||||
(Type::NominalInstance(self_instance), Type::NominalInstance(target_instance)) => {
|
||||
(Type::Instance(self_instance), Type::Instance(target_instance)) => {
|
||||
self_instance.is_subtype_of(db, target_instance)
|
||||
}
|
||||
|
||||
(Type::NominalInstance(_), Type::Callable(_)) => {
|
||||
(Type::Instance(_), Type::Callable(_)) => {
|
||||
let call_symbol = self.member(db, "__call__").symbol;
|
||||
match call_symbol {
|
||||
Symbol::Type(Type::BoundMethod(call_function), _) => call_function
|
||||
@@ -1278,7 +1260,7 @@ impl<'db> Type<'db> {
|
||||
|
||||
// Other than the special cases enumerated above, `Instance` types and typevars are
|
||||
// never subtypes of any other variants
|
||||
(Type::NominalInstance(_) | Type::TypeVar(_), _) => false,
|
||||
(Type::Instance(_) | Type::TypeVar(_), _) => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1300,7 +1282,7 @@ impl<'db> Type<'db> {
|
||||
|
||||
// All types are assignable to `object`.
|
||||
// TODO this special case might be removable once the below cases are comprehensive
|
||||
(_, Type::NominalInstance(instance)) if instance.class().is_object(db) => true,
|
||||
(_, Type::Instance(instance)) if instance.class().is_object(db) => true,
|
||||
|
||||
// A typevar is always assignable to itself, and is never assignable to any other
|
||||
// typevar, since there is no guarantee that they will be specialized to the same
|
||||
@@ -1434,7 +1416,7 @@ impl<'db> Type<'db> {
|
||||
// subtypes of `type[object]` are `type[...]` types (or `Never`), and `type[Any]` can
|
||||
// materialize to any `type[...]` type (or to `type[Never]`, which is equivalent to
|
||||
// `Never`.)
|
||||
(Type::SubclassOf(subclass_of_ty), Type::NominalInstance(_))
|
||||
(Type::SubclassOf(subclass_of_ty), Type::Instance(_))
|
||||
if subclass_of_ty.is_dynamic()
|
||||
&& (KnownClass::Type
|
||||
.to_instance(db)
|
||||
@@ -1446,14 +1428,44 @@ impl<'db> Type<'db> {
|
||||
|
||||
// Any type that is assignable to `type[object]` is also assignable to `type[Any]`,
|
||||
// because `type[Any]` can materialize to `type[object]`.
|
||||
(Type::NominalInstance(_), Type::SubclassOf(subclass_of_ty))
|
||||
(Type::Instance(_), Type::SubclassOf(subclass_of_ty))
|
||||
if subclass_of_ty.is_dynamic()
|
||||
&& self.is_assignable_to(db, KnownClass::Type.to_instance(db)) =>
|
||||
{
|
||||
true
|
||||
}
|
||||
|
||||
(Type::NominalInstance(self_instance), Type::NominalInstance(target_instance)) => {
|
||||
// TODO: This is a workaround to avoid false positives (e.g. when checking function calls
|
||||
// with `SupportsIndex` parameters), which should be removed when we understand protocols.
|
||||
(lhs, Type::Instance(instance))
|
||||
if instance.class().is_known(db, KnownClass::SupportsIndex) =>
|
||||
{
|
||||
match lhs {
|
||||
Type::Instance(instance)
|
||||
if matches!(
|
||||
instance.class().known(db),
|
||||
Some(KnownClass::Int | KnownClass::SupportsIndex)
|
||||
) =>
|
||||
{
|
||||
true
|
||||
}
|
||||
Type::IntLiteral(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: ditto for avoiding false positives when checking function calls with `Sized` parameters.
|
||||
(lhs, Type::Instance(instance)) if instance.class().is_known(db, KnownClass::Sized) => {
|
||||
matches!(
|
||||
lhs.to_meta_type(db).member(db, "__len__"),
|
||||
SymbolAndQualifiers {
|
||||
symbol: Symbol::Type(..),
|
||||
..
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
(Type::Instance(self_instance), Type::Instance(target_instance)) => {
|
||||
self_instance.is_assignable_to(db, target_instance)
|
||||
}
|
||||
|
||||
@@ -1461,7 +1473,7 @@ impl<'db> Type<'db> {
|
||||
self_callable.is_assignable_to(db, target_callable)
|
||||
}
|
||||
|
||||
(Type::NominalInstance(_), Type::Callable(_)) => {
|
||||
(Type::Instance(_), Type::Callable(_)) => {
|
||||
let call_symbol = self.member(db, "__call__").symbol;
|
||||
match call_symbol {
|
||||
Symbol::Type(Type::BoundMethod(call_function), _) => call_function
|
||||
@@ -1481,16 +1493,6 @@ impl<'db> Type<'db> {
|
||||
.into_callable_type(db)
|
||||
.is_assignable_to(db, target),
|
||||
|
||||
(Type::ProtocolInstance(left), Type::ProtocolInstance(right)) => {
|
||||
left.is_assignable_to(db, right)
|
||||
}
|
||||
// Other than the dynamic types such as `Any`/`Unknown`/`Todo` handled above,
|
||||
// a protocol instance can never be assignable to a nominal type,
|
||||
// with the *sole* exception of `object`.
|
||||
// TODO: `Callable` types are also structural types.
|
||||
(Type::ProtocolInstance(_), _) => false,
|
||||
(_, Type::ProtocolInstance(protocol)) => self.satisfies_protocol(db, protocol),
|
||||
|
||||
// TODO other types containing gradual forms
|
||||
_ => self.is_subtype_of(db, target),
|
||||
}
|
||||
@@ -1511,16 +1513,7 @@ impl<'db> Type<'db> {
|
||||
}
|
||||
(Type::Tuple(left), Type::Tuple(right)) => left.is_equivalent_to(db, right),
|
||||
(Type::Callable(left), Type::Callable(right)) => left.is_equivalent_to(db, right),
|
||||
(Type::NominalInstance(left), Type::NominalInstance(right)) => {
|
||||
left.is_equivalent_to(db, right)
|
||||
}
|
||||
(Type::ProtocolInstance(first), Type::ProtocolInstance(right)) => {
|
||||
first.is_equivalent_to(db, right)
|
||||
}
|
||||
(Type::ProtocolInstance(protocol), nominal @ Type::NominalInstance(n))
|
||||
| (nominal @ Type::NominalInstance(n), Type::ProtocolInstance(protocol)) => {
|
||||
n.class().is_object(db) && protocol.normalized(db) == nominal
|
||||
}
|
||||
(Type::Instance(left), Type::Instance(right)) => left.is_equivalent_to(db, right),
|
||||
_ => self == other && self.is_fully_static(db) && other.is_fully_static(db),
|
||||
}
|
||||
}
|
||||
@@ -1555,7 +1548,7 @@ impl<'db> Type<'db> {
|
||||
|
||||
(Type::TypeVar(first), Type::TypeVar(second)) => first == second,
|
||||
|
||||
(Type::NominalInstance(first), Type::NominalInstance(second)) => {
|
||||
(Type::Instance(first), Type::Instance(second)) => {
|
||||
first.is_gradual_equivalent_to(db, second)
|
||||
}
|
||||
|
||||
@@ -1571,24 +1564,10 @@ impl<'db> Type<'db> {
|
||||
first.is_gradual_equivalent_to(db, second)
|
||||
}
|
||||
|
||||
(Type::ProtocolInstance(first), Type::ProtocolInstance(right)) => {
|
||||
first.is_gradual_equivalent_to(db, right)
|
||||
}
|
||||
(Type::ProtocolInstance(protocol), nominal @ Type::NominalInstance(n))
|
||||
| (nominal @ Type::NominalInstance(n), Type::ProtocolInstance(protocol)) => {
|
||||
n.class().is_object(db) && protocol.normalized(db) == nominal
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn satisfies_protocol(self, db: &'db dyn Db, protocol: ProtocolInstanceType<'db>) -> bool {
|
||||
protocol
|
||||
.protocol_members(db)
|
||||
.iter()
|
||||
.all(|member| !self.member(db, member).symbol.is_unbound())
|
||||
}
|
||||
|
||||
/// Return true if this type and `other` have no common elements.
|
||||
///
|
||||
/// Note: This function aims to have no false positives, but might return
|
||||
@@ -1785,68 +1764,6 @@ impl<'db> Type<'db> {
|
||||
ty.bool(db).is_always_true()
|
||||
}
|
||||
|
||||
(Type::ProtocolInstance(left), Type::ProtocolInstance(right)) => {
|
||||
left.is_disjoint_from(db, right)
|
||||
}
|
||||
|
||||
// TODO: we could also consider `protocol` to be disjoint from `nominal` if `nominal`
|
||||
// has the right member but the type of its member is disjoint from the type of the
|
||||
// member on `protocol`.
|
||||
(Type::ProtocolInstance(protocol), nominal @ Type::NominalInstance(n))
|
||||
| (nominal @ Type::NominalInstance(n), Type::ProtocolInstance(protocol)) => {
|
||||
n.class().is_final(db) && !nominal.satisfies_protocol(db, protocol)
|
||||
}
|
||||
|
||||
(
|
||||
ty @ (Type::LiteralString
|
||||
| Type::StringLiteral(..)
|
||||
| Type::BytesLiteral(..)
|
||||
| Type::BooleanLiteral(..)
|
||||
| Type::SliceLiteral(..)
|
||||
| Type::ClassLiteral(..)
|
||||
| Type::FunctionLiteral(..)
|
||||
| Type::ModuleLiteral(..)
|
||||
| Type::GenericAlias(..)
|
||||
| Type::IntLiteral(..)),
|
||||
Type::ProtocolInstance(protocol),
|
||||
)
|
||||
| (
|
||||
Type::ProtocolInstance(protocol),
|
||||
ty @ (Type::LiteralString
|
||||
| Type::StringLiteral(..)
|
||||
| Type::BytesLiteral(..)
|
||||
| Type::BooleanLiteral(..)
|
||||
| Type::SliceLiteral(..)
|
||||
| Type::ClassLiteral(..)
|
||||
| Type::FunctionLiteral(..)
|
||||
| Type::ModuleLiteral(..)
|
||||
| Type::GenericAlias(..)
|
||||
| Type::IntLiteral(..)),
|
||||
) => !ty.satisfies_protocol(db, protocol),
|
||||
|
||||
(Type::ProtocolInstance(protocol), Type::KnownInstance(known_instance))
|
||||
| (Type::KnownInstance(known_instance), Type::ProtocolInstance(protocol)) => {
|
||||
!known_instance
|
||||
.instance_fallback(db)
|
||||
.satisfies_protocol(db, protocol)
|
||||
}
|
||||
|
||||
(Type::Callable(_), Type::ProtocolInstance(_))
|
||||
| (Type::ProtocolInstance(_), Type::Callable(_)) => {
|
||||
// TODO disjointness between `Callable` and `ProtocolInstance`
|
||||
false
|
||||
}
|
||||
|
||||
(Type::Tuple(..), Type::ProtocolInstance(..))
|
||||
| (Type::ProtocolInstance(..), Type::Tuple(..)) => {
|
||||
// Currently we do not make any general assumptions about the disjointness of a `Tuple` type
|
||||
// and a `ProtocolInstance` type because a `Tuple` type can be an instance of a tuple
|
||||
// subclass.
|
||||
//
|
||||
// TODO when we capture the types of the protocol members, we can improve on this.
|
||||
false
|
||||
}
|
||||
|
||||
// for `type[Any]`/`type[Unknown]`/`type[Todo]`, we know the type cannot be any larger than `type`,
|
||||
// so although the type is dynamic we can still determine disjointedness in some situations
|
||||
(Type::SubclassOf(subclass_of_ty), other)
|
||||
@@ -1859,8 +1776,8 @@ impl<'db> Type<'db> {
|
||||
.is_disjoint_from(db, other),
|
||||
},
|
||||
|
||||
(Type::KnownInstance(known_instance), Type::NominalInstance(instance))
|
||||
| (Type::NominalInstance(instance), Type::KnownInstance(known_instance)) => {
|
||||
(Type::KnownInstance(known_instance), Type::Instance(instance))
|
||||
| (Type::Instance(instance), Type::KnownInstance(known_instance)) => {
|
||||
!known_instance.is_instance_of(db, instance.class())
|
||||
}
|
||||
|
||||
@@ -1869,8 +1786,8 @@ impl<'db> Type<'db> {
|
||||
known_instance_ty.is_disjoint_from(db, KnownClass::Tuple.to_instance(db))
|
||||
}
|
||||
|
||||
(Type::BooleanLiteral(..), Type::NominalInstance(instance))
|
||||
| (Type::NominalInstance(instance), Type::BooleanLiteral(..)) => {
|
||||
(Type::BooleanLiteral(..), Type::Instance(instance))
|
||||
| (Type::Instance(instance), Type::BooleanLiteral(..)) => {
|
||||
// A `Type::BooleanLiteral()` must be an instance of exactly `bool`
|
||||
// (it cannot be an instance of a `bool` subclass)
|
||||
!KnownClass::Bool.is_subclass_of(db, instance.class())
|
||||
@@ -1878,8 +1795,8 @@ impl<'db> Type<'db> {
|
||||
|
||||
(Type::BooleanLiteral(..), _) | (_, Type::BooleanLiteral(..)) => true,
|
||||
|
||||
(Type::IntLiteral(..), Type::NominalInstance(instance))
|
||||
| (Type::NominalInstance(instance), Type::IntLiteral(..)) => {
|
||||
(Type::IntLiteral(..), Type::Instance(instance))
|
||||
| (Type::Instance(instance), Type::IntLiteral(..)) => {
|
||||
// A `Type::IntLiteral()` must be an instance of exactly `int`
|
||||
// (it cannot be an instance of an `int` subclass)
|
||||
!KnownClass::Int.is_subclass_of(db, instance.class())
|
||||
@@ -1890,8 +1807,8 @@ impl<'db> Type<'db> {
|
||||
(Type::StringLiteral(..), Type::LiteralString)
|
||||
| (Type::LiteralString, Type::StringLiteral(..)) => false,
|
||||
|
||||
(Type::StringLiteral(..) | Type::LiteralString, Type::NominalInstance(instance))
|
||||
| (Type::NominalInstance(instance), Type::StringLiteral(..) | Type::LiteralString) => {
|
||||
(Type::StringLiteral(..) | Type::LiteralString, Type::Instance(instance))
|
||||
| (Type::Instance(instance), Type::StringLiteral(..) | Type::LiteralString) => {
|
||||
// A `Type::StringLiteral()` or a `Type::LiteralString` must be an instance of exactly `str`
|
||||
// (it cannot be an instance of a `str` subclass)
|
||||
!KnownClass::Str.is_subclass_of(db, instance.class())
|
||||
@@ -1900,15 +1817,15 @@ impl<'db> Type<'db> {
|
||||
(Type::LiteralString, Type::LiteralString) => false,
|
||||
(Type::LiteralString, _) | (_, Type::LiteralString) => true,
|
||||
|
||||
(Type::BytesLiteral(..), Type::NominalInstance(instance))
|
||||
| (Type::NominalInstance(instance), Type::BytesLiteral(..)) => {
|
||||
(Type::BytesLiteral(..), Type::Instance(instance))
|
||||
| (Type::Instance(instance), Type::BytesLiteral(..)) => {
|
||||
// A `Type::BytesLiteral()` must be an instance of exactly `bytes`
|
||||
// (it cannot be an instance of a `bytes` subclass)
|
||||
!KnownClass::Bytes.is_subclass_of(db, instance.class())
|
||||
}
|
||||
|
||||
(Type::SliceLiteral(..), Type::NominalInstance(instance))
|
||||
| (Type::NominalInstance(instance), Type::SliceLiteral(..)) => {
|
||||
(Type::SliceLiteral(..), Type::Instance(instance))
|
||||
| (Type::Instance(instance), Type::SliceLiteral(..)) => {
|
||||
// A `Type::SliceLiteral` must be an instance of exactly `slice`
|
||||
// (it cannot be an instance of a `slice` subclass)
|
||||
!KnownClass::Slice.is_subclass_of(db, instance.class())
|
||||
@@ -1917,19 +1834,17 @@ impl<'db> Type<'db> {
|
||||
// A class-literal type `X` is always disjoint from an instance type `Y`,
|
||||
// unless the type expressing "all instances of `Z`" is a subtype of of `Y`,
|
||||
// where `Z` is `X`'s metaclass.
|
||||
(Type::ClassLiteral(class), instance @ Type::NominalInstance(_))
|
||||
| (instance @ Type::NominalInstance(_), Type::ClassLiteral(class)) => !class
|
||||
(Type::ClassLiteral(class), instance @ Type::Instance(_))
|
||||
| (instance @ Type::Instance(_), Type::ClassLiteral(class)) => !class
|
||||
.metaclass_instance_type(db)
|
||||
.is_subtype_of(db, instance),
|
||||
(Type::GenericAlias(alias), instance @ Type::Instance(_))
|
||||
| (instance @ Type::Instance(_), Type::GenericAlias(alias)) => !ClassType::from(alias)
|
||||
.metaclass_instance_type(db)
|
||||
.is_subtype_of(db, instance),
|
||||
(Type::GenericAlias(alias), instance @ Type::NominalInstance(_))
|
||||
| (instance @ Type::NominalInstance(_), Type::GenericAlias(alias)) => {
|
||||
!ClassType::from(alias)
|
||||
.metaclass_instance_type(db)
|
||||
.is_subtype_of(db, instance)
|
||||
}
|
||||
|
||||
(Type::FunctionLiteral(..), Type::NominalInstance(instance))
|
||||
| (Type::NominalInstance(instance), Type::FunctionLiteral(..)) => {
|
||||
(Type::FunctionLiteral(..), Type::Instance(instance))
|
||||
| (Type::Instance(instance), Type::FunctionLiteral(..)) => {
|
||||
// A `Type::FunctionLiteral()` must be an instance of exactly `types.FunctionType`
|
||||
// (it cannot be an instance of a `types.FunctionType` subclass)
|
||||
!KnownClass::FunctionType.is_subclass_of(db, instance.class())
|
||||
@@ -1985,15 +1900,13 @@ impl<'db> Type<'db> {
|
||||
false
|
||||
}
|
||||
|
||||
(Type::ModuleLiteral(..), other @ Type::NominalInstance(..))
|
||||
| (other @ Type::NominalInstance(..), Type::ModuleLiteral(..)) => {
|
||||
(Type::ModuleLiteral(..), other @ Type::Instance(..))
|
||||
| (other @ Type::Instance(..), Type::ModuleLiteral(..)) => {
|
||||
// Modules *can* actually be instances of `ModuleType` subclasses
|
||||
other.is_disjoint_from(db, KnownClass::ModuleType.to_instance(db))
|
||||
}
|
||||
|
||||
(Type::NominalInstance(left), Type::NominalInstance(right)) => {
|
||||
left.is_disjoint_from(db, right)
|
||||
}
|
||||
(Type::Instance(left), Type::Instance(right)) => left.is_disjoint_from(db, right),
|
||||
|
||||
(Type::Tuple(tuple), Type::Tuple(other_tuple)) => {
|
||||
let self_elements = tuple.elements(db);
|
||||
@@ -2005,8 +1918,8 @@ impl<'db> Type<'db> {
|
||||
.any(|(e1, e2)| e1.is_disjoint_from(db, *e2))
|
||||
}
|
||||
|
||||
(Type::Tuple(..), instance @ Type::NominalInstance(_))
|
||||
| (instance @ Type::NominalInstance(_), Type::Tuple(..)) => {
|
||||
(Type::Tuple(..), instance @ Type::Instance(_))
|
||||
| (instance @ Type::Instance(_), Type::Tuple(..)) => {
|
||||
// We cannot be sure if the tuple is disjoint from the instance because:
|
||||
// - 'other' might be the homogeneous arbitrary-length tuple type
|
||||
// tuple[T, ...] (which we don't have support for yet); if all of
|
||||
@@ -2052,8 +1965,6 @@ impl<'db> Type<'db> {
|
||||
| Type::AlwaysTruthy
|
||||
| Type::PropertyInstance(_) => true,
|
||||
|
||||
Type::ProtocolInstance(protocol) => protocol.is_fully_static(),
|
||||
|
||||
Type::TypeVar(typevar) => match typevar.bound_or_constraints(db) {
|
||||
None => true,
|
||||
Some(TypeVarBoundOrConstraints::UpperBound(bound)) => bound.is_fully_static(db),
|
||||
@@ -2068,7 +1979,7 @@ impl<'db> Type<'db> {
|
||||
!matches!(bound_super.pivot_class(db), ClassBase::Dynamic(_))
|
||||
&& !matches!(bound_super.owner(db), SuperOwnerKind::Dynamic(_))
|
||||
}
|
||||
Type::ClassLiteral(_) | Type::GenericAlias(_) | Type::NominalInstance(_) => {
|
||||
Type::ClassLiteral(_) | Type::GenericAlias(_) | Type::Instance(_) => {
|
||||
// TODO: Ideally, we would iterate over the MRO of the class, check if all
|
||||
// bases are fully static, and only return `true` if that is the case.
|
||||
//
|
||||
@@ -2119,26 +2030,6 @@ impl<'db> Type<'db> {
|
||||
false
|
||||
}
|
||||
|
||||
Type::ProtocolInstance(..) => {
|
||||
// It *might* be possible to have a singleton protocol-instance type...?
|
||||
//
|
||||
// E.g.:
|
||||
//
|
||||
// ```py
|
||||
// from typing import Protocol, Callable
|
||||
//
|
||||
// class WeirdAndWacky(Protocol):
|
||||
// @property
|
||||
// def __class__(self) -> Callable[[], None]: ...
|
||||
// ```
|
||||
//
|
||||
// `WeirdAndWacky` only has a single possible inhabitant: `None`!
|
||||
// It is thus a singleton type.
|
||||
// However, going out of our way to recognise it as such is probably not worth it.
|
||||
// Such cases should anyway be exceedingly rare and/or contrived.
|
||||
false
|
||||
}
|
||||
|
||||
// An unbounded, unconstrained typevar is not a singleton, because it can be
|
||||
// specialized to a non-singleton type. A bounded typevar is not a singleton, even if
|
||||
// the bound is a final singleton class, since it can still be specialized to `Never`.
|
||||
@@ -2194,7 +2085,7 @@ impl<'db> Type<'db> {
|
||||
false
|
||||
}
|
||||
Type::DataclassDecorator(_) | Type::DataclassTransformer(_) => false,
|
||||
Type::NominalInstance(instance) => instance.is_singleton(db),
|
||||
Type::Instance(instance) => instance.is_singleton(db),
|
||||
Type::PropertyInstance(_) => false,
|
||||
Type::Tuple(..) => {
|
||||
// The empty tuple is a singleton on CPython and PyPy, but not on other Python
|
||||
@@ -2241,11 +2132,6 @@ impl<'db> Type<'db> {
|
||||
| Type::SliceLiteral(..)
|
||||
| Type::KnownInstance(..) => true,
|
||||
|
||||
Type::ProtocolInstance(..) => {
|
||||
// See comment in the `Type::ProtocolInstance` branch for `Type::is_singleton`.
|
||||
false
|
||||
}
|
||||
|
||||
// An unbounded, unconstrained typevar is not single-valued, because it can be
|
||||
// specialized to a multiple-valued type. A bounded typevar is not single-valued, even
|
||||
// if the bound is a final single-valued class, since it can still be specialized to
|
||||
@@ -2271,7 +2157,7 @@ impl<'db> Type<'db> {
|
||||
.iter()
|
||||
.all(|elem| elem.is_single_valued(db)),
|
||||
|
||||
Type::NominalInstance(instance) => instance.is_single_valued(db),
|
||||
Type::Instance(instance) => instance.is_single_valued(db),
|
||||
|
||||
Type::BoundSuper(_) => {
|
||||
// At runtime two super instances never compare equal, even if their arguments are identical.
|
||||
@@ -2409,11 +2295,10 @@ impl<'db> Type<'db> {
|
||||
.to_class_literal(db)
|
||||
.find_name_in_mro_with_policy(db, name, policy),
|
||||
|
||||
// We eagerly normalize type[object], i.e. Type::SubclassOf(object) to `type`,
|
||||
// i.e. Type::NominalInstance(type). So looking up a name in the MRO of
|
||||
// `Type::NominalInstance(type)` is equivalent to looking up the name in the
|
||||
// We eagerly normalize type[object], i.e. Type::SubclassOf(object) to `type`, i.e. Type::Instance(type).
|
||||
// So looking up a name in the MRO of `Type::Instance(type)` is equivalent to looking up the name in the
|
||||
// MRO of the class `object`.
|
||||
Type::NominalInstance(instance) if instance.class().is_known(db, KnownClass::Type) => {
|
||||
Type::Instance(instance) if instance.class().is_known(db, KnownClass::Type) => {
|
||||
KnownClass::Object
|
||||
.to_class_literal(db)
|
||||
.find_name_in_mro_with_policy(db, name, policy)
|
||||
@@ -2438,8 +2323,7 @@ impl<'db> Type<'db> {
|
||||
| Type::SliceLiteral(_)
|
||||
| Type::Tuple(_)
|
||||
| Type::TypeVar(_)
|
||||
| Type::NominalInstance(_)
|
||||
| Type::ProtocolInstance(_)
|
||||
| Type::Instance(_)
|
||||
| Type::PropertyInstance(_) => None,
|
||||
}
|
||||
}
|
||||
@@ -2504,18 +2388,7 @@ impl<'db> Type<'db> {
|
||||
|
||||
Type::Dynamic(_) | Type::Never => Symbol::bound(self).into(),
|
||||
|
||||
Type::NominalInstance(instance) => instance.class().instance_member(db, name),
|
||||
|
||||
Type::ProtocolInstance(protocol) => match protocol.inner() {
|
||||
Protocol::FromClass(class) => class.instance_member(db, name),
|
||||
Protocol::Synthesized(synthesized) => {
|
||||
if synthesized.members(db).contains(name) {
|
||||
SymbolAndQualifiers::todo("Capture type of synthesized protocol members")
|
||||
} else {
|
||||
Symbol::Unbound.into()
|
||||
}
|
||||
}
|
||||
},
|
||||
Type::Instance(instance) => instance.class().instance_member(db, name),
|
||||
|
||||
Type::FunctionLiteral(_) => KnownClass::FunctionType
|
||||
.to_instance(db)
|
||||
@@ -2956,7 +2829,7 @@ impl<'db> Type<'db> {
|
||||
.to_instance(db)
|
||||
.member_lookup_with_policy(db, name, policy),
|
||||
|
||||
Type::NominalInstance(instance)
|
||||
Type::Instance(instance)
|
||||
if matches!(name.as_str(), "major" | "minor")
|
||||
&& instance.class().is_known(db, KnownClass::VersionInfo) =>
|
||||
{
|
||||
@@ -2998,8 +2871,7 @@ impl<'db> Type<'db> {
|
||||
policy,
|
||||
),
|
||||
|
||||
Type::NominalInstance(..)
|
||||
| Type::ProtocolInstance(..)
|
||||
Type::Instance(..)
|
||||
| Type::BooleanLiteral(..)
|
||||
| Type::IntLiteral(..)
|
||||
| Type::StringLiteral(..)
|
||||
@@ -3030,7 +2902,7 @@ impl<'db> Type<'db> {
|
||||
// It will need a special handling, so it remember the origin type to properly
|
||||
// resolve the attribute.
|
||||
if matches!(
|
||||
self.into_nominal_instance()
|
||||
self.into_instance()
|
||||
.and_then(|instance| instance.class().known(db)),
|
||||
Some(KnownClass::ModuleType | KnownClass::GenericAlias)
|
||||
) {
|
||||
@@ -3291,13 +3163,11 @@ impl<'db> Type<'db> {
|
||||
}
|
||||
},
|
||||
|
||||
Type::NominalInstance(instance) => match instance.class().known(db) {
|
||||
Type::Instance(instance) => match instance.class().known(db) {
|
||||
Some(known_class) => known_class.bool(),
|
||||
None => try_dunder_bool()?,
|
||||
},
|
||||
|
||||
Type::ProtocolInstance(_) => try_dunder_bool()?,
|
||||
|
||||
Type::KnownInstance(known_instance) => known_instance.bool(),
|
||||
|
||||
Type::PropertyInstance(_) => Truthiness::AlwaysTrue,
|
||||
@@ -4016,28 +3886,6 @@ impl<'db> Type<'db> {
|
||||
}
|
||||
},
|
||||
|
||||
Type::KnownInstance(KnownInstanceType::TypedDict) => {
|
||||
Signatures::single(CallableSignature::single(
|
||||
self,
|
||||
Signature::new(
|
||||
Parameters::new([
|
||||
Parameter::positional_only(Some(Name::new_static("typename")))
|
||||
.with_annotated_type(KnownClass::Str.to_instance(db)),
|
||||
Parameter::positional_only(Some(Name::new_static("fields")))
|
||||
.with_annotated_type(KnownClass::Dict.to_instance(db))
|
||||
.with_default_type(Type::any()),
|
||||
Parameter::keyword_only(Name::new_static("total"))
|
||||
.with_annotated_type(KnownClass::Bool.to_instance(db))
|
||||
.with_default_type(Type::BooleanLiteral(true)),
|
||||
// Future compatibility, in case new keyword arguments will be added:
|
||||
Parameter::keyword_variadic(Name::new_static("kwargs"))
|
||||
.with_annotated_type(Type::any()),
|
||||
]),
|
||||
None,
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
Type::GenericAlias(_) => {
|
||||
// TODO annotated return type on `__new__` or metaclass `__call__`
|
||||
// TODO check call vs signatures of `__new__` and/or `__init__`
|
||||
@@ -4059,7 +3907,7 @@ impl<'db> Type<'db> {
|
||||
SubclassOfInner::Class(class) => Type::from(class).signatures(db),
|
||||
},
|
||||
|
||||
Type::NominalInstance(_) => {
|
||||
Type::Instance(_) => {
|
||||
// Note that for objects that have a (possibly not callable!) `__call__` attribute,
|
||||
// we will get the signature of the `__call__` attribute, but will pass in the type
|
||||
// of the original object as the "callable type". That ensures that we get errors
|
||||
@@ -4345,16 +4193,13 @@ impl<'db> Type<'db> {
|
||||
// do this, we instead use the _identity_ specialization, which maps each of the class's
|
||||
// generic typevars to itself.
|
||||
let (generic_origin, self_type) = match self {
|
||||
Type::ClassLiteral(class) => match class.generic_context(db) {
|
||||
Some(generic_context) => {
|
||||
let specialization = generic_context.identity_specialization(db);
|
||||
(
|
||||
Some(class),
|
||||
Type::GenericAlias(GenericAlias::new(db, class, specialization)),
|
||||
)
|
||||
}
|
||||
_ => (None, self),
|
||||
},
|
||||
Type::ClassLiteral(ClassLiteralType::Generic(generic)) => {
|
||||
let specialization = generic.generic_context(db).identity_specialization(db);
|
||||
(
|
||||
Some(generic),
|
||||
Type::GenericAlias(GenericAlias::new(db, generic, specialization)),
|
||||
)
|
||||
}
|
||||
_ => (None, self),
|
||||
};
|
||||
|
||||
@@ -4454,14 +4299,11 @@ impl<'db> Type<'db> {
|
||||
};
|
||||
let specialized = specialization
|
||||
.map(|specialization| {
|
||||
Type::instance(
|
||||
Type::instance(ClassType::Generic(GenericAlias::new(
|
||||
db,
|
||||
ClassType::Generic(GenericAlias::new(
|
||||
db,
|
||||
generic_origin,
|
||||
specialization,
|
||||
)),
|
||||
)
|
||||
generic_origin,
|
||||
specialization,
|
||||
)))
|
||||
})
|
||||
.unwrap_or(instance_ty);
|
||||
Ok(specialized)
|
||||
@@ -4492,9 +4334,9 @@ impl<'db> Type<'db> {
|
||||
pub fn to_instance(&self, db: &'db dyn Db) -> Option<Type<'db>> {
|
||||
match self {
|
||||
Type::Dynamic(_) | Type::Never => Some(*self),
|
||||
Type::ClassLiteral(class) => Some(Type::instance(db, class.default_specialization(db))),
|
||||
Type::GenericAlias(alias) => Some(Type::instance(db, ClassType::from(*alias))),
|
||||
Type::SubclassOf(subclass_of_ty) => Some(subclass_of_ty.to_instance(db)),
|
||||
Type::ClassLiteral(class) => Some(Type::instance(class.default_specialization(db))),
|
||||
Type::GenericAlias(alias) => Some(Type::instance(ClassType::from(*alias))),
|
||||
Type::SubclassOf(subclass_of_ty) => Some(subclass_of_ty.to_instance()),
|
||||
Type::Union(union) => {
|
||||
let mut builder = UnionBuilder::new(db);
|
||||
for element in union.elements(db) {
|
||||
@@ -4512,8 +4354,7 @@ impl<'db> Type<'db> {
|
||||
| Type::WrapperDescriptor(_)
|
||||
| Type::DataclassDecorator(_)
|
||||
| Type::DataclassTransformer(_)
|
||||
| Type::NominalInstance(_)
|
||||
| Type::ProtocolInstance(_)
|
||||
| Type::Instance(_)
|
||||
| Type::KnownInstance(_)
|
||||
| Type::PropertyInstance(_)
|
||||
| Type::ModuleLiteral(_)
|
||||
@@ -4533,7 +4374,7 @@ impl<'db> Type<'db> {
|
||||
///
|
||||
/// For example, the builtin `int` as a value expression is of type
|
||||
/// `Type::ClassLiteral(builtins.int)`, that is, it is the `int` class itself. As a type
|
||||
/// expression, it names the type `Type::NominalInstance(builtins.int)`, that is, all objects whose
|
||||
/// expression, it names the type `Type::Instance(builtins.int)`, that is, all objects whose
|
||||
/// `__class__` is `int`.
|
||||
pub fn in_type_expression(
|
||||
&self,
|
||||
@@ -4560,11 +4401,11 @@ impl<'db> Type<'db> {
|
||||
KnownClass::Float.to_instance(db),
|
||||
],
|
||||
),
|
||||
_ => Type::instance(db, class.default_specialization(db)),
|
||||
_ => Type::instance(class.default_specialization(db)),
|
||||
};
|
||||
Ok(ty)
|
||||
}
|
||||
Type::GenericAlias(alias) => Ok(Type::instance(db, ClassType::from(*alias))),
|
||||
Type::GenericAlias(alias) => Ok(Type::instance(ClassType::from(*alias))),
|
||||
|
||||
Type::SubclassOf(_)
|
||||
| Type::BooleanLiteral(_)
|
||||
@@ -4587,7 +4428,6 @@ impl<'db> Type<'db> {
|
||||
| Type::Never
|
||||
| Type::FunctionLiteral(_)
|
||||
| Type::BoundSuper(_)
|
||||
| Type::ProtocolInstance(_)
|
||||
| Type::PropertyInstance(_) => Err(InvalidTypeExpressionError {
|
||||
invalid_expressions: smallvec::smallvec![InvalidTypeExpression::InvalidType(*self)],
|
||||
fallback_type: Type::unknown(),
|
||||
@@ -4624,7 +4464,6 @@ impl<'db> Type<'db> {
|
||||
|
||||
KnownInstanceType::TypingSelf => Ok(todo_type!("Support for `typing.Self`")),
|
||||
KnownInstanceType::TypeAlias => Ok(todo_type!("Support for `typing.TypeAlias`")),
|
||||
KnownInstanceType::TypedDict => Ok(todo_type!("Support for `typing.TypedDict`")),
|
||||
|
||||
KnownInstanceType::Protocol => Err(InvalidTypeExpressionError {
|
||||
invalid_expressions: smallvec::smallvec![InvalidTypeExpression::Protocol],
|
||||
@@ -4712,7 +4551,7 @@ impl<'db> Type<'db> {
|
||||
|
||||
Type::Dynamic(_) => Ok(*self),
|
||||
|
||||
Type::NominalInstance(instance) => match instance.class().known(db) {
|
||||
Type::Instance(instance) => match instance.class().known(db) {
|
||||
Some(KnownClass::TypeVar) => Ok(todo_type!(
|
||||
"Support for `typing.TypeVar` instances in type expressions"
|
||||
)),
|
||||
@@ -4788,7 +4627,7 @@ impl<'db> Type<'db> {
|
||||
pub fn to_meta_type(&self, db: &'db dyn Db) -> Type<'db> {
|
||||
match self {
|
||||
Type::Never => Type::Never,
|
||||
Type::NominalInstance(instance) => instance.to_meta_type(db),
|
||||
Type::Instance(instance) => instance.to_meta_type(db),
|
||||
Type::KnownInstance(known_instance) => known_instance.to_meta_type(db),
|
||||
Type::PropertyInstance(_) => KnownClass::Property.to_class_literal(db),
|
||||
Type::Union(union) => union.map(db, |ty| ty.to_meta_type(db)),
|
||||
@@ -4836,7 +4675,6 @@ impl<'db> Type<'db> {
|
||||
),
|
||||
Type::AlwaysTruthy | Type::AlwaysFalsy => KnownClass::Type.to_instance(db),
|
||||
Type::BoundSuper(_) => KnownClass::Super.to_class_literal(db),
|
||||
Type::ProtocolInstance(protocol) => protocol.to_meta_type(db),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4958,11 +4796,9 @@ impl<'db> Type<'db> {
|
||||
| Type::BytesLiteral(_)
|
||||
| Type::SliceLiteral(_)
|
||||
| Type::BoundSuper(_)
|
||||
// `NominalInstance` contains a ClassType, which has already been specialized if needed,
|
||||
// like above with BoundMethod's self_instance.
|
||||
| Type::NominalInstance(_)
|
||||
// Same for `ProtocolInstance`
|
||||
| Type::ProtocolInstance(_)
|
||||
// Instance contains a ClassType, which has already been specialized if needed, like
|
||||
// above with BoundMethod's self_instance.
|
||||
| Type::Instance(_)
|
||||
| Type::KnownInstance(_) => self,
|
||||
}
|
||||
}
|
||||
@@ -5026,7 +4862,7 @@ impl<'db> Type<'db> {
|
||||
Some(TypeDefinition::Class(class_literal.definition(db)))
|
||||
}
|
||||
Self::GenericAlias(alias) => Some(TypeDefinition::Class(alias.definition(db))),
|
||||
Self::NominalInstance(instance) => {
|
||||
Self::Instance(instance) => {
|
||||
Some(TypeDefinition::Class(instance.class().definition(db)))
|
||||
}
|
||||
Self::KnownInstance(instance) => match instance {
|
||||
@@ -5060,11 +4896,6 @@ impl<'db> Type<'db> {
|
||||
|
||||
Self::TypeVar(var) => Some(TypeDefinition::TypeVar(var.definition(db))),
|
||||
|
||||
Self::ProtocolInstance(protocol) => match protocol.inner() {
|
||||
Protocol::FromClass(class) => Some(TypeDefinition::Class(class.definition(db))),
|
||||
Protocol::Synthesized(_) => None,
|
||||
},
|
||||
|
||||
Self::Union(_) | Self::Intersection(_) => None,
|
||||
|
||||
// These types have no definition
|
||||
@@ -6738,18 +6569,6 @@ impl<'db> CallableType<'db> {
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a callable type which represents a fully-static "bottom" callable.
|
||||
///
|
||||
/// Specifically, this represents a callable type with a single signature:
|
||||
/// `(*args: object, **kwargs: object) -> Never`.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn bottom(db: &'db dyn Db) -> Type<'db> {
|
||||
Type::Callable(CallableType::single(
|
||||
db,
|
||||
Signature::new(Parameters::object(db), Some(Type::Never)),
|
||||
))
|
||||
}
|
||||
|
||||
/// Return a "normalized" version of this `Callable` type.
|
||||
///
|
||||
/// See [`Type::normalized`] for more details.
|
||||
@@ -6987,7 +6806,7 @@ impl<'db> TypeAliasType<'db> {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, salsa::Update)]
|
||||
pub(super) struct MetaclassCandidate<'db> {
|
||||
metaclass: ClassType<'db>,
|
||||
explicit_metaclass_of: ClassLiteral<'db>,
|
||||
explicit_metaclass_of: ClassLiteralType<'db>,
|
||||
}
|
||||
|
||||
#[salsa::interned(debug)]
|
||||
@@ -7619,7 +7438,7 @@ impl BoundSuperError<'_> {
|
||||
pub enum SuperOwnerKind<'db> {
|
||||
Dynamic(DynamicType),
|
||||
Class(ClassType<'db>),
|
||||
Instance(NominalInstanceType<'db>),
|
||||
Instance(InstanceType<'db>),
|
||||
}
|
||||
|
||||
impl<'db> SuperOwnerKind<'db> {
|
||||
@@ -7653,7 +7472,7 @@ impl<'db> SuperOwnerKind<'db> {
|
||||
Type::ClassLiteral(class_literal) => Some(SuperOwnerKind::Class(
|
||||
class_literal.apply_optional_specialization(db, None),
|
||||
)),
|
||||
Type::NominalInstance(instance) => Some(SuperOwnerKind::Instance(instance)),
|
||||
Type::Instance(instance) => Some(SuperOwnerKind::Instance(instance)),
|
||||
Type::BooleanLiteral(_) => {
|
||||
SuperOwnerKind::try_from_type(db, KnownClass::Bool.to_instance(db))
|
||||
}
|
||||
@@ -7836,9 +7655,11 @@ impl<'db> BoundSuperType<'db> {
|
||||
// super(B, b_int)
|
||||
// super(B[int], b_unknown)
|
||||
// ```
|
||||
match class_literal.generic_context(db) {
|
||||
Some(_) => Symbol::bound(todo_type!("super in generic class")).into(),
|
||||
None => class_literal.class_member_from_mro(
|
||||
match class_literal {
|
||||
ClassLiteralType::Generic(_) => {
|
||||
Symbol::bound(todo_type!("super in generic class")).into()
|
||||
}
|
||||
ClassLiteralType::NonGeneric(_) => class_literal.class_member_from_mro(
|
||||
db,
|
||||
name,
|
||||
policy,
|
||||
|
||||
@@ -591,7 +591,7 @@ impl<'db> InnerIntersectionBuilder<'db> {
|
||||
}
|
||||
_ => {
|
||||
let known_instance = new_positive
|
||||
.into_nominal_instance()
|
||||
.into_instance()
|
||||
.and_then(|instance| instance.class().known(db));
|
||||
|
||||
if known_instance == Some(KnownClass::Object) {
|
||||
@@ -611,7 +611,7 @@ impl<'db> InnerIntersectionBuilder<'db> {
|
||||
Type::AlwaysFalsy if addition_is_bool_instance => {
|
||||
new_positive = Type::BooleanLiteral(false);
|
||||
}
|
||||
Type::NominalInstance(instance)
|
||||
Type::Instance(instance)
|
||||
if instance.class().is_known(db, KnownClass::Bool) =>
|
||||
{
|
||||
match new_positive {
|
||||
@@ -705,7 +705,7 @@ impl<'db> InnerIntersectionBuilder<'db> {
|
||||
let contains_bool = || {
|
||||
self.positive
|
||||
.iter()
|
||||
.filter_map(|ty| ty.into_nominal_instance())
|
||||
.filter_map(|ty| ty.into_instance())
|
||||
.filter_map(|instance| instance.class().known(db))
|
||||
.any(KnownClass::is_bool)
|
||||
};
|
||||
@@ -722,7 +722,7 @@ impl<'db> InnerIntersectionBuilder<'db> {
|
||||
Type::Never => {
|
||||
// Adding ~Never to an intersection is a no-op.
|
||||
}
|
||||
Type::NominalInstance(instance) if instance.class().is_object(db) => {
|
||||
Type::Instance(instance) if instance.class().is_object(db) => {
|
||||
// Adding ~object to an intersection results in Never.
|
||||
*self = Self::default();
|
||||
self.positive.insert(Type::Never);
|
||||
|
||||
@@ -19,9 +19,9 @@ use crate::types::diagnostic::{
|
||||
use crate::types::generics::{Specialization, SpecializationBuilder};
|
||||
use crate::types::signatures::{Parameter, ParameterForm};
|
||||
use crate::types::{
|
||||
todo_type, BoundMethodType, DataclassParams, DataclassTransformerParams, FunctionDecorators,
|
||||
KnownClass, KnownFunction, KnownInstanceType, MethodWrapperKind, PropertyInstanceType,
|
||||
TupleType, UnionType, WrapperDescriptorKind,
|
||||
BoundMethodType, DataclassParams, DataclassTransformerParams, FunctionDecorators, KnownClass,
|
||||
KnownFunction, KnownInstanceType, MethodWrapperKind, PropertyInstanceType, TupleType,
|
||||
UnionType, WrapperDescriptorKind,
|
||||
};
|
||||
use ruff_db::diagnostic::{Annotation, Severity, SubDiagnostic};
|
||||
use ruff_python_ast as ast;
|
||||
@@ -772,10 +772,6 @@ impl<'db> Bindings<'db> {
|
||||
_ => {}
|
||||
},
|
||||
|
||||
Type::KnownInstance(KnownInstanceType::TypedDict) => {
|
||||
overload.set_return_type(todo_type!("TypedDict"));
|
||||
}
|
||||
|
||||
// Not a special case
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -50,67 +50,111 @@ fn explicit_bases_cycle_recover<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_value: &[Type<'db>],
|
||||
_count: u32,
|
||||
_self: ClassLiteral<'db>,
|
||||
_self: ClassLiteralType<'db>,
|
||||
) -> salsa::CycleRecoveryAction<Box<[Type<'db>]>> {
|
||||
salsa::CycleRecoveryAction::Iterate
|
||||
}
|
||||
|
||||
fn explicit_bases_cycle_initial<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_self: ClassLiteral<'db>,
|
||||
_self: ClassLiteralType<'db>,
|
||||
) -> Box<[Type<'db>]> {
|
||||
Box::default()
|
||||
}
|
||||
|
||||
fn try_mro_cycle_recover<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_value: &Result<Mro<'db>, MroError<'db>>,
|
||||
_count: u32,
|
||||
_self: ClassLiteral<'db>,
|
||||
_specialization: Option<Specialization<'db>>,
|
||||
) -> salsa::CycleRecoveryAction<Result<Mro<'db>, MroError<'db>>> {
|
||||
salsa::CycleRecoveryAction::Iterate
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn try_mro_cycle_initial<'db>(
|
||||
db: &'db dyn Db,
|
||||
self_: ClassLiteral<'db>,
|
||||
specialization: Option<Specialization<'db>>,
|
||||
) -> Result<Mro<'db>, MroError<'db>> {
|
||||
Ok(Mro::from_error(
|
||||
db,
|
||||
self_.apply_optional_specialization(db, specialization),
|
||||
))
|
||||
}
|
||||
|
||||
#[allow(clippy::ref_option, clippy::trivially_copy_pass_by_ref)]
|
||||
fn inheritance_cycle_recover<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_value: &Option<InheritanceCycle>,
|
||||
_count: u32,
|
||||
_self: ClassLiteral<'db>,
|
||||
_self: ClassLiteralType<'db>,
|
||||
) -> salsa::CycleRecoveryAction<Option<InheritanceCycle>> {
|
||||
salsa::CycleRecoveryAction::Iterate
|
||||
}
|
||||
|
||||
fn inheritance_cycle_initial<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_self: ClassLiteral<'db>,
|
||||
_self: ClassLiteralType<'db>,
|
||||
) -> Option<InheritanceCycle> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Representation of a class definition statement in the AST. This does not in itself represent a
|
||||
/// type, but is used as the inner data for several structs that *do* represent types.
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, salsa::Update)]
|
||||
pub struct Class<'db> {
|
||||
/// Name of the class at definition
|
||||
pub(crate) name: ast::name::Name,
|
||||
|
||||
pub(crate) body_scope: ScopeId<'db>,
|
||||
|
||||
pub(crate) known: Option<KnownClass>,
|
||||
|
||||
pub(crate) dataclass_params: Option<DataclassParams>,
|
||||
pub(crate) dataclass_transformer_params: Option<DataclassTransformerParams>,
|
||||
}
|
||||
|
||||
impl<'db> Class<'db> {
|
||||
fn file(&self, db: &dyn Db) -> File {
|
||||
self.body_scope.file(db)
|
||||
}
|
||||
|
||||
/// Return the original [`ast::StmtClassDef`] node associated with this class
|
||||
///
|
||||
/// ## Note
|
||||
/// Only call this function from queries in the same file or your
|
||||
/// query depends on the AST of another file (bad!).
|
||||
fn node(&self, db: &'db dyn Db) -> &'db ast::StmtClassDef {
|
||||
self.body_scope.node(db).expect_class()
|
||||
}
|
||||
|
||||
fn definition(&self, db: &'db dyn Db) -> Definition<'db> {
|
||||
let index = semantic_index(db, self.body_scope.file(db));
|
||||
index.expect_single_definition(self.body_scope.node(db).expect_class())
|
||||
}
|
||||
}
|
||||
|
||||
/// A [`Class`] that is not generic.
|
||||
#[salsa::interned(debug)]
|
||||
pub struct NonGenericClass<'db> {
|
||||
#[return_ref]
|
||||
pub(crate) class: Class<'db>,
|
||||
}
|
||||
|
||||
impl<'db> From<NonGenericClass<'db>> for Type<'db> {
|
||||
fn from(class: NonGenericClass<'db>) -> Type<'db> {
|
||||
Type::ClassLiteral(ClassLiteralType::NonGeneric(class))
|
||||
}
|
||||
}
|
||||
|
||||
/// A [`Class`] that is generic.
|
||||
#[salsa::interned(debug)]
|
||||
pub struct GenericClass<'db> {
|
||||
#[return_ref]
|
||||
pub(crate) class: Class<'db>,
|
||||
pub(crate) generic_context: GenericContext<'db>,
|
||||
}
|
||||
|
||||
impl<'db> From<GenericClass<'db>> for Type<'db> {
|
||||
fn from(class: GenericClass<'db>) -> Type<'db> {
|
||||
Type::ClassLiteral(ClassLiteralType::Generic(class))
|
||||
}
|
||||
}
|
||||
|
||||
/// A specialization of a generic class with a particular assignment of types to typevars.
|
||||
#[salsa::interned(debug)]
|
||||
pub struct GenericAlias<'db> {
|
||||
pub(crate) origin: ClassLiteral<'db>,
|
||||
pub(crate) origin: GenericClass<'db>,
|
||||
pub(crate) specialization: Specialization<'db>,
|
||||
}
|
||||
|
||||
impl<'db> GenericAlias<'db> {
|
||||
pub(crate) fn definition(self, db: &'db dyn Db) -> Definition<'db> {
|
||||
self.origin(db).definition(db)
|
||||
self.origin(db).class(db).definition(db)
|
||||
}
|
||||
|
||||
pub(crate) fn class_literal(self, db: &'db dyn Db) -> ClassLiteralType<'db> {
|
||||
ClassLiteralType::Generic(self.origin(db))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,47 +170,44 @@ impl<'db> From<GenericAlias<'db>> for Type<'db> {
|
||||
Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, salsa::Supertype, salsa::Update,
|
||||
)]
|
||||
pub enum ClassType<'db> {
|
||||
NonGeneric(ClassLiteral<'db>),
|
||||
NonGeneric(NonGenericClass<'db>),
|
||||
Generic(GenericAlias<'db>),
|
||||
}
|
||||
|
||||
#[salsa::tracked]
|
||||
impl<'db> ClassType<'db> {
|
||||
fn class(self, db: &'db dyn Db) -> &'db Class<'db> {
|
||||
match self {
|
||||
Self::NonGeneric(non_generic) => non_generic.class(db),
|
||||
Self::Generic(generic) => generic.origin(db).class(db),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the class literal and specialization for this class. For a non-generic class, this
|
||||
/// is the class itself. For a generic alias, this is the alias's origin.
|
||||
pub(crate) fn class_literal(
|
||||
self,
|
||||
db: &'db dyn Db,
|
||||
) -> (ClassLiteral<'db>, Option<Specialization<'db>>) {
|
||||
) -> (ClassLiteralType<'db>, Option<Specialization<'db>>) {
|
||||
match self {
|
||||
Self::NonGeneric(non_generic) => (non_generic, None),
|
||||
Self::Generic(generic) => (generic.origin(db), Some(generic.specialization(db))),
|
||||
Self::NonGeneric(non_generic) => (ClassLiteralType::NonGeneric(non_generic), None),
|
||||
Self::Generic(generic) => (
|
||||
ClassLiteralType::Generic(generic.origin(db)),
|
||||
Some(generic.specialization(db)),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn is_protocol(self, db: &'db dyn Db) -> bool {
|
||||
// `str` requires some special-casing here because in order to construct the type "instance of `str`"
|
||||
// we must evaluate a call to `TypeVar.__new__`, and `TypeVar.__new__` has a parameter annotated with `str`,
|
||||
// causing a Salsa cycle.
|
||||
if self.is_known(db, KnownClass::Str) {
|
||||
return false;
|
||||
}
|
||||
self.class_literal(db).0.is_protocol(db)
|
||||
}
|
||||
|
||||
pub(crate) fn name(self, db: &'db dyn Db) -> &'db ast::name::Name {
|
||||
let (class_literal, _) = self.class_literal(db);
|
||||
class_literal.name(db)
|
||||
&self.class(db).name
|
||||
}
|
||||
|
||||
pub(crate) fn known(self, db: &'db dyn Db) -> Option<KnownClass> {
|
||||
let (class_literal, _) = self.class_literal(db);
|
||||
class_literal.known(db)
|
||||
self.class(db).known
|
||||
}
|
||||
|
||||
pub(crate) fn definition(self, db: &'db dyn Db) -> Definition<'db> {
|
||||
let (class_literal, _) = self.class_literal(db);
|
||||
class_literal.definition(db)
|
||||
self.class(db).definition(db)
|
||||
}
|
||||
|
||||
fn specialize_type(self, db: &'db dyn Db, ty: Type<'db>) -> Type<'db> {
|
||||
@@ -178,7 +219,7 @@ impl<'db> ClassType<'db> {
|
||||
|
||||
/// Return `true` if this class represents `known_class`
|
||||
pub(crate) fn is_known(self, db: &'db dyn Db, known_class: KnownClass) -> bool {
|
||||
self.known(db) == Some(known_class)
|
||||
self.class(db).known == Some(known_class)
|
||||
}
|
||||
|
||||
/// Return `true` if this class represents the builtin class `object`
|
||||
@@ -190,7 +231,7 @@ impl<'db> ClassType<'db> {
|
||||
///
|
||||
/// If the MRO could not be accurately resolved, this method falls back to iterating
|
||||
/// over an MRO that has the class directly inheriting from `Unknown`. Use
|
||||
/// [`ClassLiteral::try_mro`] if you need to distinguish between the success and failure
|
||||
/// [`ClassLiteralType::try_mro`] if you need to distinguish between the success and failure
|
||||
/// cases rather than simply iterating over the inferred resolution order for the class.
|
||||
///
|
||||
/// [method resolution order]: https://docs.python.org/3/glossary.html#term-method-resolution-order
|
||||
@@ -398,40 +439,47 @@ impl<'db> From<ClassType<'db>> for Type<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Representation of a class definition statement in the AST: either a non-generic class, or a
|
||||
/// generic class that has not been specialized.
|
||||
///
|
||||
/// This does not in itself represent a type, but can be transformed into a [`ClassType`] that
|
||||
/// does. (For generic classes, this requires specializing its generic context.)
|
||||
#[salsa::interned(debug)]
|
||||
pub struct ClassLiteral<'db> {
|
||||
/// Name of the class at definition
|
||||
#[return_ref]
|
||||
pub(crate) name: ast::name::Name,
|
||||
|
||||
pub(crate) body_scope: ScopeId<'db>,
|
||||
|
||||
pub(crate) known: Option<KnownClass>,
|
||||
|
||||
pub(crate) dataclass_params: Option<DataclassParams>,
|
||||
pub(crate) dataclass_transformer_params: Option<DataclassTransformerParams>,
|
||||
/// Represents a single class object at runtime, which might be a non-generic class, or a generic
|
||||
/// class that has not been specialized.
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, salsa::Supertype, salsa::Update,
|
||||
)]
|
||||
pub enum ClassLiteralType<'db> {
|
||||
NonGeneric(NonGenericClass<'db>),
|
||||
Generic(GenericClass<'db>),
|
||||
}
|
||||
|
||||
#[salsa::tracked]
|
||||
impl<'db> ClassLiteral<'db> {
|
||||
/// Return `true` if this class represents `known_class`
|
||||
pub(crate) fn is_known(self, db: &'db dyn Db, known_class: KnownClass) -> bool {
|
||||
self.known(db) == Some(known_class)
|
||||
impl<'db> ClassLiteralType<'db> {
|
||||
fn class(self, db: &'db dyn Db) -> &'db Class<'db> {
|
||||
match self {
|
||||
Self::NonGeneric(non_generic) => non_generic.class(db),
|
||||
Self::Generic(generic) => generic.class(db),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn name(self, db: &'db dyn Db) -> &'db ast::name::Name {
|
||||
&self.class(db).name
|
||||
}
|
||||
|
||||
pub(crate) fn known(self, db: &'db dyn Db) -> Option<KnownClass> {
|
||||
self.class(db).known
|
||||
}
|
||||
|
||||
pub(crate) fn dataclass_params(self, db: &'db dyn Db) -> Option<DataclassParams> {
|
||||
self.class(db).dataclass_params
|
||||
}
|
||||
|
||||
/// Return `true` if this class represents `known_class`
|
||||
pub(crate) fn is_known(self, db: &'db dyn Db, known_class: KnownClass) -> bool {
|
||||
self.class(db).known == Some(known_class)
|
||||
}
|
||||
|
||||
#[salsa::tracked]
|
||||
pub(crate) fn generic_context(self, db: &'db dyn Db) -> Option<GenericContext<'db>> {
|
||||
let scope = self.body_scope(db);
|
||||
let class_def_node = scope.node(db).expect_class();
|
||||
class_def_node.type_params.as_ref().map(|type_params| {
|
||||
let index = semantic_index(db, scope.file(db));
|
||||
GenericContext::from_type_params(db, index, type_params)
|
||||
})
|
||||
match self {
|
||||
Self::NonGeneric(_) => None,
|
||||
Self::Generic(generic) => Some(generic.generic_context(db)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return `true` if this class represents the builtin class `object`
|
||||
@@ -439,23 +487,12 @@ impl<'db> ClassLiteral<'db> {
|
||||
self.is_known(db, KnownClass::Object)
|
||||
}
|
||||
|
||||
fn file(self, db: &dyn Db) -> File {
|
||||
self.body_scope(db).file(db)
|
||||
}
|
||||
|
||||
/// Return the original [`ast::StmtClassDef`] node associated with this class
|
||||
///
|
||||
/// ## Note
|
||||
/// Only call this function from queries in the same file or your
|
||||
/// query depends on the AST of another file (bad!).
|
||||
fn node(self, db: &'db dyn Db) -> &'db ast::StmtClassDef {
|
||||
self.body_scope(db).node(db).expect_class()
|
||||
pub(crate) fn body_scope(self, db: &'db dyn Db) -> ScopeId<'db> {
|
||||
self.class(db).body_scope
|
||||
}
|
||||
|
||||
pub(crate) fn definition(self, db: &'db dyn Db) -> Definition<'db> {
|
||||
let body_scope = self.body_scope(db);
|
||||
let index = semantic_index(db, body_scope.file(db));
|
||||
index.expect_single_definition(body_scope.node(db).expect_class())
|
||||
self.class(db).definition(db)
|
||||
}
|
||||
|
||||
pub(crate) fn apply_optional_specialization(
|
||||
@@ -463,14 +500,14 @@ impl<'db> ClassLiteral<'db> {
|
||||
db: &'db dyn Db,
|
||||
specialization: Option<Specialization<'db>>,
|
||||
) -> ClassType<'db> {
|
||||
match (self.generic_context(db), specialization) {
|
||||
(None, _) => ClassType::NonGeneric(self),
|
||||
(Some(generic_context), None) => {
|
||||
let specialization = generic_context.default_specialization(db);
|
||||
ClassType::Generic(GenericAlias::new(db, self, specialization))
|
||||
match (self, specialization) {
|
||||
(Self::NonGeneric(non_generic), _) => ClassType::NonGeneric(non_generic),
|
||||
(Self::Generic(generic), None) => {
|
||||
let specialization = generic.generic_context(db).default_specialization(db);
|
||||
ClassType::Generic(GenericAlias::new(db, generic, specialization))
|
||||
}
|
||||
(Some(_), Some(specialization)) => {
|
||||
ClassType::Generic(GenericAlias::new(db, self, specialization))
|
||||
(Self::Generic(generic), Some(specialization)) => {
|
||||
ClassType::Generic(GenericAlias::new(db, generic, specialization))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,11 +516,11 @@ impl<'db> ClassLiteral<'db> {
|
||||
/// returned unchanged. For a non-specialized generic class, we return a generic alias that
|
||||
/// applies the default specialization to the class's typevars.
|
||||
pub(crate) fn default_specialization(self, db: &'db dyn Db) -> ClassType<'db> {
|
||||
match self.generic_context(db) {
|
||||
None => ClassType::NonGeneric(self),
|
||||
Some(generic_context) => {
|
||||
let specialization = generic_context.default_specialization(db);
|
||||
ClassType::Generic(GenericAlias::new(db, self, specialization))
|
||||
match self {
|
||||
Self::NonGeneric(non_generic) => ClassType::NonGeneric(non_generic),
|
||||
Self::Generic(generic) => {
|
||||
let specialization = generic.generic_context(db).default_specialization(db);
|
||||
ClassType::Generic(GenericAlias::new(db, generic, specialization))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -492,11 +529,11 @@ impl<'db> ClassLiteral<'db> {
|
||||
/// returned unchanged. For a non-specialized generic class, we return a generic alias that
|
||||
/// maps each of the class's typevars to `Unknown`.
|
||||
pub(crate) fn unknown_specialization(self, db: &'db dyn Db) -> ClassType<'db> {
|
||||
match self.generic_context(db) {
|
||||
None => ClassType::NonGeneric(self),
|
||||
Some(generic_context) => {
|
||||
let specialization = generic_context.unknown_specialization(db);
|
||||
ClassType::Generic(GenericAlias::new(db, self, specialization))
|
||||
match self {
|
||||
Self::NonGeneric(non_generic) => ClassType::NonGeneric(non_generic),
|
||||
Self::Generic(generic) => {
|
||||
let specialization = generic.generic_context(db).unknown_specialization(db);
|
||||
ClassType::Generic(GenericAlias::new(db, generic, specialization))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -529,11 +566,12 @@ impl<'db> ClassLiteral<'db> {
|
||||
|
||||
#[salsa::tracked(return_ref, cycle_fn=explicit_bases_cycle_recover, cycle_initial=explicit_bases_cycle_initial)]
|
||||
fn explicit_bases_query(self, db: &'db dyn Db) -> Box<[Type<'db>]> {
|
||||
tracing::trace!("ClassLiteral::explicit_bases_query: {}", self.name(db));
|
||||
let class = self.class(db);
|
||||
tracing::trace!("ClassLiteralType::explicit_bases_query: {}", class.name);
|
||||
|
||||
let class_stmt = self.node(db);
|
||||
let class_stmt = class.node(db);
|
||||
let class_definition =
|
||||
semantic_index(db, self.file(db)).expect_single_definition(class_stmt);
|
||||
semantic_index(db, class.file(db)).expect_single_definition(class_stmt);
|
||||
|
||||
class_stmt
|
||||
.bases()
|
||||
@@ -556,15 +594,16 @@ impl<'db> ClassLiteral<'db> {
|
||||
/// Return the types of the decorators on this class
|
||||
#[salsa::tracked(return_ref)]
|
||||
fn decorators(self, db: &'db dyn Db) -> Box<[Type<'db>]> {
|
||||
tracing::trace!("ClassLiteral::decorators: {}", self.name(db));
|
||||
let class = self.class(db);
|
||||
tracing::trace!("ClassLiteralType::decorators: {}", class.name);
|
||||
|
||||
let class_stmt = self.node(db);
|
||||
let class_stmt = class.node(db);
|
||||
if class_stmt.decorator_list.is_empty() {
|
||||
return Box::new([]);
|
||||
}
|
||||
|
||||
let class_definition =
|
||||
semantic_index(db, self.file(db)).expect_single_definition(class_stmt);
|
||||
semantic_index(db, class.file(db)).expect_single_definition(class_stmt);
|
||||
|
||||
class_stmt
|
||||
.decorator_list
|
||||
@@ -600,13 +639,14 @@ impl<'db> ClassLiteral<'db> {
|
||||
/// attribute on a class at runtime.
|
||||
///
|
||||
/// [method resolution order]: https://docs.python.org/3/glossary.html#term-method-resolution-order
|
||||
#[salsa::tracked(return_ref, cycle_fn=try_mro_cycle_recover, cycle_initial=try_mro_cycle_initial)]
|
||||
#[salsa::tracked(return_ref)]
|
||||
pub(super) fn try_mro(
|
||||
self,
|
||||
db: &'db dyn Db,
|
||||
specialization: Option<Specialization<'db>>,
|
||||
) -> Result<Mro<'db>, MroError<'db>> {
|
||||
tracing::trace!("ClassLiteral::try_mro: {}", self.name(db));
|
||||
let class = self.class(db);
|
||||
tracing::trace!("ClassLiteralType::try_mro: {}", class.name);
|
||||
Mro::of_class(db, self, specialization)
|
||||
}
|
||||
|
||||
@@ -614,7 +654,7 @@ impl<'db> ClassLiteral<'db> {
|
||||
///
|
||||
/// If the MRO could not be accurately resolved, this method falls back to iterating
|
||||
/// over an MRO that has the class directly inheriting from `Unknown`. Use
|
||||
/// [`ClassLiteral::try_mro`] if you need to distinguish between the success and failure
|
||||
/// [`ClassLiteralType::try_mro`] if you need to distinguish between the success and failure
|
||||
/// cases rather than simply iterating over the inferred resolution order for the class.
|
||||
///
|
||||
/// [method resolution order]: https://docs.python.org/3/glossary.html#term-method-resolution-order
|
||||
@@ -645,14 +685,15 @@ impl<'db> ClassLiteral<'db> {
|
||||
/// Only call this function from queries in the same file or your
|
||||
/// query depends on the AST of another file (bad!).
|
||||
fn explicit_metaclass(self, db: &'db dyn Db) -> Option<Type<'db>> {
|
||||
let class_stmt = self.node(db);
|
||||
let class = self.class(db);
|
||||
let class_stmt = class.node(db);
|
||||
let metaclass_node = &class_stmt
|
||||
.arguments
|
||||
.as_ref()?
|
||||
.find_keyword("metaclass")?
|
||||
.value;
|
||||
|
||||
let class_definition = self.definition(db);
|
||||
let class_definition = class.definition(db);
|
||||
|
||||
Some(definition_expression_type(
|
||||
db,
|
||||
@@ -682,7 +723,8 @@ impl<'db> ClassLiteral<'db> {
|
||||
self,
|
||||
db: &'db dyn Db,
|
||||
) -> Result<(Type<'db>, Option<DataclassTransformerParams>), MetaclassError<'db>> {
|
||||
tracing::trace!("ClassLiteral::try_metaclass: {}", self.name(db));
|
||||
let class = self.class(db);
|
||||
tracing::trace!("ClassLiteralType::try_metaclass: {}", class.name);
|
||||
|
||||
// Identify the class's own metaclass (or take the first base class's metaclass).
|
||||
let mut base_classes = self.fully_static_explicit_bases(db).peekable();
|
||||
@@ -710,7 +752,7 @@ impl<'db> ClassLiteral<'db> {
|
||||
explicit_metaclass_of: class_metaclass_was_from,
|
||||
}
|
||||
} else {
|
||||
let name = Type::string_literal(db, self.name(db));
|
||||
let name = Type::string_literal(db, &class.name);
|
||||
let bases = TupleType::from_elements(db, self.explicit_bases(db));
|
||||
// TODO: Should be `dict[str, Any]`
|
||||
let namespace = KnownClass::Dict.to_instance(db);
|
||||
@@ -773,10 +815,9 @@ impl<'db> ClassLiteral<'db> {
|
||||
});
|
||||
}
|
||||
|
||||
let (metaclass_literal, _) = candidate.metaclass.class_literal(db);
|
||||
Ok((
|
||||
candidate.metaclass.into(),
|
||||
metaclass_literal.dataclass_transformer_params(db),
|
||||
candidate.metaclass.class(db).dataclass_transformer_params,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -943,7 +984,7 @@ impl<'db> ClassLiteral<'db> {
|
||||
/// or those marked as ClassVars are considered.
|
||||
///
|
||||
/// Returns [`Symbol::Unbound`] if `name` cannot be found in this class's scope
|
||||
/// directly. Use [`ClassLiteral::class_member`] if you require a method that will
|
||||
/// directly. Use [`ClassLiteralType::class_member`] if you require a method that will
|
||||
/// traverse through the MRO until it finds the member.
|
||||
pub(super) fn own_class_member(
|
||||
self,
|
||||
@@ -964,14 +1005,14 @@ impl<'db> ClassLiteral<'db> {
|
||||
// to any method with a `@classmethod` decorator. (`__init__` would remain a special
|
||||
// case, since it's an _instance_ method where we don't yet know the generic class's
|
||||
// specialization.)
|
||||
match (self.generic_context(db), ty, specialization, name) {
|
||||
match (self, ty, specialization, name) {
|
||||
(
|
||||
Some(generic_context),
|
||||
ClassLiteralType::Generic(origin),
|
||||
Type::FunctionLiteral(function),
|
||||
Some(_),
|
||||
"__new__" | "__init__",
|
||||
) => Type::FunctionLiteral(
|
||||
function.with_inherited_generic_context(db, generic_context),
|
||||
function.with_inherited_generic_context(db, origin.generic_context(db)),
|
||||
),
|
||||
_ => ty,
|
||||
}
|
||||
@@ -1086,7 +1127,6 @@ impl<'db> ClassLiteral<'db> {
|
||||
Parameters::new([Parameter::positional_or_keyword(Name::new_static("other"))
|
||||
// TODO: could be `Self`.
|
||||
.with_annotated_type(Type::instance(
|
||||
db,
|
||||
self.apply_optional_specialization(db, specialization),
|
||||
))]),
|
||||
Some(KnownClass::Bool.to_instance(db)),
|
||||
@@ -1107,7 +1147,7 @@ impl<'db> ClassLiteral<'db> {
|
||||
|
||||
/// Returns a list of all annotated attributes defined in this class, or any of its superclasses.
|
||||
///
|
||||
/// See [`ClassLiteral::own_dataclass_fields`] for more details.
|
||||
/// See [`ClassLiteralType::own_dataclass_fields`] for more details.
|
||||
fn dataclass_fields(
|
||||
self,
|
||||
db: &'db dyn Db,
|
||||
@@ -1628,15 +1668,15 @@ impl<'db> ClassLiteral<'db> {
|
||||
/// Also, populates `visited_classes` with all base classes of `self`.
|
||||
fn is_cyclically_defined_recursive<'db>(
|
||||
db: &'db dyn Db,
|
||||
class: ClassLiteral<'db>,
|
||||
classes_on_stack: &mut IndexSet<ClassLiteral<'db>>,
|
||||
visited_classes: &mut IndexSet<ClassLiteral<'db>>,
|
||||
class: ClassLiteralType<'db>,
|
||||
classes_on_stack: &mut IndexSet<ClassLiteralType<'db>>,
|
||||
visited_classes: &mut IndexSet<ClassLiteralType<'db>>,
|
||||
) -> bool {
|
||||
let mut result = false;
|
||||
for explicit_base in class.explicit_bases(db) {
|
||||
let explicit_base_class_literal = match explicit_base {
|
||||
Type::ClassLiteral(class_literal) => *class_literal,
|
||||
Type::GenericAlias(generic_alias) => generic_alias.origin(db),
|
||||
Type::GenericAlias(generic_alias) => generic_alias.class_literal(db),
|
||||
_ => continue,
|
||||
};
|
||||
if !classes_on_stack.insert(explicit_base_class_literal) {
|
||||
@@ -1697,15 +1737,18 @@ impl<'db> ClassLiteral<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> From<ClassLiteral<'db>> for Type<'db> {
|
||||
fn from(class: ClassLiteral<'db>) -> Type<'db> {
|
||||
Type::ClassLiteral(class)
|
||||
impl<'db> From<ClassLiteralType<'db>> for Type<'db> {
|
||||
fn from(class: ClassLiteralType<'db>) -> Type<'db> {
|
||||
match class {
|
||||
ClassLiteralType::NonGeneric(non_generic) => non_generic.into(),
|
||||
ClassLiteralType::Generic(generic) => generic.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Representation of a single `Protocol` class definition.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub(super) struct ProtocolClassLiteral<'db>(ClassLiteral<'db>);
|
||||
pub(super) struct ProtocolClassLiteral<'db>(ClassLiteralType<'db>);
|
||||
|
||||
impl<'db> ProtocolClassLiteral<'db> {
|
||||
/// Returns the protocol members of this class.
|
||||
@@ -1722,7 +1765,7 @@ impl<'db> ProtocolClassLiteral<'db> {
|
||||
/// It is illegal for a protocol class to have any instance attributes that are not declared
|
||||
/// in the protocol's class body. If any are assigned to, they are not taken into account in
|
||||
/// the protocol's list of members.
|
||||
pub(super) fn protocol_members(self, db: &'db dyn Db) -> FxOrderSet<Name> {
|
||||
pub(super) fn protocol_members(self, db: &'db dyn Db) -> &'db ordermap::set::Slice<Name> {
|
||||
/// The list of excluded members is subject to change between Python versions,
|
||||
/// especially for dunders, but it probably doesn't matter *too* much if this
|
||||
/// list goes out of date. It's up to date as of Python commit 87b1ea016b1454b1e83b9113fa9435849b7743aa
|
||||
@@ -1759,52 +1802,58 @@ impl<'db> ProtocolClassLiteral<'db> {
|
||||
)
|
||||
}
|
||||
|
||||
let mut members = FxOrderSet::default();
|
||||
#[salsa::tracked(return_ref)]
|
||||
fn cached_protocol_members<'db>(
|
||||
db: &'db dyn Db,
|
||||
class: ClassLiteralType<'db>,
|
||||
) -> Box<ordermap::set::Slice<Name>> {
|
||||
let mut members = FxOrderSet::default();
|
||||
|
||||
for parent_protocol in self
|
||||
.iter_mro(db, None)
|
||||
.filter_map(ClassBase::into_class)
|
||||
.filter_map(|class| class.class_literal(db).0.into_protocol_class(db))
|
||||
{
|
||||
let parent_scope = parent_protocol.body_scope(db);
|
||||
let use_def_map = use_def_map(db, parent_scope);
|
||||
let symbol_table = symbol_table(db, parent_scope);
|
||||
for parent_protocol in class
|
||||
.iter_mro(db, None)
|
||||
.filter_map(ClassBase::into_class)
|
||||
.filter_map(|class| class.class_literal(db).0.into_protocol_class(db))
|
||||
{
|
||||
let parent_scope = parent_protocol.body_scope(db);
|
||||
let use_def_map = use_def_map(db, parent_scope);
|
||||
let symbol_table = symbol_table(db, parent_scope);
|
||||
|
||||
members.extend(
|
||||
use_def_map
|
||||
.all_public_declarations()
|
||||
.flat_map(|(symbol_id, declarations)| {
|
||||
symbol_from_declarations(db, declarations).map(|symbol| (symbol_id, symbol))
|
||||
})
|
||||
.filter_map(|(symbol_id, symbol)| {
|
||||
symbol.symbol.ignore_possibly_unbound().map(|_| symbol_id)
|
||||
})
|
||||
// Bindings in the class body that are not declared in the class body
|
||||
// are not valid protocol members, and we plan to emit diagnostics for them
|
||||
// elsewhere. Invalid or not, however, it's important that we still consider
|
||||
// them to be protocol members. The implementation of `issubclass()` and
|
||||
// `isinstance()` for runtime-checkable protocols considers them to be protocol
|
||||
// members at runtime, and it's important that we accurately understand
|
||||
// type narrowing that uses `isinstance()` or `issubclass()` with
|
||||
// runtime-checkable protocols.
|
||||
.chain(
|
||||
use_def_map
|
||||
.all_public_bindings()
|
||||
.filter_map(|(symbol_id, bindings)| {
|
||||
members.extend(
|
||||
use_def_map
|
||||
.all_public_declarations()
|
||||
.flat_map(|(symbol_id, declarations)| {
|
||||
symbol_from_declarations(db, declarations)
|
||||
.map(|symbol| (symbol_id, symbol))
|
||||
})
|
||||
.filter_map(|(symbol_id, symbol)| {
|
||||
symbol.symbol.ignore_possibly_unbound().map(|_| symbol_id)
|
||||
})
|
||||
// Bindings in the class body that are not declared in the class body
|
||||
// are not valid protocol members, and we plan to emit diagnostics for them
|
||||
// elsewhere. Invalid or not, however, it's important that we still consider
|
||||
// them to be protocol members. The implementation of `issubclass()` and
|
||||
// `isinstance()` for runtime-checkable protocols considers them to be protocol
|
||||
// members at runtime, and it's important that we accurately understand
|
||||
// type narrowing that uses `isinstance()` or `issubclass()` with
|
||||
// runtime-checkable protocols.
|
||||
.chain(use_def_map.all_public_bindings().filter_map(
|
||||
|(symbol_id, bindings)| {
|
||||
symbol_from_bindings(db, bindings)
|
||||
.ignore_possibly_unbound()
|
||||
.map(|_| symbol_id)
|
||||
}),
|
||||
)
|
||||
.map(|symbol_id| symbol_table.symbol(symbol_id).name())
|
||||
.filter(|name| !excluded_from_proto_members(name))
|
||||
.cloned(),
|
||||
);
|
||||
},
|
||||
))
|
||||
.map(|symbol_id| symbol_table.symbol(symbol_id).name())
|
||||
.filter(|name| !excluded_from_proto_members(name))
|
||||
.cloned(),
|
||||
);
|
||||
}
|
||||
|
||||
members.sort();
|
||||
members.into_boxed_slice()
|
||||
}
|
||||
|
||||
members.sort();
|
||||
members.shrink_to_fit();
|
||||
members
|
||||
cached_protocol_members(db, *self)
|
||||
}
|
||||
|
||||
pub(super) fn is_runtime_checkable(self, db: &'db dyn Db) -> bool {
|
||||
@@ -1814,7 +1863,7 @@ impl<'db> ProtocolClassLiteral<'db> {
|
||||
}
|
||||
|
||||
impl<'db> Deref for ProtocolClassLiteral<'db> {
|
||||
type Target = ClassLiteral<'db>;
|
||||
type Target = ClassLiteralType<'db>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
@@ -1845,7 +1894,7 @@ impl InheritanceCycle {
|
||||
/// Note: good candidates are any classes in `[crate::module_resolver::module::KnownModule]`
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(test, derive(strum_macros::EnumIter))]
|
||||
pub enum KnownClass {
|
||||
pub(crate) enum KnownClass {
|
||||
// To figure out where an stdlib symbol is defined, you can go into `crates/red_knot_vendored`
|
||||
// and grep for the symbol name in any `.pyi` file.
|
||||
|
||||
@@ -2095,7 +2144,7 @@ impl<'db> KnownClass {
|
||||
pub(crate) fn to_instance(self, db: &'db dyn Db) -> Type<'db> {
|
||||
self.to_class_literal(db)
|
||||
.to_class_type(db)
|
||||
.map(|class| Type::instance(db, class))
|
||||
.map(Type::instance)
|
||||
.unwrap_or_else(Type::unknown)
|
||||
}
|
||||
|
||||
@@ -2106,7 +2155,7 @@ impl<'db> KnownClass {
|
||||
pub(crate) fn try_to_class_literal(
|
||||
self,
|
||||
db: &'db dyn Db,
|
||||
) -> Result<ClassLiteral<'db>, KnownClassLookupError<'db>> {
|
||||
) -> Result<ClassLiteralType<'db>, KnownClassLookupError<'db>> {
|
||||
let symbol = known_module_symbol(db, self.canonical_module(db), self.name(db)).symbol;
|
||||
match symbol {
|
||||
Symbol::Type(Type::ClassLiteral(class_literal), Boundness::Bound) => Ok(class_literal),
|
||||
@@ -2512,7 +2561,9 @@ pub(crate) enum KnownClassLookupError<'db> {
|
||||
SymbolNotAClass { found_type: Type<'db> },
|
||||
/// There is a symbol by that name in the expected typeshed module,
|
||||
/// and it's a class definition, but it's possibly unbound.
|
||||
ClassPossiblyUnbound { class_literal: ClassLiteral<'db> },
|
||||
ClassPossiblyUnbound {
|
||||
class_literal: ClassLiteralType<'db>,
|
||||
},
|
||||
}
|
||||
|
||||
impl<'db> KnownClassLookupError<'db> {
|
||||
|
||||
@@ -78,14 +78,12 @@ impl<'db> ClassBase<'db> {
|
||||
Self::Class(literal.default_specialization(db))
|
||||
}),
|
||||
Type::GenericAlias(generic) => Some(Self::Class(ClassType::Generic(generic))),
|
||||
Type::NominalInstance(instance)
|
||||
if instance.class().is_known(db, KnownClass::GenericAlias) =>
|
||||
{
|
||||
Type::Instance(instance) if instance.class().is_known(db, KnownClass::GenericAlias) => {
|
||||
Self::try_from_type(db, todo_type!("GenericAlias instance"))
|
||||
}
|
||||
Type::Union(_) => None, // TODO -- forces consideration of multiple possible MROs?
|
||||
Type::Intersection(_) => None, // TODO -- probably incorrect?
|
||||
Type::NominalInstance(_) => None, // TODO -- handle `__mro_entries__`?
|
||||
Type::Instance(_) => None, // TODO -- handle `__mro_entries__`?
|
||||
Type::PropertyInstance(_) => None,
|
||||
Type::Never
|
||||
| Type::BooleanLiteral(_)
|
||||
@@ -106,7 +104,6 @@ impl<'db> ClassBase<'db> {
|
||||
| Type::SubclassOf(_)
|
||||
| Type::TypeVar(_)
|
||||
| Type::BoundSuper(_)
|
||||
| Type::ProtocolInstance(_)
|
||||
| Type::AlwaysFalsy
|
||||
| Type::AlwaysTruthy => None,
|
||||
Type::KnownInstance(known_instance) => match known_instance {
|
||||
@@ -172,7 +169,6 @@ impl<'db> ClassBase<'db> {
|
||||
KnownInstanceType::OrderedDict => {
|
||||
Self::try_from_type(db, KnownClass::OrderedDict.to_class_literal(db))
|
||||
}
|
||||
KnownInstanceType::TypedDict => Self::try_from_type(db, todo_type!("TypedDict")),
|
||||
KnownInstanceType::Callable => {
|
||||
Self::try_from_type(db, todo_type!("Support for Callable as a base class"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::context::InferContext;
|
||||
use super::ClassLiteral;
|
||||
use super::ClassLiteralType;
|
||||
use crate::declare_lint;
|
||||
use crate::lint::{Level, LintRegistryBuilder, LintStatus};
|
||||
use crate::suppression::FileSuppressionId;
|
||||
@@ -1321,7 +1321,7 @@ pub(crate) fn report_invalid_arguments_to_annotated(
|
||||
pub(crate) fn report_bad_argument_to_get_protocol_members(
|
||||
context: &InferContext,
|
||||
call: &ast::ExprCall,
|
||||
class: ClassLiteral,
|
||||
class: ClassLiteralType,
|
||||
) {
|
||||
let Some(builder) = context.report_lint(&INVALID_ARGUMENT_TYPE, call) else {
|
||||
return;
|
||||
|
||||
@@ -6,7 +6,7 @@ use ruff_db::display::FormatterJoinExtension;
|
||||
use ruff_python_ast::str::{Quote, TripleQuotes};
|
||||
use ruff_python_literal::escape::AsciiEscape;
|
||||
|
||||
use crate::types::class::{ClassLiteral, ClassType, GenericAlias};
|
||||
use crate::types::class::{ClassType, GenericAlias, GenericClass};
|
||||
use crate::types::generics::{GenericContext, Specialization};
|
||||
use crate::types::signatures::{Parameter, Parameters, Signature};
|
||||
use crate::types::{
|
||||
@@ -17,7 +17,6 @@ use crate::types::{
|
||||
use crate::Db;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use super::instance::Protocol;
|
||||
use super::CallableType;
|
||||
|
||||
impl<'db> Type<'db> {
|
||||
@@ -74,32 +73,11 @@ impl Display for DisplayRepresentation<'_> {
|
||||
match self.ty {
|
||||
Type::Dynamic(dynamic) => dynamic.fmt(f),
|
||||
Type::Never => f.write_str("Never"),
|
||||
Type::NominalInstance(instance) => {
|
||||
match (instance.class(), instance.class().known(self.db)) {
|
||||
(_, Some(KnownClass::NoneType)) => f.write_str("None"),
|
||||
(_, Some(KnownClass::NoDefaultType)) => f.write_str("NoDefault"),
|
||||
(ClassType::NonGeneric(class), _) => f.write_str(class.name(self.db)),
|
||||
(ClassType::Generic(alias), _) => write!(f, "{}", alias.display(self.db)),
|
||||
}
|
||||
}
|
||||
Type::ProtocolInstance(protocol) => match protocol.inner() {
|
||||
Protocol::FromClass(ClassType::NonGeneric(class)) => {
|
||||
f.write_str(class.name(self.db))
|
||||
}
|
||||
Protocol::FromClass(ClassType::Generic(alias)) => alias.display(self.db).fmt(f),
|
||||
Protocol::Synthesized(synthetic) => {
|
||||
f.write_str("<Protocol with members ")?;
|
||||
let member_list = synthetic.members(self.db);
|
||||
let num_members = member_list.len();
|
||||
for (i, member) in member_list.iter().enumerate() {
|
||||
let is_last = i == num_members - 1;
|
||||
write!(f, "'{member}'")?;
|
||||
if !is_last {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
}
|
||||
f.write_char('>')
|
||||
}
|
||||
Type::Instance(instance) => match (instance.class(), instance.class().known(self.db)) {
|
||||
(_, Some(KnownClass::NoneType)) => f.write_str("None"),
|
||||
(_, Some(KnownClass::NoDefaultType)) => f.write_str("NoDefault"),
|
||||
(ClassType::NonGeneric(class), _) => f.write_str(&class.class(self.db).name),
|
||||
(ClassType::Generic(alias), _) => write!(f, "{}", alias.display(self.db)),
|
||||
},
|
||||
Type::PropertyInstance(_) => f.write_str("property"),
|
||||
Type::ModuleLiteral(module) => {
|
||||
@@ -294,7 +272,7 @@ impl<'db> GenericAlias<'db> {
|
||||
}
|
||||
|
||||
pub(crate) struct DisplayGenericAlias<'db> {
|
||||
origin: ClassLiteral<'db>,
|
||||
origin: GenericClass<'db>,
|
||||
specialization: Specialization<'db>,
|
||||
db: &'db dyn Db,
|
||||
}
|
||||
@@ -304,7 +282,7 @@ impl Display for DisplayGenericAlias<'_> {
|
||||
write!(
|
||||
f,
|
||||
"{origin}{specialization}",
|
||||
origin = self.origin.name(self.db),
|
||||
origin = self.origin.class(self.db).name,
|
||||
specialization = self.specialization.display_short(self.db),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -81,13 +81,14 @@ use crate::types::generics::GenericContext;
|
||||
use crate::types::mro::MroErrorKind;
|
||||
use crate::types::unpacker::{UnpackResult, Unpacker};
|
||||
use crate::types::{
|
||||
binding_type, todo_type, CallDunderError, CallableSignature, CallableType, ClassLiteral,
|
||||
ClassType, DataclassParams, DynamicType, FunctionDecorators, FunctionType, GenericAlias,
|
||||
IntersectionBuilder, IntersectionType, KnownClass, KnownFunction, KnownInstanceType,
|
||||
MemberLookupPolicy, MetaclassCandidate, Parameter, ParameterForm, Parameters, Signature,
|
||||
Signatures, SliceLiteralType, StringLiteralType, SubclassOfType, Symbol, SymbolAndQualifiers,
|
||||
Truthiness, TupleType, Type, TypeAliasType, TypeAndQualifiers, TypeArrayDisplay,
|
||||
TypeQualifiers, TypeVarBoundOrConstraints, TypeVarInstance, UnionBuilder, UnionType,
|
||||
binding_type, todo_type, CallDunderError, CallableSignature, CallableType, Class,
|
||||
ClassLiteralType, ClassType, DataclassParams, DynamicType, FunctionDecorators, FunctionType,
|
||||
GenericAlias, GenericClass, IntersectionBuilder, IntersectionType, KnownClass, KnownFunction,
|
||||
KnownInstanceType, MemberLookupPolicy, MetaclassCandidate, NonGenericClass, Parameter,
|
||||
ParameterForm, Parameters, Signature, Signatures, SliceLiteralType, StringLiteralType,
|
||||
SubclassOfType, Symbol, SymbolAndQualifiers, Truthiness, TupleType, Type, TypeAliasType,
|
||||
TypeAndQualifiers, TypeArrayDisplay, TypeQualifiers, TypeVarBoundOrConstraints,
|
||||
TypeVarInstance, UnionBuilder, UnionType,
|
||||
};
|
||||
use crate::unpack::{Unpack, UnpackPosition};
|
||||
use crate::util::subscript::{PyIndex, PySlice};
|
||||
@@ -1064,7 +1065,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
) -> bool {
|
||||
match left {
|
||||
Type::BooleanLiteral(_) | Type::IntLiteral(_) => {}
|
||||
Type::NominalInstance(instance)
|
||||
Type::Instance(instance)
|
||||
if matches!(
|
||||
instance.class().known(self.db()),
|
||||
Some(KnownClass::Float | KnownClass::Int | KnownClass::Bool)
|
||||
@@ -1832,6 +1833,10 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
let generic_context = type_params.as_ref().map(|type_params| {
|
||||
GenericContext::from_type_params(self.db(), self.index, type_params)
|
||||
});
|
||||
|
||||
let body_scope = self
|
||||
.index
|
||||
.node_scope(NodeWithScopeRef::Class(class_node))
|
||||
@@ -1839,14 +1844,20 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
|
||||
let maybe_known_class = KnownClass::try_from_file_and_name(self.db(), self.file(), name);
|
||||
|
||||
let class_ty = Type::from(ClassLiteral::new(
|
||||
self.db(),
|
||||
name.id.clone(),
|
||||
let class = Class {
|
||||
name: name.id.clone(),
|
||||
body_scope,
|
||||
maybe_known_class,
|
||||
known: maybe_known_class,
|
||||
dataclass_params,
|
||||
dataclass_transformer_params,
|
||||
));
|
||||
};
|
||||
let class_literal = match generic_context {
|
||||
Some(generic_context) => {
|
||||
ClassLiteralType::Generic(GenericClass::new(self.db(), class, generic_context))
|
||||
}
|
||||
None => ClassLiteralType::NonGeneric(NonGenericClass::new(self.db(), class)),
|
||||
};
|
||||
let class_ty = Type::from(class_literal);
|
||||
|
||||
self.add_declaration_with_binding(
|
||||
class_node.into(),
|
||||
@@ -2515,7 +2526,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
}
|
||||
|
||||
// Super instances do not allow attribute assignment
|
||||
Type::NominalInstance(instance) if instance.class().is_known(db, KnownClass::Super) => {
|
||||
Type::Instance(instance) if instance.class().is_known(db, KnownClass::Super) => {
|
||||
if emit_diagnostics {
|
||||
if let Some(builder) = self.context.report_lint(&INVALID_ASSIGNMENT, target) {
|
||||
builder.into_diagnostic(format_args!(
|
||||
@@ -2540,8 +2551,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
|
||||
Type::Dynamic(..) | Type::Never => true,
|
||||
|
||||
Type::NominalInstance(..)
|
||||
| Type::ProtocolInstance(_)
|
||||
Type::Instance(..)
|
||||
| Type::BooleanLiteral(..)
|
||||
| Type::IntLiteral(..)
|
||||
| Type::StringLiteral(..)
|
||||
@@ -3032,7 +3042,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
}
|
||||
|
||||
// Handle various singletons.
|
||||
if let Type::NominalInstance(instance) = declared_ty.inner_type() {
|
||||
if let Type::Instance(instance) = declared_ty.inner_type() {
|
||||
if instance
|
||||
.class()
|
||||
.is_known(self.db(), KnownClass::SpecialForm)
|
||||
@@ -5008,8 +5018,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
| Type::ClassLiteral(_)
|
||||
| Type::GenericAlias(_)
|
||||
| Type::SubclassOf(_)
|
||||
| Type::NominalInstance(_)
|
||||
| Type::ProtocolInstance(_)
|
||||
| Type::Instance(_)
|
||||
| Type::KnownInstance(_)
|
||||
| Type::PropertyInstance(_)
|
||||
| Type::Union(_)
|
||||
@@ -5289,8 +5298,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
| Type::ClassLiteral(_)
|
||||
| Type::GenericAlias(_)
|
||||
| Type::SubclassOf(_)
|
||||
| Type::NominalInstance(_)
|
||||
| Type::ProtocolInstance(_)
|
||||
| Type::Instance(_)
|
||||
| Type::KnownInstance(_)
|
||||
| Type::PropertyInstance(_)
|
||||
| Type::Intersection(_)
|
||||
@@ -5315,8 +5323,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
| Type::ClassLiteral(_)
|
||||
| Type::GenericAlias(_)
|
||||
| Type::SubclassOf(_)
|
||||
| Type::NominalInstance(_)
|
||||
| Type::ProtocolInstance(_)
|
||||
| Type::Instance(_)
|
||||
| Type::KnownInstance(_)
|
||||
| Type::PropertyInstance(_)
|
||||
| Type::Intersection(_)
|
||||
@@ -5749,13 +5756,13 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
right_ty: right,
|
||||
}),
|
||||
},
|
||||
(Type::IntLiteral(_), Type::NominalInstance(_)) => self.infer_binary_type_comparison(
|
||||
(Type::IntLiteral(_), Type::Instance(_)) => self.infer_binary_type_comparison(
|
||||
KnownClass::Int.to_instance(self.db()),
|
||||
op,
|
||||
right,
|
||||
range,
|
||||
),
|
||||
(Type::NominalInstance(_), Type::IntLiteral(_)) => self.infer_binary_type_comparison(
|
||||
(Type::Instance(_), Type::IntLiteral(_)) => self.infer_binary_type_comparison(
|
||||
left,
|
||||
op,
|
||||
KnownClass::Int.to_instance(self.db()),
|
||||
@@ -5881,7 +5888,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
KnownClass::Bytes.to_instance(self.db()),
|
||||
range,
|
||||
),
|
||||
(Type::Tuple(_), Type::NominalInstance(instance))
|
||||
(Type::Tuple(_), Type::Instance(instance))
|
||||
if instance
|
||||
.class()
|
||||
.is_known(self.db(), KnownClass::VersionInfo) =>
|
||||
@@ -5893,7 +5900,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
range,
|
||||
)
|
||||
}
|
||||
(Type::NominalInstance(instance), Type::Tuple(_))
|
||||
(Type::Instance(instance), Type::Tuple(_))
|
||||
if instance
|
||||
.class()
|
||||
.is_known(self.db(), KnownClass::VersionInfo) =>
|
||||
@@ -6211,15 +6218,8 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
// updating all of the subscript logic below to use custom callables for all of the _other_
|
||||
// special cases, too.
|
||||
let value_ty = self.infer_expression(value);
|
||||
if let Type::ClassLiteral(class) = value_ty {
|
||||
if let Some(generic_context) = class.generic_context(self.db()) {
|
||||
return self.infer_explicit_class_specialization(
|
||||
subscript,
|
||||
value_ty,
|
||||
class,
|
||||
generic_context,
|
||||
);
|
||||
}
|
||||
if let Type::ClassLiteral(ClassLiteralType::Generic(generic_class)) = value_ty {
|
||||
return self.infer_explicit_class_specialization(subscript, value_ty, generic_class);
|
||||
}
|
||||
|
||||
let slice_ty = self.infer_expression(slice);
|
||||
@@ -6230,8 +6230,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
&mut self,
|
||||
subscript: &ast::ExprSubscript,
|
||||
value_ty: Type<'db>,
|
||||
generic_class: ClassLiteral<'db>,
|
||||
generic_context: GenericContext<'db>,
|
||||
generic_class: GenericClass<'db>,
|
||||
) -> Type<'db> {
|
||||
let slice_node = subscript.slice.as_ref();
|
||||
let mut call_argument_types = match slice_node {
|
||||
@@ -6240,6 +6239,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
),
|
||||
_ => CallArgumentTypes::positional([self.infer_type_expression(slice_node)]),
|
||||
};
|
||||
let generic_context = generic_class.generic_context(self.db());
|
||||
let signatures = Signatures::single(CallableSignature::single(
|
||||
value_ty,
|
||||
generic_context.signature(self.db()),
|
||||
@@ -6279,7 +6279,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
) -> Type<'db> {
|
||||
match (value_ty, slice_ty) {
|
||||
(
|
||||
Type::NominalInstance(instance),
|
||||
Type::Instance(instance),
|
||||
Type::IntLiteral(_) | Type::BooleanLiteral(_) | Type::SliceLiteral(_),
|
||||
) if instance
|
||||
.class()
|
||||
@@ -6511,7 +6511,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
return KnownClass::GenericAlias.to_instance(self.db());
|
||||
}
|
||||
|
||||
if class.generic_context(self.db()).is_some() {
|
||||
if let ClassLiteralType::Generic(_) = class {
|
||||
// TODO: specialize the generic class using these explicit type
|
||||
// variable assignments
|
||||
return value_ty;
|
||||
@@ -6580,7 +6580,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
Err(_) => SliceArg::Unsupported,
|
||||
},
|
||||
Some(Type::BooleanLiteral(b)) => SliceArg::Arg(Some(i32::from(b))),
|
||||
Some(Type::NominalInstance(instance))
|
||||
Some(Type::Instance(instance))
|
||||
if instance.class().is_known(self.db(), KnownClass::NoneType) =>
|
||||
{
|
||||
SliceArg::Arg(None)
|
||||
@@ -7369,26 +7369,18 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
self.infer_type_expression(slice);
|
||||
value_ty
|
||||
}
|
||||
Type::ClassLiteral(class) => {
|
||||
match class.generic_context(self.db()) {
|
||||
Some(generic_context) => {
|
||||
let specialized_class = self.infer_explicit_class_specialization(
|
||||
subscript,
|
||||
value_ty,
|
||||
class,
|
||||
generic_context,
|
||||
);
|
||||
specialized_class
|
||||
.in_type_expression(self.db())
|
||||
.unwrap_or(Type::unknown())
|
||||
}
|
||||
None => {
|
||||
// TODO: Once we know that e.g. `list` is generic, emit a diagnostic if you try to
|
||||
// specialize a non-generic class.
|
||||
self.infer_type_expression(slice);
|
||||
todo_type!("specialized non-generic class")
|
||||
}
|
||||
}
|
||||
Type::ClassLiteral(ClassLiteralType::Generic(generic_class)) => {
|
||||
let specialized_class =
|
||||
self.infer_explicit_class_specialization(subscript, value_ty, generic_class);
|
||||
specialized_class
|
||||
.in_type_expression(self.db())
|
||||
.unwrap_or(Type::unknown())
|
||||
}
|
||||
Type::ClassLiteral(ClassLiteralType::NonGeneric(_)) => {
|
||||
// TODO: Once we know that e.g. `list` is generic, emit a diagnostic if you try to
|
||||
// specialize a non-generic class.
|
||||
self.infer_type_expression(slice);
|
||||
todo_type!("specialized non-generic class")
|
||||
}
|
||||
_ => {
|
||||
// TODO: Emit a diagnostic once we've implemented all valid subscript type
|
||||
@@ -7714,8 +7706,6 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
| KnownInstanceType::Any
|
||||
| KnownInstanceType::AlwaysTruthy
|
||||
| KnownInstanceType::AlwaysFalsy => {
|
||||
self.infer_type_expression(arguments_slice);
|
||||
|
||||
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
|
||||
builder.into_diagnostic(format_args!(
|
||||
"Type `{}` expected no type parameter",
|
||||
@@ -7726,10 +7716,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
}
|
||||
KnownInstanceType::TypingSelf
|
||||
| KnownInstanceType::TypeAlias
|
||||
| KnownInstanceType::TypedDict
|
||||
| KnownInstanceType::Unknown => {
|
||||
self.infer_type_expression(arguments_slice);
|
||||
|
||||
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
|
||||
builder.into_diagnostic(format_args!(
|
||||
"Special form `{}` expected no type parameter",
|
||||
@@ -7739,8 +7726,6 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
Type::unknown()
|
||||
}
|
||||
KnownInstanceType::LiteralString => {
|
||||
self.infer_type_expression(arguments_slice);
|
||||
|
||||
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
|
||||
let mut diag = builder.into_diagnostic(format_args!(
|
||||
"Type `{}` expected no type parameter",
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
//! Instance types: both nominal and structural.
|
||||
|
||||
use ruff_python_ast::name::Name;
|
||||
|
||||
use super::{ClassType, KnownClass, SubclassOfType, Type};
|
||||
use crate::{Db, FxOrderSet};
|
||||
use crate::Db;
|
||||
|
||||
impl<'db> Type<'db> {
|
||||
pub(crate) fn instance(db: &'db dyn Db, class: ClassType<'db>) -> Self {
|
||||
if class.is_protocol(db) {
|
||||
Self::ProtocolInstance(ProtocolInstanceType(Protocol::FromClass(class)))
|
||||
} else {
|
||||
Self::NominalInstance(NominalInstanceType { class })
|
||||
}
|
||||
pub(crate) const fn instance(class: ClassType<'db>) -> Self {
|
||||
Self::Instance(InstanceType { class })
|
||||
}
|
||||
|
||||
pub(crate) const fn into_nominal_instance(self) -> Option<NominalInstanceType<'db>> {
|
||||
pub(crate) const fn into_instance(self) -> Option<InstanceType<'db>> {
|
||||
match self {
|
||||
Type::NominalInstance(instance_type) => Some(instance_type),
|
||||
Type::Instance(instance_type) => Some(instance_type),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -24,13 +18,13 @@ impl<'db> Type<'db> {
|
||||
|
||||
/// A type representing the set of runtime objects which are instances of a certain nominal class.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, salsa::Update)]
|
||||
pub struct NominalInstanceType<'db> {
|
||||
// Keep this field private, so that the only way of constructing `NominalInstanceType` instances
|
||||
pub struct InstanceType<'db> {
|
||||
// Keep this field private, so that the only way of constructing `InstanceType` instances
|
||||
// is through the `Type::instance` constructor function.
|
||||
class: ClassType<'db>,
|
||||
}
|
||||
|
||||
impl<'db> NominalInstanceType<'db> {
|
||||
impl<'db> InstanceType<'db> {
|
||||
pub(super) fn class(self) -> ClassType<'db> {
|
||||
self.class
|
||||
}
|
||||
@@ -93,134 +87,8 @@ impl<'db> NominalInstanceType<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> From<NominalInstanceType<'db>> for Type<'db> {
|
||||
fn from(value: NominalInstanceType<'db>) -> Self {
|
||||
Self::NominalInstance(value)
|
||||
impl<'db> From<InstanceType<'db>> for Type<'db> {
|
||||
fn from(value: InstanceType<'db>) -> Self {
|
||||
Self::Instance(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, salsa::Update)]
|
||||
pub struct ProtocolInstanceType<'db>(
|
||||
// Keep the inner field here private,
|
||||
// so that the only way of constructing `ProtocolInstanceType` instances
|
||||
// is through the `Type::instance` constructor function.
|
||||
Protocol<'db>,
|
||||
);
|
||||
|
||||
impl<'db> ProtocolInstanceType<'db> {
|
||||
pub(super) fn protocol_members(self, db: &'db dyn Db) -> &'db FxOrderSet<Name> {
|
||||
self.0.protocol_members(db)
|
||||
}
|
||||
|
||||
pub(super) fn inner(self) -> Protocol<'db> {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub(super) fn to_meta_type(self, db: &'db dyn Db) -> Type<'db> {
|
||||
match self.0 {
|
||||
Protocol::FromClass(class) => SubclassOfType::from(db, class),
|
||||
|
||||
// TODO: we can and should do better here.
|
||||
//
|
||||
// This is supported by mypy, and should be supported by us as well.
|
||||
// We'll need to come up with a better solution for the meta-type of
|
||||
// synthesized protocols to solve this:
|
||||
//
|
||||
// ```py
|
||||
// from typing import Callable
|
||||
//
|
||||
// def foo(x: Callable[[], int]) -> None:
|
||||
// reveal_type(type(x)) # mypy: "type[def (builtins.int) -> builtins.str]"
|
||||
// reveal_type(type(x).__call__) # mypy: "def (*args: Any, **kwds: Any) -> Any"
|
||||
// ```
|
||||
Protocol::Synthesized(_) => KnownClass::Type.to_instance(db),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn normalized(self, db: &'db dyn Db) -> Type<'db> {
|
||||
let object = KnownClass::Object.to_instance(db);
|
||||
if object.satisfies_protocol(db, self) {
|
||||
return object;
|
||||
}
|
||||
match self.0 {
|
||||
Protocol::FromClass(_) => Type::ProtocolInstance(Self(Protocol::Synthesized(
|
||||
SynthesizedProtocolType::new(db, self.protocol_members(db)),
|
||||
))),
|
||||
Protocol::Synthesized(_) => Type::ProtocolInstance(self),
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO: should iterate over the types of the members
|
||||
/// and check if any of them contain `Todo` types
|
||||
#[expect(clippy::unused_self)]
|
||||
pub(super) fn contains_todo(self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// TODO: should not be considered fully static if any members do not have fully static types
|
||||
#[expect(clippy::unused_self)]
|
||||
pub(super) fn is_fully_static(self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// TODO: consider the types of the members as well as their existence
|
||||
pub(super) fn is_subtype_of(self, db: &'db dyn Db, other: Self) -> bool {
|
||||
self.protocol_members(db)
|
||||
.is_superset(other.protocol_members(db))
|
||||
}
|
||||
|
||||
/// TODO: consider the types of the members as well as their existence
|
||||
pub(super) fn is_assignable_to(self, db: &'db dyn Db, other: Self) -> bool {
|
||||
self.is_subtype_of(db, other)
|
||||
}
|
||||
|
||||
/// TODO: consider the types of the members as well as their existence
|
||||
pub(super) fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool {
|
||||
self.normalized(db) == other.normalized(db)
|
||||
}
|
||||
|
||||
/// TODO: consider the types of the members as well as their existence
|
||||
pub(super) fn is_gradual_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool {
|
||||
self.is_equivalent_to(db, other)
|
||||
}
|
||||
|
||||
/// TODO: a protocol `X` is disjoint from a protocol `Y` if `X` and `Y`
|
||||
/// have a member with the same name but disjoint types
|
||||
#[expect(clippy::unused_self)]
|
||||
pub(super) fn is_disjoint_from(self, _db: &'db dyn Db, _other: Self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Private inner enum to represent the two kinds of protocol types.
|
||||
/// This is not exposed publicly, so that the only way of constructing `Protocol` instances
|
||||
/// is through the [`Type::instance`] constructor function.
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Eq, PartialEq, Hash, salsa::Update, salsa::Supertype, PartialOrd, Ord,
|
||||
)]
|
||||
pub(super) enum Protocol<'db> {
|
||||
FromClass(ClassType<'db>),
|
||||
Synthesized(SynthesizedProtocolType<'db>),
|
||||
}
|
||||
|
||||
#[salsa::tracked]
|
||||
impl<'db> Protocol<'db> {
|
||||
#[salsa::tracked(return_ref)]
|
||||
fn protocol_members(self, db: &'db dyn Db) -> FxOrderSet<Name> {
|
||||
match self {
|
||||
Self::FromClass(class) => class
|
||||
.class_literal(db)
|
||||
.0
|
||||
.into_protocol_class(db)
|
||||
.expect("Protocol class literal should be a protocol class")
|
||||
.protocol_members(db),
|
||||
Self::Synthesized(synthesized) => synthesized.members(db).clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[salsa::interned(debug)]
|
||||
pub(super) struct SynthesizedProtocolType<'db> {
|
||||
#[return_ref]
|
||||
pub(super) members: FxOrderSet<Name>,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! The `KnownInstance` type.
|
||||
//!
|
||||
//! Despite its name, this is quite a different type from [`super::NominalInstanceType`].
|
||||
//! Despite its name, this is quite a different type from [`super::InstanceType`].
|
||||
//! For the vast majority of instance-types in Python, we cannot say how many possible
|
||||
//! inhabitants there are or could be of that type at runtime. Each variant of the
|
||||
//! [`KnownInstanceType`] enum, however, represents a specific runtime symbol
|
||||
@@ -95,7 +95,6 @@ pub enum KnownInstanceType<'db> {
|
||||
NotRequired,
|
||||
TypeAlias,
|
||||
TypeGuard,
|
||||
TypedDict,
|
||||
TypeIs,
|
||||
ReadOnly,
|
||||
// TODO: fill this enum out with more special forms, etc.
|
||||
@@ -126,7 +125,6 @@ impl<'db> KnownInstanceType<'db> {
|
||||
| Self::NotRequired
|
||||
| Self::TypeAlias
|
||||
| Self::TypeGuard
|
||||
| Self::TypedDict
|
||||
| Self::TypeIs
|
||||
| Self::List
|
||||
| Self::Dict
|
||||
@@ -174,7 +172,6 @@ impl<'db> KnownInstanceType<'db> {
|
||||
Self::NotRequired => "typing.NotRequired",
|
||||
Self::TypeAlias => "typing.TypeAlias",
|
||||
Self::TypeGuard => "typing.TypeGuard",
|
||||
Self::TypedDict => "typing.TypedDict",
|
||||
Self::TypeIs => "typing.TypeIs",
|
||||
Self::List => "typing.List",
|
||||
Self::Dict => "typing.Dict",
|
||||
@@ -223,7 +220,6 @@ impl<'db> KnownInstanceType<'db> {
|
||||
Self::NotRequired => KnownClass::SpecialForm,
|
||||
Self::TypeAlias => KnownClass::SpecialForm,
|
||||
Self::TypeGuard => KnownClass::SpecialForm,
|
||||
Self::TypedDict => KnownClass::SpecialForm,
|
||||
Self::TypeIs => KnownClass::SpecialForm,
|
||||
Self::ReadOnly => KnownClass::SpecialForm,
|
||||
Self::List => KnownClass::StdlibAlias,
|
||||
@@ -253,7 +249,7 @@ impl<'db> KnownInstanceType<'db> {
|
||||
///
|
||||
/// For example, the symbol `typing.Literal` is an instance of `typing._SpecialForm`,
|
||||
/// so `KnownInstanceType::Literal.instance_fallback(db)`
|
||||
/// returns `Type::NominalInstance(NominalInstanceType { class: <typing._SpecialForm> })`.
|
||||
/// returns `Type::Instance(InstanceType { class: <typing._SpecialForm> })`.
|
||||
pub(super) fn instance_fallback(self, db: &dyn Db) -> Type {
|
||||
self.class().to_instance(db)
|
||||
}
|
||||
@@ -297,7 +293,6 @@ impl<'db> KnownInstanceType<'db> {
|
||||
"Required" => Self::Required,
|
||||
"TypeAlias" => Self::TypeAlias,
|
||||
"TypeGuard" => Self::TypeGuard,
|
||||
"TypedDict" => Self::TypedDict,
|
||||
"TypeIs" => Self::TypeIs,
|
||||
"ReadOnly" => Self::ReadOnly,
|
||||
"Concatenate" => Self::Concatenate,
|
||||
@@ -355,7 +350,6 @@ impl<'db> KnownInstanceType<'db> {
|
||||
| Self::NotRequired
|
||||
| Self::TypeAlias
|
||||
| Self::TypeGuard
|
||||
| Self::TypedDict
|
||||
| Self::TypeIs
|
||||
| Self::ReadOnly
|
||||
| Self::TypeAliasType(_)
|
||||
|
||||
@@ -5,13 +5,13 @@ use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::types::class_base::ClassBase;
|
||||
use crate::types::generics::Specialization;
|
||||
use crate::types::{ClassLiteral, ClassType, Type};
|
||||
use crate::types::{ClassLiteralType, ClassType, Type};
|
||||
use crate::Db;
|
||||
|
||||
/// The inferred method resolution order of a given class.
|
||||
///
|
||||
/// An MRO cannot contain non-specialized generic classes. (This is why [`ClassBase`] contains a
|
||||
/// [`ClassType`], not a [`ClassLiteral`].) Any generic classes in a base class list are always
|
||||
/// [`ClassType`], not a [`ClassLiteralType`].) Any generic classes in a base class list are always
|
||||
/// specialized — either because the class is explicitly specialized if there is a subscript
|
||||
/// expression, or because we create the default specialization if there isn't.
|
||||
///
|
||||
@@ -33,7 +33,7 @@ pub(super) struct Mro<'db>(Box<[ClassBase<'db>]>);
|
||||
impl<'db> Mro<'db> {
|
||||
/// Attempt to resolve the MRO of a given class. Because we derive the MRO from the list of
|
||||
/// base classes in the class definition, this operation is performed on a [class
|
||||
/// literal][ClassLiteral], not a [class type][ClassType]. (You can _also_ get the MRO of a
|
||||
/// literal][ClassLiteralType], not a [class type][ClassType]. (You can _also_ get the MRO of a
|
||||
/// class type, but this is done by first getting the MRO of the underlying class literal, and
|
||||
/// specializing each base class as needed if the class type is a generic alias.)
|
||||
///
|
||||
@@ -47,7 +47,7 @@ impl<'db> Mro<'db> {
|
||||
/// [`super::infer::TypeInferenceBuilder::infer_region_scope`].)
|
||||
pub(super) fn of_class(
|
||||
db: &'db dyn Db,
|
||||
class: ClassLiteral<'db>,
|
||||
class: ClassLiteralType<'db>,
|
||||
specialization: Option<Specialization<'db>>,
|
||||
) -> Result<Self, MroError<'db>> {
|
||||
Self::of_class_impl(db, class, specialization).map_err(|err| {
|
||||
@@ -65,7 +65,7 @@ impl<'db> Mro<'db> {
|
||||
|
||||
fn of_class_impl(
|
||||
db: &'db dyn Db,
|
||||
class: ClassLiteral<'db>,
|
||||
class: ClassLiteralType<'db>,
|
||||
specialization: Option<Specialization<'db>>,
|
||||
) -> Result<Self, MroErrorKind<'db>> {
|
||||
let class_bases = class.explicit_bases(db);
|
||||
@@ -220,12 +220,12 @@ impl<'db> FromIterator<ClassBase<'db>> for Mro<'db> {
|
||||
///
|
||||
/// Even for first-party code, where we will have to resolve the MRO for every class we encounter,
|
||||
/// loading the cached MRO comes with a certain amount of overhead, so it's best to avoid calling the
|
||||
/// Salsa-tracked [`ClassLiteral::try_mro`] method unless it's absolutely necessary.
|
||||
/// Salsa-tracked [`ClassLiteralType::try_mro`] method unless it's absolutely necessary.
|
||||
pub(super) struct MroIterator<'db> {
|
||||
db: &'db dyn Db,
|
||||
|
||||
/// The class whose MRO we're iterating over
|
||||
class: ClassLiteral<'db>,
|
||||
class: ClassLiteralType<'db>,
|
||||
|
||||
/// The specialization to apply to each MRO element, if any
|
||||
specialization: Option<Specialization<'db>>,
|
||||
@@ -244,7 +244,7 @@ pub(super) struct MroIterator<'db> {
|
||||
impl<'db> MroIterator<'db> {
|
||||
pub(super) fn new(
|
||||
db: &'db dyn Db,
|
||||
class: ClassLiteral<'db>,
|
||||
class: ClassLiteralType<'db>,
|
||||
specialization: Option<Specialization<'db>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -326,11 +326,11 @@ pub(super) enum MroErrorKind<'db> {
|
||||
|
||||
/// The class has one or more duplicate bases.
|
||||
///
|
||||
/// This variant records the indices and [`ClassLiteral`]s
|
||||
/// This variant records the indices and [`ClassLiteralType`]s
|
||||
/// of the duplicate bases. The indices are the indices of nodes
|
||||
/// in the bases list of the class's [`StmtClassDef`](ruff_python_ast::StmtClassDef) node.
|
||||
/// Each index is the index of a node representing a duplicate base.
|
||||
DuplicateBases(Box<[(usize, ClassLiteral<'db>)]>),
|
||||
DuplicateBases(Box<[(usize, ClassLiteralType<'db>)]>),
|
||||
|
||||
/// The MRO is otherwise unresolvable through the C3-merge algorithm.
|
||||
///
|
||||
|
||||
@@ -8,8 +8,8 @@ use crate::semantic_index::symbol::{ScopeId, ScopedSymbolId, SymbolTable};
|
||||
use crate::semantic_index::symbol_table;
|
||||
use crate::types::infer::infer_same_file_expression_type;
|
||||
use crate::types::{
|
||||
infer_expression_types, IntersectionBuilder, KnownClass, SubclassOfType, Truthiness, Type,
|
||||
UnionBuilder,
|
||||
infer_expression_types, ClassLiteralType, IntersectionBuilder, KnownClass, SubclassOfType,
|
||||
Truthiness, Type, UnionBuilder,
|
||||
};
|
||||
use crate::Db;
|
||||
use itertools::Itertools;
|
||||
@@ -159,7 +159,7 @@ impl KnownConstraintFunction {
|
||||
/// union types are not yet supported. Returns `None` if the `classinfo` argument has a wrong type.
|
||||
fn generate_constraint<'db>(self, db: &'db dyn Db, classinfo: Type<'db>) -> Option<Type<'db>> {
|
||||
let constraint_fn = |class| match self {
|
||||
KnownConstraintFunction::IsInstance => Type::instance(db, class),
|
||||
KnownConstraintFunction::IsInstance => Type::instance(class),
|
||||
KnownConstraintFunction::IsSubclass => SubclassOfType::from(db, class),
|
||||
};
|
||||
|
||||
@@ -472,9 +472,7 @@ impl<'db> NarrowingConstraintsBuilder<'db> {
|
||||
union.map(db, |ty| filter_to_cannot_be_equal(db, *ty, rhs_ty))
|
||||
}
|
||||
// Treat `bool` as `Literal[True, False]`.
|
||||
Type::NominalInstance(instance)
|
||||
if instance.class().is_known(db, KnownClass::Bool) =>
|
||||
{
|
||||
Type::Instance(instance) if instance.class().is_known(db, KnownClass::Bool) => {
|
||||
UnionType::from_elements(
|
||||
db,
|
||||
[Type::BooleanLiteral(true), Type::BooleanLiteral(false)]
|
||||
@@ -503,7 +501,7 @@ impl<'db> NarrowingConstraintsBuilder<'db> {
|
||||
|
||||
fn evaluate_expr_ne(&mut self, lhs_ty: Type<'db>, rhs_ty: Type<'db>) -> Option<Type<'db>> {
|
||||
match (lhs_ty, rhs_ty) {
|
||||
(Type::NominalInstance(instance), Type::IntLiteral(i))
|
||||
(Type::Instance(instance), Type::IntLiteral(i))
|
||||
if instance.class().is_known(self.db, KnownClass::Bool) =>
|
||||
{
|
||||
if i == 0 {
|
||||
@@ -650,7 +648,9 @@ impl<'db> NarrowingConstraintsBuilder<'db> {
|
||||
}) if keywords.is_empty() => {
|
||||
let rhs_class = match rhs_ty {
|
||||
Type::ClassLiteral(class) => class,
|
||||
Type::GenericAlias(alias) => alias.origin(self.db),
|
||||
Type::GenericAlias(alias) => {
|
||||
ClassLiteralType::Generic(alias.origin(self.db))
|
||||
}
|
||||
_ => {
|
||||
continue;
|
||||
}
|
||||
@@ -684,7 +684,7 @@ impl<'db> NarrowingConstraintsBuilder<'db> {
|
||||
let symbol = self.expect_expr_name_symbol(id);
|
||||
constraints.insert(
|
||||
symbol,
|
||||
Type::instance(self.db, rhs_class.unknown_specialization(self.db)),
|
||||
Type::instance(rhs_class.unknown_specialization(self.db)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ macro_rules! type_property_test {
|
||||
|
||||
mod stable {
|
||||
use super::union;
|
||||
use crate::types::{CallableType, Type};
|
||||
use crate::types::Type;
|
||||
|
||||
// Reflexivity: `T` is equivalent to itself.
|
||||
type_property_test!(
|
||||
@@ -169,14 +169,6 @@ mod stable {
|
||||
forall types t. t.is_fully_static(db) => Type::Never.is_subtype_of(db, t)
|
||||
);
|
||||
|
||||
// Similar to `Never`, a fully-static "bottom" callable type should be a subtype of all
|
||||
// fully-static callable types
|
||||
type_property_test!(
|
||||
bottom_callable_is_subtype_of_all_fully_static_callable, db,
|
||||
forall types t. t.is_callable_type() && t.is_fully_static(db)
|
||||
=> CallableType::bottom(db).is_subtype_of(db, t)
|
||||
);
|
||||
|
||||
// For any two fully static types, each type in the pair must be a subtype of their union.
|
||||
type_property_test!(
|
||||
all_fully_static_type_pairs_are_subtype_of_their_union, db,
|
||||
|
||||
@@ -934,19 +934,6 @@ impl<'db> Parameters<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return parameters that represents `(*args: object, **kwargs: object)`.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn object(db: &'db dyn Db) -> Self {
|
||||
Self {
|
||||
value: vec![
|
||||
Parameter::variadic(Name::new_static("args")).with_annotated_type(Type::object(db)),
|
||||
Parameter::keyword_variadic(Name::new_static("kwargs"))
|
||||
.with_annotated_type(Type::object(db)),
|
||||
],
|
||||
is_gradual: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn from_parameters(
|
||||
db: &'db dyn Db,
|
||||
definition: Definition<'db>,
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::db::Db;
|
||||
use crate::symbol::{Boundness, Symbol};
|
||||
use crate::types::class_base::ClassBase;
|
||||
use crate::types::diagnostic::report_base_with_incompatible_slots;
|
||||
use crate::types::{ClassLiteral, Type};
|
||||
use crate::types::{ClassLiteralType, Type};
|
||||
|
||||
use super::InferContext;
|
||||
|
||||
@@ -23,7 +23,7 @@ enum SlotsKind {
|
||||
}
|
||||
|
||||
impl SlotsKind {
|
||||
fn from(db: &dyn Db, base: ClassLiteral) -> Self {
|
||||
fn from(db: &dyn Db, base: ClassLiteralType) -> Self {
|
||||
let Symbol::Type(slots_ty, bound) = base.own_class_member(db, None, "__slots__").symbol
|
||||
else {
|
||||
return Self::NotSpecified;
|
||||
@@ -53,7 +53,7 @@ impl SlotsKind {
|
||||
|
||||
pub(super) fn check_class_slots(
|
||||
context: &InferContext,
|
||||
class: ClassLiteral,
|
||||
class: ClassLiteralType,
|
||||
node: &ast::StmtClassDef,
|
||||
) {
|
||||
let db = context.db();
|
||||
|
||||
@@ -16,8 +16,8 @@ impl<'db> SubclassOfType<'db> {
|
||||
/// This method does not always return a [`Type::SubclassOf`] variant.
|
||||
/// If the class object is known to be a final class,
|
||||
/// this method will return a [`Type::ClassLiteral`] variant; this is a more precise type.
|
||||
/// If the class object is `builtins.object`, `Type::NominalInstance(<builtins.type>)`
|
||||
/// will be returned; this is no more precise, but it is exactly equivalent to `type[object]`.
|
||||
/// If the class object is `builtins.object`, `Type::Instance(<builtins.type>)` will be returned;
|
||||
/// this is no more precise, but it is exactly equivalent to `type[object]`.
|
||||
///
|
||||
/// The eager normalization here means that we do not need to worry elsewhere about distinguishing
|
||||
/// between `@final` classes and other classes when dealing with [`Type::SubclassOf`] variants.
|
||||
@@ -94,9 +94,9 @@ impl<'db> SubclassOfType<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn to_instance(self, db: &'db dyn Db) -> Type<'db> {
|
||||
pub(crate) fn to_instance(self) -> Type<'db> {
|
||||
match self.subclass_of {
|
||||
SubclassOfInner::Class(class) => Type::instance(db, class),
|
||||
SubclassOfInner::Class(class) => Type::instance(class),
|
||||
SubclassOfInner::Dynamic(dynamic_type) => Type::Dynamic(dynamic_type),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,20 +126,10 @@ pub(super) fn union_or_intersection_elements_ordering<'db>(
|
||||
|
||||
(Type::SubclassOf(_), _) => Ordering::Less,
|
||||
(_, Type::SubclassOf(_)) => Ordering::Greater,
|
||||
(Type::Instance(left), Type::Instance(right)) => left.class().cmp(&right.class()),
|
||||
|
||||
(Type::NominalInstance(left), Type::NominalInstance(right)) => {
|
||||
left.class().cmp(&right.class())
|
||||
}
|
||||
(Type::NominalInstance(_), _) => Ordering::Less,
|
||||
(_, Type::NominalInstance(_)) => Ordering::Greater,
|
||||
|
||||
(Type::ProtocolInstance(left_proto), Type::ProtocolInstance(right_proto)) => {
|
||||
debug_assert_eq!(*left, left_proto.normalized(db));
|
||||
debug_assert_eq!(*right, right_proto.normalized(db));
|
||||
left_proto.cmp(right_proto)
|
||||
}
|
||||
(Type::ProtocolInstance(_), _) => Ordering::Less,
|
||||
(_, Type::ProtocolInstance(_)) => Ordering::Greater,
|
||||
(Type::Instance(_), _) => Ordering::Less,
|
||||
(_, Type::Instance(_)) => Ordering::Greater,
|
||||
|
||||
(Type::TypeVar(left), Type::TypeVar(right)) => left.cmp(right),
|
||||
(Type::TypeVar(_), _) => Ordering::Less,
|
||||
@@ -231,9 +221,6 @@ pub(super) fn union_or_intersection_elements_ordering<'db>(
|
||||
(KnownInstanceType::TypeGuard, _) => Ordering::Less,
|
||||
(_, KnownInstanceType::TypeGuard) => Ordering::Greater,
|
||||
|
||||
(KnownInstanceType::TypedDict, _) => Ordering::Less,
|
||||
(_, KnownInstanceType::TypedDict) => Ordering::Greater,
|
||||
|
||||
(KnownInstanceType::List, _) => Ordering::Less,
|
||||
(_, KnownInstanceType::List) => Ordering::Greater,
|
||||
|
||||
|
||||
@@ -27,16 +27,6 @@ pub enum PositionEncoding {
|
||||
UTF8,
|
||||
}
|
||||
|
||||
impl From<PositionEncoding> for ruff_source_file::PositionEncoding {
|
||||
fn from(value: PositionEncoding) -> Self {
|
||||
match value {
|
||||
PositionEncoding::UTF8 => Self::Utf8,
|
||||
PositionEncoding::UTF16 => Self::Utf16,
|
||||
PositionEncoding::UTF32 => Self::Utf32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A unique document ID, derived from a URL passed as part of an LSP request.
|
||||
/// This document ID can point to either be a standalone Python file, a full notebook, or a cell within a notebook.
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -9,8 +9,8 @@ use red_knot_python_semantic::Db;
|
||||
use ruff_db::files::FileRange;
|
||||
use ruff_db::source::{line_index, source_text};
|
||||
use ruff_notebook::NotebookIndex;
|
||||
use ruff_source_file::LineIndex;
|
||||
use ruff_source_file::{OneIndexed, SourceLocation};
|
||||
use ruff_source_file::OneIndexed;
|
||||
use ruff_source_file::{LineIndex, SourceLocation};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
|
||||
#[expect(dead_code)]
|
||||
@@ -46,7 +46,7 @@ impl TextSizeExt for TextSize {
|
||||
index: &LineIndex,
|
||||
encoding: PositionEncoding,
|
||||
) -> types::Position {
|
||||
let source_location = index.source_location(self, text, encoding.into());
|
||||
let source_location = offset_to_source_location(self, text, index, encoding);
|
||||
source_location_to_position(&source_location)
|
||||
}
|
||||
}
|
||||
@@ -75,14 +75,36 @@ fn u32_index_to_usize(index: u32) -> usize {
|
||||
|
||||
impl PositionExt for lsp_types::Position {
|
||||
fn to_text_size(&self, text: &str, index: &LineIndex, encoding: PositionEncoding) -> TextSize {
|
||||
index.offset(
|
||||
SourceLocation {
|
||||
line: OneIndexed::from_zero_indexed(u32_index_to_usize(self.line)),
|
||||
character_offset: OneIndexed::from_zero_indexed(u32_index_to_usize(self.character)),
|
||||
},
|
||||
let start_line = index.line_range(
|
||||
OneIndexed::from_zero_indexed(u32_index_to_usize(self.line)),
|
||||
text,
|
||||
encoding.into(),
|
||||
)
|
||||
);
|
||||
|
||||
let start_column_offset = match encoding {
|
||||
PositionEncoding::UTF8 => TextSize::new(self.character),
|
||||
|
||||
PositionEncoding::UTF16 => {
|
||||
// Fast path for ASCII only documents
|
||||
if index.is_ascii() {
|
||||
TextSize::new(self.character)
|
||||
} else {
|
||||
// UTF16 encodes characters either as one or two 16 bit words.
|
||||
// The position in `range` is the 16-bit word offset from the start of the line (and not the character offset)
|
||||
// UTF-16 with a text that may use variable-length characters.
|
||||
utf8_column_offset(self.character, &text[start_line])
|
||||
}
|
||||
}
|
||||
PositionEncoding::UTF32 => {
|
||||
// UTF-32 uses 4 bytes for each character. Meaning, the position in range is a character offset.
|
||||
return index.offset(
|
||||
OneIndexed::from_zero_indexed(u32_index_to_usize(self.line)),
|
||||
OneIndexed::from_zero_indexed(u32_index_to_usize(self.character)),
|
||||
text,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
start_line.start() + start_column_offset.clamp(TextSize::new(0), start_line.end())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,23 +142,26 @@ impl ToRangeExt for TextRange {
|
||||
notebook_index: &NotebookIndex,
|
||||
encoding: PositionEncoding,
|
||||
) -> NotebookRange {
|
||||
let start = source_index.source_location(self.start(), text, encoding.into());
|
||||
let mut end = source_index.source_location(self.end(), text, encoding.into());
|
||||
let starting_cell = notebook_index.cell(start.line);
|
||||
let start = offset_to_source_location(self.start(), text, source_index, encoding);
|
||||
let mut end = offset_to_source_location(self.end(), text, source_index, encoding);
|
||||
let starting_cell = notebook_index.cell(start.row);
|
||||
|
||||
// weird edge case here - if the end of the range is where the newline after the cell got added (making it 'out of bounds')
|
||||
// we need to move it one character back (which should place it at the end of the last line).
|
||||
// we test this by checking if the ending offset is in a different (or nonexistent) cell compared to the cell of the starting offset.
|
||||
if notebook_index.cell(end.line) != starting_cell {
|
||||
end.line = end.line.saturating_sub(1);
|
||||
let offset = self.end().checked_sub(1.into()).unwrap_or_default();
|
||||
end.character_offset = source_index
|
||||
.source_location(offset, text, encoding.into())
|
||||
.character_offset;
|
||||
if notebook_index.cell(end.row) != starting_cell {
|
||||
end.row = end.row.saturating_sub(1);
|
||||
end.column = offset_to_source_location(
|
||||
self.end().checked_sub(1.into()).unwrap_or_default(),
|
||||
text,
|
||||
source_index,
|
||||
encoding,
|
||||
)
|
||||
.column;
|
||||
}
|
||||
|
||||
let start = source_location_to_position(¬ebook_index.translate_source_location(&start));
|
||||
let end = source_location_to_position(¬ebook_index.translate_source_location(&end));
|
||||
let start = source_location_to_position(¬ebook_index.translate_location(&start));
|
||||
let end = source_location_to_position(¬ebook_index.translate_location(&end));
|
||||
|
||||
NotebookRange {
|
||||
cell: starting_cell
|
||||
@@ -147,10 +172,67 @@ impl ToRangeExt for TextRange {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a UTF-16 code unit offset for a given line into a UTF-8 column number.
|
||||
fn utf8_column_offset(utf16_code_unit_offset: u32, line: &str) -> TextSize {
|
||||
let mut utf8_code_unit_offset = TextSize::new(0);
|
||||
|
||||
let mut i = 0u32;
|
||||
|
||||
for c in line.chars() {
|
||||
if i >= utf16_code_unit_offset {
|
||||
break;
|
||||
}
|
||||
|
||||
// Count characters encoded as two 16 bit words as 2 characters.
|
||||
{
|
||||
utf8_code_unit_offset +=
|
||||
TextSize::new(u32::try_from(c.len_utf8()).expect("utf8 len always <=4"));
|
||||
i += u32::try_from(c.len_utf16()).expect("utf16 len always <=2");
|
||||
}
|
||||
}
|
||||
|
||||
utf8_code_unit_offset
|
||||
}
|
||||
|
||||
fn offset_to_source_location(
|
||||
offset: TextSize,
|
||||
text: &str,
|
||||
index: &LineIndex,
|
||||
encoding: PositionEncoding,
|
||||
) -> SourceLocation {
|
||||
match encoding {
|
||||
PositionEncoding::UTF8 => {
|
||||
let row = index.line_index(offset);
|
||||
let column = offset - index.line_start(row, text);
|
||||
|
||||
SourceLocation {
|
||||
column: OneIndexed::from_zero_indexed(column.to_usize()),
|
||||
row,
|
||||
}
|
||||
}
|
||||
PositionEncoding::UTF16 => {
|
||||
let row = index.line_index(offset);
|
||||
|
||||
let column = if index.is_ascii() {
|
||||
(offset - index.line_start(row, text)).to_usize()
|
||||
} else {
|
||||
let up_to_line = &text[TextRange::new(index.line_start(row, text), offset)];
|
||||
up_to_line.encode_utf16().count()
|
||||
};
|
||||
|
||||
SourceLocation {
|
||||
column: OneIndexed::from_zero_indexed(column),
|
||||
row,
|
||||
}
|
||||
}
|
||||
PositionEncoding::UTF32 => index.source_location(offset, text),
|
||||
}
|
||||
}
|
||||
|
||||
fn source_location_to_position(location: &SourceLocation) -> types::Position {
|
||||
types::Position {
|
||||
line: u32::try_from(location.line.to_zero_indexed()).expect("line usize fits in u32"),
|
||||
character: u32::try_from(location.character_offset.to_zero_indexed())
|
||||
line: u32::try_from(location.row.to_zero_indexed()).expect("row usize fits in u32"),
|
||||
character: u32::try_from(location.column.to_zero_indexed())
|
||||
.expect("character usize fits in u32"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ smallvec = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -96,10 +96,7 @@ impl SemanticDb for Db {
|
||||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Db {
|
||||
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
|
||||
let event = event();
|
||||
tracing::trace!("event: {:?}", event);
|
||||
}
|
||||
fn salsa_event(&self, _event: &dyn Fn() -> salsa::Event) {}
|
||||
}
|
||||
|
||||
impl DbWithWritableSystem for Db {
|
||||
|
||||
@@ -263,7 +263,7 @@ impl Matcher {
|
||||
.and_then(|span| span.range())
|
||||
.map(|range| {
|
||||
self.line_index
|
||||
.line_column(range.start(), &self.source)
|
||||
.source_location(range.start(), &self.source)
|
||||
.column
|
||||
})
|
||||
.unwrap_or(OneIndexed::from_zero_indexed(0))
|
||||
|
||||
36
crates/red_knot_vendored/vendor/typeshed/stdlib/__future__.pyi
vendored
Normal file
36
crates/red_knot_vendored/vendor/typeshed/stdlib/__future__.pyi
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
_VersionInfo: TypeAlias = tuple[int, int, int, str, int]
|
||||
|
||||
class _Feature:
|
||||
def __init__(self, optionalRelease: _VersionInfo, mandatoryRelease: _VersionInfo | None, compiler_flag: int) -> None: ...
|
||||
def getOptionalRelease(self) -> _VersionInfo: ...
|
||||
def getMandatoryRelease(self) -> _VersionInfo | None: ...
|
||||
compiler_flag: int
|
||||
|
||||
absolute_import: _Feature
|
||||
division: _Feature
|
||||
generators: _Feature
|
||||
nested_scopes: _Feature
|
||||
print_function: _Feature
|
||||
unicode_literals: _Feature
|
||||
with_statement: _Feature
|
||||
barry_as_FLUFL: _Feature
|
||||
generator_stop: _Feature
|
||||
annotations: _Feature
|
||||
|
||||
all_feature_names: list[str] # undocumented
|
||||
|
||||
__all__ = [
|
||||
"all_feature_names",
|
||||
"absolute_import",
|
||||
"division",
|
||||
"generators",
|
||||
"nested_scopes",
|
||||
"print_function",
|
||||
"unicode_literals",
|
||||
"with_statement",
|
||||
"barry_as_FLUFL",
|
||||
"generator_stop",
|
||||
"annotations",
|
||||
]
|
||||
3
crates/red_knot_vendored/vendor/typeshed/stdlib/__main__.pyi
vendored
Normal file
3
crates/red_knot_vendored/vendor/typeshed/stdlib/__main__.pyi
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
from typing import Any
|
||||
|
||||
def __getattr__(name: str) -> Any: ...
|
||||
138
crates/red_knot_vendored/vendor/typeshed/stdlib/_ast.pyi
vendored
Normal file
138
crates/red_knot_vendored/vendor/typeshed/stdlib/_ast.pyi
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
import sys
|
||||
from ast import (
|
||||
AST as AST,
|
||||
Add as Add,
|
||||
And as And,
|
||||
AnnAssign as AnnAssign,
|
||||
Assert as Assert,
|
||||
Assign as Assign,
|
||||
AsyncFor as AsyncFor,
|
||||
AsyncFunctionDef as AsyncFunctionDef,
|
||||
AsyncWith as AsyncWith,
|
||||
Attribute as Attribute,
|
||||
AugAssign as AugAssign,
|
||||
Await as Await,
|
||||
BinOp as BinOp,
|
||||
BitAnd as BitAnd,
|
||||
BitOr as BitOr,
|
||||
BitXor as BitXor,
|
||||
BoolOp as BoolOp,
|
||||
Break as Break,
|
||||
Call as Call,
|
||||
ClassDef as ClassDef,
|
||||
Compare as Compare,
|
||||
Constant as Constant,
|
||||
Continue as Continue,
|
||||
Del as Del,
|
||||
Delete as Delete,
|
||||
Dict as Dict,
|
||||
DictComp as DictComp,
|
||||
Div as Div,
|
||||
Eq as Eq,
|
||||
ExceptHandler as ExceptHandler,
|
||||
Expr as Expr,
|
||||
Expression as Expression,
|
||||
FloorDiv as FloorDiv,
|
||||
For as For,
|
||||
FormattedValue as FormattedValue,
|
||||
FunctionDef as FunctionDef,
|
||||
FunctionType as FunctionType,
|
||||
GeneratorExp as GeneratorExp,
|
||||
Global as Global,
|
||||
Gt as Gt,
|
||||
GtE as GtE,
|
||||
If as If,
|
||||
IfExp as IfExp,
|
||||
Import as Import,
|
||||
ImportFrom as ImportFrom,
|
||||
In as In,
|
||||
Interactive as Interactive,
|
||||
Invert as Invert,
|
||||
Is as Is,
|
||||
IsNot as IsNot,
|
||||
JoinedStr as JoinedStr,
|
||||
Lambda as Lambda,
|
||||
List as List,
|
||||
ListComp as ListComp,
|
||||
Load as Load,
|
||||
LShift as LShift,
|
||||
Lt as Lt,
|
||||
LtE as LtE,
|
||||
MatMult as MatMult,
|
||||
Mod as Mod,
|
||||
Module as Module,
|
||||
Mult as Mult,
|
||||
Name as Name,
|
||||
NamedExpr as NamedExpr,
|
||||
Nonlocal as Nonlocal,
|
||||
Not as Not,
|
||||
NotEq as NotEq,
|
||||
NotIn as NotIn,
|
||||
Or as Or,
|
||||
Pass as Pass,
|
||||
Pow as Pow,
|
||||
Raise as Raise,
|
||||
Return as Return,
|
||||
RShift as RShift,
|
||||
Set as Set,
|
||||
SetComp as SetComp,
|
||||
Slice as Slice,
|
||||
Starred as Starred,
|
||||
Store as Store,
|
||||
Sub as Sub,
|
||||
Subscript as Subscript,
|
||||
Try as Try,
|
||||
Tuple as Tuple,
|
||||
TypeIgnore as TypeIgnore,
|
||||
UAdd as UAdd,
|
||||
UnaryOp as UnaryOp,
|
||||
USub as USub,
|
||||
While as While,
|
||||
With as With,
|
||||
Yield as Yield,
|
||||
YieldFrom as YieldFrom,
|
||||
alias as alias,
|
||||
arg as arg,
|
||||
arguments as arguments,
|
||||
boolop as boolop,
|
||||
cmpop as cmpop,
|
||||
comprehension as comprehension,
|
||||
excepthandler as excepthandler,
|
||||
expr as expr,
|
||||
expr_context as expr_context,
|
||||
keyword as keyword,
|
||||
mod as mod,
|
||||
operator as operator,
|
||||
stmt as stmt,
|
||||
type_ignore as type_ignore,
|
||||
unaryop as unaryop,
|
||||
withitem as withitem,
|
||||
)
|
||||
from typing import Literal
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
from ast import ParamSpec as ParamSpec, TypeVar as TypeVar, TypeVarTuple as TypeVarTuple, type_param as type_param
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from ast import TryStar as TryStar
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from ast import (
|
||||
MatchAs as MatchAs,
|
||||
MatchClass as MatchClass,
|
||||
MatchMapping as MatchMapping,
|
||||
MatchOr as MatchOr,
|
||||
MatchSequence as MatchSequence,
|
||||
MatchSingleton as MatchSingleton,
|
||||
MatchStar as MatchStar,
|
||||
MatchValue as MatchValue,
|
||||
match_case as match_case,
|
||||
pattern as pattern,
|
||||
)
|
||||
|
||||
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
|
||||
PyCF_ONLY_AST: Literal[1024]
|
||||
PyCF_TYPE_COMMENTS: Literal[4096]
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
PyCF_OPTIMIZED_AST: Literal[33792]
|
||||
105
crates/red_knot_vendored/vendor/typeshed/stdlib/_asyncio.pyi
vendored
Normal file
105
crates/red_knot_vendored/vendor/typeshed/stdlib/_asyncio.pyi
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
import sys
|
||||
from asyncio.events import AbstractEventLoop
|
||||
from collections.abc import Awaitable, Callable, Coroutine, Generator
|
||||
from contextvars import Context
|
||||
from types import FrameType, GenericAlias
|
||||
from typing import Any, Literal, TextIO, TypeVar
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_T_co = TypeVar("_T_co", covariant=True)
|
||||
_TaskYieldType: TypeAlias = Future[object] | None
|
||||
|
||||
class Future(Awaitable[_T]):
|
||||
_state: str
|
||||
@property
|
||||
def _exception(self) -> BaseException | None: ...
|
||||
_blocking: bool
|
||||
@property
|
||||
def _log_traceback(self) -> bool: ...
|
||||
@_log_traceback.setter
|
||||
def _log_traceback(self, val: Literal[False]) -> None: ...
|
||||
_asyncio_future_blocking: bool # is a part of duck-typing contract for `Future`
|
||||
def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
def get_loop(self) -> AbstractEventLoop: ...
|
||||
@property
|
||||
def _callbacks(self) -> list[tuple[Callable[[Self], Any], Context]]: ...
|
||||
def add_done_callback(self, fn: Callable[[Self], object], /, *, context: Context | None = None) -> None: ...
|
||||
def cancel(self, msg: Any | None = None) -> bool: ...
|
||||
def cancelled(self) -> bool: ...
|
||||
def done(self) -> bool: ...
|
||||
def result(self) -> _T: ...
|
||||
def exception(self) -> BaseException | None: ...
|
||||
def remove_done_callback(self, fn: Callable[[Self], object], /) -> int: ...
|
||||
def set_result(self, result: _T, /) -> None: ...
|
||||
def set_exception(self, exception: type | BaseException, /) -> None: ...
|
||||
def __iter__(self) -> Generator[Any, None, _T]: ...
|
||||
def __await__(self) -> Generator[Any, None, _T]: ...
|
||||
@property
|
||||
def _loop(self) -> AbstractEventLoop: ...
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
_TaskCompatibleCoro: TypeAlias = Coroutine[Any, Any, _T_co]
|
||||
else:
|
||||
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Coroutine[Any, Any, _T_co]
|
||||
|
||||
# mypy and pyright complain that a subclass of an invariant class shouldn't be covariant.
|
||||
# While this is true in general, here it's sort-of okay to have a covariant subclass,
|
||||
# since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
|
||||
# and `asyncio.Task.set_result()` always raises.
|
||||
class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportInvalidTypeArguments]
|
||||
if sys.version_info >= (3, 12):
|
||||
def __init__(
|
||||
self,
|
||||
coro: _TaskCompatibleCoro[_T_co],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
name: str | None = ...,
|
||||
context: Context | None = None,
|
||||
eager_start: bool = False,
|
||||
) -> None: ...
|
||||
elif sys.version_info >= (3, 11):
|
||||
def __init__(
|
||||
self,
|
||||
coro: _TaskCompatibleCoro[_T_co],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
name: str | None = ...,
|
||||
context: Context | None = None,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, name: str | None = ...
|
||||
) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
def get_coro(self) -> _TaskCompatibleCoro[_T_co] | None: ...
|
||||
else:
|
||||
def get_coro(self) -> _TaskCompatibleCoro[_T_co]: ...
|
||||
|
||||
def get_name(self) -> str: ...
|
||||
def set_name(self, value: object, /) -> None: ...
|
||||
if sys.version_info >= (3, 12):
|
||||
def get_context(self) -> Context: ...
|
||||
|
||||
def get_stack(self, *, limit: int | None = None) -> list[FrameType]: ...
|
||||
def print_stack(self, *, limit: int | None = None, file: TextIO | None = None) -> None: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
def cancelling(self) -> int: ...
|
||||
def uncancel(self) -> int: ...
|
||||
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
def get_event_loop() -> AbstractEventLoop: ...
|
||||
def get_running_loop() -> AbstractEventLoop: ...
|
||||
def _set_running_loop(loop: AbstractEventLoop | None, /) -> None: ...
|
||||
def _get_running_loop() -> AbstractEventLoop: ...
|
||||
def _register_task(task: Task[Any]) -> None: ...
|
||||
def _unregister_task(task: Task[Any]) -> None: ...
|
||||
def _enter_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ...
|
||||
def _leave_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
def current_task(loop: AbstractEventLoop | None = None) -> Task[Any] | None: ...
|
||||
84
crates/red_knot_vendored/vendor/typeshed/stdlib/_bisect.pyi
vendored
Normal file
84
crates/red_knot_vendored/vendor/typeshed/stdlib/_bisect.pyi
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
import sys
|
||||
from _typeshed import SupportsLenAndGetItem, SupportsRichComparisonT
|
||||
from collections.abc import Callable, MutableSequence
|
||||
from typing import TypeVar, overload
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
@overload
|
||||
def bisect_left(
|
||||
a: SupportsLenAndGetItem[SupportsRichComparisonT],
|
||||
x: SupportsRichComparisonT,
|
||||
lo: int = 0,
|
||||
hi: int | None = None,
|
||||
*,
|
||||
key: None = None,
|
||||
) -> int: ...
|
||||
@overload
|
||||
def bisect_left(
|
||||
a: SupportsLenAndGetItem[_T],
|
||||
x: SupportsRichComparisonT,
|
||||
lo: int = 0,
|
||||
hi: int | None = None,
|
||||
*,
|
||||
key: Callable[[_T], SupportsRichComparisonT],
|
||||
) -> int: ...
|
||||
@overload
|
||||
def bisect_right(
|
||||
a: SupportsLenAndGetItem[SupportsRichComparisonT],
|
||||
x: SupportsRichComparisonT,
|
||||
lo: int = 0,
|
||||
hi: int | None = None,
|
||||
*,
|
||||
key: None = None,
|
||||
) -> int: ...
|
||||
@overload
|
||||
def bisect_right(
|
||||
a: SupportsLenAndGetItem[_T],
|
||||
x: SupportsRichComparisonT,
|
||||
lo: int = 0,
|
||||
hi: int | None = None,
|
||||
*,
|
||||
key: Callable[[_T], SupportsRichComparisonT],
|
||||
) -> int: ...
|
||||
@overload
|
||||
def insort_left(
|
||||
a: MutableSequence[SupportsRichComparisonT],
|
||||
x: SupportsRichComparisonT,
|
||||
lo: int = 0,
|
||||
hi: int | None = None,
|
||||
*,
|
||||
key: None = None,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def insort_left(
|
||||
a: MutableSequence[_T], x: _T, lo: int = 0, hi: int | None = None, *, key: Callable[[_T], SupportsRichComparisonT]
|
||||
) -> None: ...
|
||||
@overload
|
||||
def insort_right(
|
||||
a: MutableSequence[SupportsRichComparisonT],
|
||||
x: SupportsRichComparisonT,
|
||||
lo: int = 0,
|
||||
hi: int | None = None,
|
||||
*,
|
||||
key: None = None,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def insort_right(
|
||||
a: MutableSequence[_T], x: _T, lo: int = 0, hi: int | None = None, *, key: Callable[[_T], SupportsRichComparisonT]
|
||||
) -> None: ...
|
||||
|
||||
else:
|
||||
def bisect_left(
|
||||
a: SupportsLenAndGetItem[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
|
||||
) -> int: ...
|
||||
def bisect_right(
|
||||
a: SupportsLenAndGetItem[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
|
||||
) -> int: ...
|
||||
def insort_left(
|
||||
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
|
||||
) -> None: ...
|
||||
def insort_right(
|
||||
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None
|
||||
) -> None: ...
|
||||
76
crates/red_knot_vendored/vendor/typeshed/stdlib/_blake2.pyi
vendored
Normal file
76
crates/red_knot_vendored/vendor/typeshed/stdlib/_blake2.pyi
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
from _typeshed import ReadableBuffer
|
||||
from typing import ClassVar, final
|
||||
from typing_extensions import Self
|
||||
|
||||
BLAKE2B_MAX_DIGEST_SIZE: int = 64
|
||||
BLAKE2B_MAX_KEY_SIZE: int = 64
|
||||
BLAKE2B_PERSON_SIZE: int = 16
|
||||
BLAKE2B_SALT_SIZE: int = 16
|
||||
BLAKE2S_MAX_DIGEST_SIZE: int = 32
|
||||
BLAKE2S_MAX_KEY_SIZE: int = 32
|
||||
BLAKE2S_PERSON_SIZE: int = 8
|
||||
BLAKE2S_SALT_SIZE: int = 8
|
||||
|
||||
@final
|
||||
class blake2b:
|
||||
MAX_DIGEST_SIZE: ClassVar[int] = 64
|
||||
MAX_KEY_SIZE: ClassVar[int] = 64
|
||||
PERSON_SIZE: ClassVar[int] = 16
|
||||
SALT_SIZE: ClassVar[int] = 16
|
||||
block_size: int
|
||||
digest_size: int
|
||||
name: str
|
||||
def __new__(
|
||||
cls,
|
||||
data: ReadableBuffer = b"",
|
||||
/,
|
||||
*,
|
||||
digest_size: int = 64,
|
||||
key: ReadableBuffer = b"",
|
||||
salt: ReadableBuffer = b"",
|
||||
person: ReadableBuffer = b"",
|
||||
fanout: int = 1,
|
||||
depth: int = 1,
|
||||
leaf_size: int = 0,
|
||||
node_offset: int = 0,
|
||||
node_depth: int = 0,
|
||||
inner_size: int = 0,
|
||||
last_node: bool = False,
|
||||
usedforsecurity: bool = True,
|
||||
) -> Self: ...
|
||||
def copy(self) -> Self: ...
|
||||
def digest(self) -> bytes: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def update(self, data: ReadableBuffer, /) -> None: ...
|
||||
|
||||
@final
|
||||
class blake2s:
|
||||
MAX_DIGEST_SIZE: ClassVar[int] = 32
|
||||
MAX_KEY_SIZE: ClassVar[int] = 32
|
||||
PERSON_SIZE: ClassVar[int] = 8
|
||||
SALT_SIZE: ClassVar[int] = 8
|
||||
block_size: int
|
||||
digest_size: int
|
||||
name: str
|
||||
def __new__(
|
||||
cls,
|
||||
data: ReadableBuffer = b"",
|
||||
/,
|
||||
*,
|
||||
digest_size: int = 32,
|
||||
key: ReadableBuffer = b"",
|
||||
salt: ReadableBuffer = b"",
|
||||
person: ReadableBuffer = b"",
|
||||
fanout: int = 1,
|
||||
depth: int = 1,
|
||||
leaf_size: int = 0,
|
||||
node_offset: int = 0,
|
||||
node_depth: int = 0,
|
||||
inner_size: int = 0,
|
||||
last_node: bool = False,
|
||||
usedforsecurity: bool = True,
|
||||
) -> Self: ...
|
||||
def copy(self) -> Self: ...
|
||||
def digest(self) -> bytes: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def update(self, data: ReadableBuffer, /) -> None: ...
|
||||
1
crates/red_knot_vendored/vendor/typeshed/stdlib/_bootlocale.pyi
vendored
Normal file
1
crates/red_knot_vendored/vendor/typeshed/stdlib/_bootlocale.pyi
vendored
Normal file
@@ -0,0 +1 @@
|
||||
def getpreferredencoding(do_setlocale: bool = True) -> str: ...
|
||||
24
crates/red_knot_vendored/vendor/typeshed/stdlib/_bz2.pyi
vendored
Normal file
24
crates/red_knot_vendored/vendor/typeshed/stdlib/_bz2.pyi
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer
|
||||
from typing import final
|
||||
from typing_extensions import Self
|
||||
|
||||
@final
|
||||
class BZ2Compressor:
|
||||
if sys.version_info >= (3, 12):
|
||||
def __new__(cls, compresslevel: int = 9, /) -> Self: ...
|
||||
else:
|
||||
def __init__(self, compresslevel: int = 9, /) -> None: ...
|
||||
|
||||
def compress(self, data: ReadableBuffer, /) -> bytes: ...
|
||||
def flush(self) -> bytes: ...
|
||||
|
||||
@final
|
||||
class BZ2Decompressor:
|
||||
def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
|
||||
@property
|
||||
def eof(self) -> bool: ...
|
||||
@property
|
||||
def needs_input(self) -> bool: ...
|
||||
@property
|
||||
def unused_data(self) -> bytes: ...
|
||||
122
crates/red_knot_vendored/vendor/typeshed/stdlib/_codecs.pyi
vendored
Normal file
122
crates/red_knot_vendored/vendor/typeshed/stdlib/_codecs.pyi
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
import codecs
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer
|
||||
from collections.abc import Callable
|
||||
from typing import Literal, final, overload, type_check_only
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
# This type is not exposed; it is defined in unicodeobject.c
|
||||
# At runtime it calls itself builtins.EncodingMap
|
||||
@final
|
||||
@type_check_only
|
||||
class _EncodingMap:
|
||||
def size(self) -> int: ...
|
||||
|
||||
_CharMap: TypeAlias = dict[int, int] | _EncodingMap
|
||||
_Handler: TypeAlias = Callable[[UnicodeError], tuple[str | bytes, int]]
|
||||
_SearchFunction: TypeAlias = Callable[[str], codecs.CodecInfo | None]
|
||||
|
||||
def register(search_function: _SearchFunction, /) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
def unregister(search_function: _SearchFunction, /) -> None: ...
|
||||
|
||||
def register_error(errors: str, handler: _Handler, /) -> None: ...
|
||||
def lookup_error(name: str, /) -> _Handler: ...
|
||||
|
||||
# The type ignore on `encode` and `decode` is to avoid issues with overlapping overloads, for more details, see #300
|
||||
# https://docs.python.org/3/library/codecs.html#binary-transforms
|
||||
_BytesToBytesEncoding: TypeAlias = Literal[
|
||||
"base64",
|
||||
"base_64",
|
||||
"base64_codec",
|
||||
"bz2",
|
||||
"bz2_codec",
|
||||
"hex",
|
||||
"hex_codec",
|
||||
"quopri",
|
||||
"quotedprintable",
|
||||
"quoted_printable",
|
||||
"quopri_codec",
|
||||
"uu",
|
||||
"uu_codec",
|
||||
"zip",
|
||||
"zlib",
|
||||
"zlib_codec",
|
||||
]
|
||||
# https://docs.python.org/3/library/codecs.html#text-transforms
|
||||
_StrToStrEncoding: TypeAlias = Literal["rot13", "rot_13"]
|
||||
|
||||
@overload
|
||||
def encode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = "strict") -> bytes: ...
|
||||
@overload
|
||||
def encode(obj: str, encoding: _StrToStrEncoding, errors: str = "strict") -> str: ... # type: ignore[overload-overlap]
|
||||
@overload
|
||||
def encode(obj: str, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
|
||||
@overload
|
||||
def decode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = "strict") -> bytes: ... # type: ignore[overload-overlap]
|
||||
@overload
|
||||
def decode(obj: str, encoding: _StrToStrEncoding, errors: str = "strict") -> str: ...
|
||||
|
||||
# these are documented as text encodings but in practice they also accept str as input
|
||||
@overload
|
||||
def decode(
|
||||
obj: str,
|
||||
encoding: Literal["unicode_escape", "unicode-escape", "raw_unicode_escape", "raw-unicode-escape"],
|
||||
errors: str = "strict",
|
||||
) -> str: ...
|
||||
|
||||
# hex is officially documented as a bytes to bytes encoding, but it appears to also work with str
|
||||
@overload
|
||||
def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = "strict") -> bytes: ...
|
||||
@overload
|
||||
def decode(obj: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> str: ...
|
||||
def lookup(encoding: str, /) -> codecs.CodecInfo: ...
|
||||
def charmap_build(map: str, /) -> _CharMap: ...
|
||||
def ascii_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
|
||||
def ascii_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def charmap_decode(data: ReadableBuffer, errors: str | None = None, mapping: _CharMap | None = None, /) -> tuple[str, int]: ...
|
||||
def charmap_encode(str: str, errors: str | None = None, mapping: _CharMap | None = None, /) -> tuple[bytes, int]: ...
|
||||
def escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
|
||||
def escape_encode(data: bytes, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def latin_1_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
|
||||
def latin_1_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def raw_unicode_escape_decode(
|
||||
data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /
|
||||
) -> tuple[str, int]: ...
|
||||
def raw_unicode_escape_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def readbuffer_encode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def unicode_escape_decode(data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /) -> tuple[str, int]: ...
|
||||
def unicode_escape_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def utf_16_be_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def utf_16_be_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def utf_16_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def utf_16_encode(str: str, errors: str | None = None, byteorder: int = 0, /) -> tuple[bytes, int]: ...
|
||||
def utf_16_ex_decode(
|
||||
data: ReadableBuffer, errors: str | None = None, byteorder: int = 0, final: bool = False, /
|
||||
) -> tuple[str, int, int]: ...
|
||||
def utf_16_le_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def utf_16_le_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def utf_32_be_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def utf_32_be_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def utf_32_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def utf_32_encode(str: str, errors: str | None = None, byteorder: int = 0, /) -> tuple[bytes, int]: ...
|
||||
def utf_32_ex_decode(
|
||||
data: ReadableBuffer, errors: str | None = None, byteorder: int = 0, final: bool = False, /
|
||||
) -> tuple[str, int, int]: ...
|
||||
def utf_32_le_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def utf_32_le_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def utf_7_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def utf_7_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def utf_8_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def utf_8_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
def mbcs_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def mbcs_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def code_page_decode(
|
||||
codepage: int, data: ReadableBuffer, errors: str | None = None, final: bool = False, /
|
||||
) -> tuple[str, int]: ...
|
||||
def code_page_encode(code_page: int, str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
def oem_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
|
||||
def oem_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
|
||||
107
crates/red_knot_vendored/vendor/typeshed/stdlib/_collections_abc.pyi
vendored
Normal file
107
crates/red_knot_vendored/vendor/typeshed/stdlib/_collections_abc.pyi
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
import sys
|
||||
from abc import abstractmethod
|
||||
from types import MappingProxyType
|
||||
from typing import ( # noqa: Y022,Y038,UP035
|
||||
AbstractSet as Set,
|
||||
AsyncGenerator as AsyncGenerator,
|
||||
AsyncIterable as AsyncIterable,
|
||||
AsyncIterator as AsyncIterator,
|
||||
Awaitable as Awaitable,
|
||||
Callable as Callable,
|
||||
ClassVar,
|
||||
Collection as Collection,
|
||||
Container as Container,
|
||||
Coroutine as Coroutine,
|
||||
Generator as Generator,
|
||||
Generic,
|
||||
Hashable as Hashable,
|
||||
ItemsView as ItemsView,
|
||||
Iterable as Iterable,
|
||||
Iterator as Iterator,
|
||||
KeysView as KeysView,
|
||||
Mapping as Mapping,
|
||||
MappingView as MappingView,
|
||||
MutableMapping as MutableMapping,
|
||||
MutableSequence as MutableSequence,
|
||||
MutableSet as MutableSet,
|
||||
Protocol,
|
||||
Reversible as Reversible,
|
||||
Sequence as Sequence,
|
||||
Sized as Sized,
|
||||
TypeVar,
|
||||
ValuesView as ValuesView,
|
||||
final,
|
||||
runtime_checkable,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Awaitable",
|
||||
"Coroutine",
|
||||
"AsyncIterable",
|
||||
"AsyncIterator",
|
||||
"AsyncGenerator",
|
||||
"Hashable",
|
||||
"Iterable",
|
||||
"Iterator",
|
||||
"Generator",
|
||||
"Reversible",
|
||||
"Sized",
|
||||
"Container",
|
||||
"Callable",
|
||||
"Collection",
|
||||
"Set",
|
||||
"MutableSet",
|
||||
"Mapping",
|
||||
"MutableMapping",
|
||||
"MappingView",
|
||||
"KeysView",
|
||||
"ItemsView",
|
||||
"ValuesView",
|
||||
"Sequence",
|
||||
"MutableSequence",
|
||||
]
|
||||
if sys.version_info < (3, 14):
|
||||
from typing import ByteString as ByteString # noqa: Y057,UP035
|
||||
|
||||
__all__ += ["ByteString"]
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
__all__ += ["Buffer"]
|
||||
|
||||
_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
|
||||
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
|
||||
|
||||
@final
|
||||
class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented
|
||||
def __eq__(self, value: object, /) -> bool: ...
|
||||
def __reversed__(self) -> Iterator[_KT_co]: ...
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
if sys.version_info >= (3, 13):
|
||||
def isdisjoint(self, other: Iterable[_KT_co], /) -> bool: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@property
|
||||
def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ...
|
||||
|
||||
@final
|
||||
class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented
|
||||
def __reversed__(self) -> Iterator[_VT_co]: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@property
|
||||
def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ...
|
||||
|
||||
@final
|
||||
class dict_items(ItemsView[_KT_co, _VT_co]): # undocumented
|
||||
def __eq__(self, value: object, /) -> bool: ...
|
||||
def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
if sys.version_info >= (3, 13):
|
||||
def isdisjoint(self, other: Iterable[tuple[_KT_co, _VT_co]], /) -> bool: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@property
|
||||
def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
@runtime_checkable
|
||||
class Buffer(Protocol):
|
||||
@abstractmethod
|
||||
def __buffer__(self, flags: int, /) -> memoryview: ...
|
||||
8
crates/red_knot_vendored/vendor/typeshed/stdlib/_compat_pickle.pyi
vendored
Normal file
8
crates/red_knot_vendored/vendor/typeshed/stdlib/_compat_pickle.pyi
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
IMPORT_MAPPING: dict[str, str]
|
||||
NAME_MAPPING: dict[tuple[str, str], tuple[str, str]]
|
||||
PYTHON2_EXCEPTIONS: tuple[str, ...]
|
||||
MULTIPROCESSING_EXCEPTIONS: tuple[str, ...]
|
||||
REVERSE_IMPORT_MAPPING: dict[str, str]
|
||||
REVERSE_NAME_MAPPING: dict[tuple[str, str], tuple[str, str]]
|
||||
PYTHON3_OSERROR_EXCEPTIONS: tuple[str, ...]
|
||||
PYTHON3_IMPORTERROR_EXCEPTIONS: tuple[str, ...]
|
||||
25
crates/red_knot_vendored/vendor/typeshed/stdlib/_compression.pyi
vendored
Normal file
25
crates/red_knot_vendored/vendor/typeshed/stdlib/_compression.pyi
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
from _typeshed import WriteableBuffer
|
||||
from collections.abc import Callable
|
||||
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
|
||||
from typing import Any, Protocol
|
||||
|
||||
BUFFER_SIZE = DEFAULT_BUFFER_SIZE
|
||||
|
||||
class _Reader(Protocol):
|
||||
def read(self, n: int, /) -> bytes: ...
|
||||
def seekable(self) -> bool: ...
|
||||
def seek(self, n: int, /) -> Any: ...
|
||||
|
||||
class BaseStream(BufferedIOBase): ...
|
||||
|
||||
class DecompressReader(RawIOBase):
|
||||
def __init__(
|
||||
self,
|
||||
fp: _Reader,
|
||||
decomp_factory: Callable[..., object],
|
||||
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
|
||||
**decomp_args: Any,
|
||||
) -> None: ...
|
||||
def readinto(self, b: WriteableBuffer) -> int: ...
|
||||
def read(self, size: int = -1) -> bytes: ...
|
||||
def seek(self, offset: int, whence: int = 0) -> int: ...
|
||||
58
crates/red_knot_vendored/vendor/typeshed/stdlib/_contextvars.pyi
vendored
Normal file
58
crates/red_knot_vendored/vendor/typeshed/stdlib/_contextvars.pyi
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
from collections.abc import Callable, Iterator, Mapping
|
||||
from types import GenericAlias
|
||||
from typing import Any, ClassVar, Generic, TypeVar, final, overload
|
||||
from typing_extensions import ParamSpec, Self
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_D = TypeVar("_D")
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
@final
|
||||
class ContextVar(Generic[_T]):
|
||||
@overload
|
||||
def __new__(cls, name: str) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls, name: str, *, default: _T) -> Self: ...
|
||||
def __hash__(self) -> int: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
@overload
|
||||
def get(self) -> _T: ...
|
||||
@overload
|
||||
def get(self, default: _T, /) -> _T: ...
|
||||
@overload
|
||||
def get(self, default: _D, /) -> _D | _T: ...
|
||||
def set(self, value: _T, /) -> Token[_T]: ...
|
||||
def reset(self, token: Token[_T], /) -> None: ...
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
@final
|
||||
class Token(Generic[_T]):
|
||||
@property
|
||||
def var(self) -> ContextVar[_T]: ...
|
||||
@property
|
||||
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
|
||||
MISSING: ClassVar[object]
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
def copy_context() -> Context: ...
|
||||
|
||||
# It doesn't make sense to make this generic, because for most Contexts each ContextVar will have
|
||||
# a different value.
|
||||
@final
|
||||
class Context(Mapping[ContextVar[Any], Any]):
|
||||
def __init__(self) -> None: ...
|
||||
@overload
|
||||
def get(self, key: ContextVar[_T], default: None = None, /) -> _T | None: ...
|
||||
@overload
|
||||
def get(self, key: ContextVar[_T], default: _T, /) -> _T: ...
|
||||
@overload
|
||||
def get(self, key: ContextVar[_T], default: _D, /) -> _T | _D: ...
|
||||
def run(self, callable: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ...
|
||||
def copy(self) -> Context: ...
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
def __getitem__(self, key: ContextVar[_T], /) -> _T: ...
|
||||
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __eq__(self, value: object, /) -> bool: ...
|
||||
132
crates/red_knot_vendored/vendor/typeshed/stdlib/_csv.pyi
vendored
Normal file
132
crates/red_knot_vendored/vendor/typeshed/stdlib/_csv.pyi
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
import csv
|
||||
import sys
|
||||
from _typeshed import SupportsWrite
|
||||
from collections.abc import Iterable
|
||||
from typing import Any, Final, type_check_only
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
__version__: Final[str]
|
||||
|
||||
QUOTE_ALL: Final = 1
|
||||
QUOTE_MINIMAL: Final = 0
|
||||
QUOTE_NONE: Final = 3
|
||||
QUOTE_NONNUMERIC: Final = 2
|
||||
if sys.version_info >= (3, 12):
|
||||
QUOTE_STRINGS: Final = 4
|
||||
QUOTE_NOTNULL: Final = 5
|
||||
|
||||
# Ideally this would be `QUOTE_ALL | QUOTE_MINIMAL | QUOTE_NONE | QUOTE_NONNUMERIC`
|
||||
# However, using literals in situations like these can cause false-positives (see #7258)
|
||||
_QuotingType: TypeAlias = int
|
||||
|
||||
class Error(Exception): ...
|
||||
|
||||
_DialectLike: TypeAlias = str | Dialect | csv.Dialect | type[Dialect | csv.Dialect]
|
||||
|
||||
class Dialect:
|
||||
delimiter: str
|
||||
quotechar: str | None
|
||||
escapechar: str | None
|
||||
doublequote: bool
|
||||
skipinitialspace: bool
|
||||
lineterminator: str
|
||||
quoting: _QuotingType
|
||||
strict: bool
|
||||
def __new__(
|
||||
cls,
|
||||
dialect: _DialectLike | None = ...,
|
||||
delimiter: str = ",",
|
||||
doublequote: bool = True,
|
||||
escapechar: str | None = None,
|
||||
lineterminator: str = "\r\n",
|
||||
quotechar: str | None = '"',
|
||||
quoting: _QuotingType = 0,
|
||||
skipinitialspace: bool = False,
|
||||
strict: bool = False,
|
||||
) -> Self: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
# This class calls itself _csv.reader.
|
||||
class Reader:
|
||||
@property
|
||||
def dialect(self) -> Dialect: ...
|
||||
line_num: int
|
||||
def __iter__(self) -> Self: ...
|
||||
def __next__(self) -> list[str]: ...
|
||||
|
||||
# This class calls itself _csv.writer.
|
||||
class Writer:
|
||||
@property
|
||||
def dialect(self) -> Dialect: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
def writerow(self, row: Iterable[Any], /) -> Any: ...
|
||||
def writerows(self, rows: Iterable[Iterable[Any]], /) -> None: ...
|
||||
else:
|
||||
def writerow(self, row: Iterable[Any]) -> Any: ...
|
||||
def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ...
|
||||
|
||||
# For the return types below.
|
||||
# These aliases can be removed when typeshed drops support for 3.9.
|
||||
_reader = Reader
|
||||
_writer = Writer
|
||||
else:
|
||||
# This class is not exposed. It calls itself _csv.reader.
|
||||
@type_check_only
|
||||
class _reader:
|
||||
@property
|
||||
def dialect(self) -> Dialect: ...
|
||||
line_num: int
|
||||
def __iter__(self) -> Self: ...
|
||||
def __next__(self) -> list[str]: ...
|
||||
|
||||
# This class is not exposed. It calls itself _csv.writer.
|
||||
@type_check_only
|
||||
class _writer:
|
||||
@property
|
||||
def dialect(self) -> Dialect: ...
|
||||
def writerow(self, row: Iterable[Any]) -> Any: ...
|
||||
def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ...
|
||||
|
||||
def writer(
|
||||
csvfile: SupportsWrite[str],
|
||||
dialect: _DialectLike = "excel",
|
||||
*,
|
||||
delimiter: str = ",",
|
||||
quotechar: str | None = '"',
|
||||
escapechar: str | None = None,
|
||||
doublequote: bool = True,
|
||||
skipinitialspace: bool = False,
|
||||
lineterminator: str = "\r\n",
|
||||
quoting: _QuotingType = 0,
|
||||
strict: bool = False,
|
||||
) -> _writer: ...
|
||||
def reader(
|
||||
csvfile: Iterable[str],
|
||||
dialect: _DialectLike = "excel",
|
||||
*,
|
||||
delimiter: str = ",",
|
||||
quotechar: str | None = '"',
|
||||
escapechar: str | None = None,
|
||||
doublequote: bool = True,
|
||||
skipinitialspace: bool = False,
|
||||
lineterminator: str = "\r\n",
|
||||
quoting: _QuotingType = 0,
|
||||
strict: bool = False,
|
||||
) -> _reader: ...
|
||||
def register_dialect(
|
||||
name: str,
|
||||
dialect: type[Dialect | csv.Dialect] = ...,
|
||||
*,
|
||||
delimiter: str = ",",
|
||||
quotechar: str | None = '"',
|
||||
escapechar: str | None = None,
|
||||
doublequote: bool = True,
|
||||
skipinitialspace: bool = False,
|
||||
lineterminator: str = "\r\n",
|
||||
quoting: _QuotingType = 0,
|
||||
strict: bool = False,
|
||||
) -> None: ...
|
||||
def unregister_dialect(name: str) -> None: ...
|
||||
def get_dialect(name: str) -> Dialect: ...
|
||||
def list_dialects() -> list[str]: ...
|
||||
def field_size_limit(new_limit: int = ...) -> int: ...
|
||||
331
crates/red_knot_vendored/vendor/typeshed/stdlib/_ctypes.pyi
vendored
Normal file
331
crates/red_knot_vendored/vendor/typeshed/stdlib/_ctypes.pyi
vendored
Normal file
@@ -0,0 +1,331 @@
|
||||
import _typeshed
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
|
||||
from abc import abstractmethod
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
|
||||
from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p
|
||||
from types import GenericAlias
|
||||
from typing import Any, ClassVar, Generic, TypeVar, final, overload, type_check_only
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_CT = TypeVar("_CT", bound=_CData)
|
||||
|
||||
FUNCFLAG_CDECL: int
|
||||
FUNCFLAG_PYTHONAPI: int
|
||||
FUNCFLAG_USE_ERRNO: int
|
||||
FUNCFLAG_USE_LASTERROR: int
|
||||
RTLD_GLOBAL: int
|
||||
RTLD_LOCAL: int
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
CTYPES_MAX_ARGCOUNT: int
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
SIZEOF_TIME_T: int
|
||||
|
||||
if sys.platform == "win32":
|
||||
# Description, Source, HelpFile, HelpContext, scode
|
||||
_COMError_Details: TypeAlias = tuple[str | None, str | None, str | None, int | None, int | None]
|
||||
|
||||
class COMError(Exception):
|
||||
hresult: int
|
||||
text: str | None
|
||||
details: _COMError_Details
|
||||
|
||||
def __init__(self, hresult: int, text: str | None, details: _COMError_Details) -> None: ...
|
||||
|
||||
def CopyComPointer(src: _PointerLike, dst: _PointerLike | _CArgObject) -> int: ...
|
||||
|
||||
FUNCFLAG_HRESULT: int
|
||||
FUNCFLAG_STDCALL: int
|
||||
|
||||
def FormatError(code: int = ...) -> str: ...
|
||||
def get_last_error() -> int: ...
|
||||
def set_last_error(value: int) -> int: ...
|
||||
def LoadLibrary(name: str, load_flags: int = 0, /) -> int: ...
|
||||
def FreeLibrary(handle: int, /) -> None: ...
|
||||
|
||||
else:
|
||||
def dlclose(handle: int, /) -> None: ...
|
||||
# The default for flag is RTLD_GLOBAL|RTLD_LOCAL, which is platform dependent.
|
||||
def dlopen(name: StrOrBytesPath, flag: int = ..., /) -> int: ...
|
||||
def dlsym(handle: int, name: str, /) -> int: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
# This class is not exposed. It calls itself _ctypes.CType_Type.
|
||||
@type_check_only
|
||||
class _CType_Type(type):
|
||||
# By default mypy complains about the following two methods, because strictly speaking cls
|
||||
# might not be a Type[_CT]. However this doesn't happen because this is only a
|
||||
# metaclass for subclasses of _CData.
|
||||
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
|
||||
_CTypeBaseType = _CType_Type
|
||||
|
||||
else:
|
||||
_CTypeBaseType = type
|
||||
|
||||
# This class is not exposed.
|
||||
@type_check_only
|
||||
class _CData:
|
||||
_b_base_: int
|
||||
_b_needsfree_: bool
|
||||
_objects: Mapping[Any, int] | None
|
||||
def __buffer__(self, flags: int, /) -> memoryview: ...
|
||||
def __ctypes_from_outparam__(self, /) -> Self: ...
|
||||
|
||||
# this is a union of all the subclasses of _CData, which is useful because of
|
||||
# the methods that are present on each of those subclasses which are not present
|
||||
# on _CData itself.
|
||||
_CDataType: TypeAlias = _SimpleCData[Any] | _Pointer[Any] | CFuncPtr | Union | Structure | Array[Any]
|
||||
|
||||
# This class is not exposed. It calls itself _ctypes.PyCSimpleType.
|
||||
@type_check_only
|
||||
class _PyCSimpleType(_CTypeBaseType):
|
||||
def from_address(self: type[_typeshed.Self], value: int, /) -> _typeshed.Self: ...
|
||||
def from_buffer(self: type[_typeshed.Self], obj: WriteableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_buffer_copy(self: type[_typeshed.Self], buffer: ReadableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_param(self: type[_typeshed.Self], value: Any, /) -> _typeshed.Self | _CArgObject: ...
|
||||
def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ...
|
||||
if sys.version_info < (3, 13):
|
||||
# Inherited from CType_Type starting on 3.13
|
||||
def __mul__(self: type[_CT], value: int, /) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
def __rmul__(self: type[_CT], value: int, /) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
|
||||
class _SimpleCData(_CData, Generic[_T], metaclass=_PyCSimpleType):
|
||||
value: _T
|
||||
# The TypeVar can be unsolved here,
|
||||
# but we can't use overloads without creating many, many mypy false-positive errors
|
||||
def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse]
|
||||
def __ctypes_from_outparam__(self, /) -> _T: ... # type: ignore[override]
|
||||
|
||||
class _CanCastTo(_CData): ...
|
||||
class _PointerLike(_CanCastTo): ...
|
||||
|
||||
# This type is not exposed. It calls itself _ctypes.PyCPointerType.
|
||||
@type_check_only
|
||||
class _PyCPointerType(_CTypeBaseType):
|
||||
def from_address(self: type[_typeshed.Self], value: int, /) -> _typeshed.Self: ...
|
||||
def from_buffer(self: type[_typeshed.Self], obj: WriteableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_buffer_copy(self: type[_typeshed.Self], buffer: ReadableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_param(self: type[_typeshed.Self], value: Any, /) -> _typeshed.Self | _CArgObject: ...
|
||||
def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ...
|
||||
def set_type(self, type: Any, /) -> None: ...
|
||||
if sys.version_info < (3, 13):
|
||||
# Inherited from CType_Type starting on 3.13
|
||||
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
|
||||
class _Pointer(_PointerLike, _CData, Generic[_CT], metaclass=_PyCPointerType):
|
||||
_type_: type[_CT]
|
||||
contents: _CT
|
||||
@overload
|
||||
def __init__(self) -> None: ...
|
||||
@overload
|
||||
def __init__(self, arg: _CT) -> None: ...
|
||||
@overload
|
||||
def __getitem__(self, key: int, /) -> Any: ...
|
||||
@overload
|
||||
def __getitem__(self, key: slice, /) -> list[Any]: ...
|
||||
def __setitem__(self, key: int, value: Any, /) -> None: ...
|
||||
|
||||
@overload
|
||||
def POINTER(type: None, /) -> type[c_void_p]: ...
|
||||
@overload
|
||||
def POINTER(type: type[_CT], /) -> type[_Pointer[_CT]]: ...
|
||||
def pointer(obj: _CT, /) -> _Pointer[_CT]: ...
|
||||
|
||||
# This class is not exposed. It calls itself _ctypes.CArgObject.
|
||||
@final
|
||||
@type_check_only
|
||||
class _CArgObject: ...
|
||||
|
||||
def byref(obj: _CData | _CDataType, offset: int = ...) -> _CArgObject: ...
|
||||
|
||||
_ECT: TypeAlias = Callable[[_CData | _CDataType | None, CFuncPtr, tuple[_CData | _CDataType, ...]], _CDataType]
|
||||
_PF: TypeAlias = tuple[int] | tuple[int, str | None] | tuple[int, str | None, Any]
|
||||
|
||||
# This class is not exposed. It calls itself _ctypes.PyCFuncPtrType.
|
||||
@type_check_only
|
||||
class _PyCFuncPtrType(_CTypeBaseType):
|
||||
def from_address(self: type[_typeshed.Self], value: int, /) -> _typeshed.Self: ...
|
||||
def from_buffer(self: type[_typeshed.Self], obj: WriteableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_buffer_copy(self: type[_typeshed.Self], buffer: ReadableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_param(self: type[_typeshed.Self], value: Any, /) -> _typeshed.Self | _CArgObject: ...
|
||||
def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ...
|
||||
if sys.version_info < (3, 13):
|
||||
# Inherited from CType_Type starting on 3.13
|
||||
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
|
||||
class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType):
|
||||
restype: type[_CDataType] | Callable[[int], Any] | None
|
||||
argtypes: Sequence[type[_CDataType]]
|
||||
errcheck: _ECT
|
||||
# Abstract attribute that must be defined on subclasses
|
||||
_flags_: ClassVar[int]
|
||||
@overload
|
||||
def __new__(cls) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls, address: int, /) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls, callable: Callable[..., Any], /) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> Self: ...
|
||||
if sys.platform == "win32":
|
||||
@overload
|
||||
def __new__(
|
||||
cls, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
|
||||
) -> Self: ...
|
||||
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
|
||||
_GetT = TypeVar("_GetT")
|
||||
_SetT = TypeVar("_SetT")
|
||||
|
||||
# This class is not exposed. It calls itself _ctypes.CField.
|
||||
@final
|
||||
@type_check_only
|
||||
class _CField(Generic[_CT, _GetT, _SetT]):
|
||||
offset: int
|
||||
size: int
|
||||
if sys.version_info >= (3, 10):
|
||||
@overload
|
||||
def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ...
|
||||
@overload
|
||||
def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ...
|
||||
else:
|
||||
@overload
|
||||
def __get__(self, instance: None, owner: type[Any] | None, /) -> Self: ...
|
||||
@overload
|
||||
def __get__(self, instance: Any, owner: type[Any] | None, /) -> _GetT: ...
|
||||
|
||||
def __set__(self, instance: Any, value: _SetT, /) -> None: ...
|
||||
|
||||
# This class is not exposed. It calls itself _ctypes.UnionType.
|
||||
@type_check_only
|
||||
class _UnionType(_CTypeBaseType):
|
||||
def from_address(self: type[_typeshed.Self], value: int, /) -> _typeshed.Self: ...
|
||||
def from_buffer(self: type[_typeshed.Self], obj: WriteableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_buffer_copy(self: type[_typeshed.Self], buffer: ReadableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_param(self: type[_typeshed.Self], value: Any, /) -> _typeshed.Self | _CArgObject: ...
|
||||
def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ...
|
||||
# At runtime, various attributes are created on a Union subclass based
|
||||
# on its _fields_. This method doesn't exist, but represents those
|
||||
# dynamically created attributes.
|
||||
def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ...
|
||||
if sys.version_info < (3, 13):
|
||||
# Inherited from CType_Type starting on 3.13
|
||||
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
|
||||
class Union(_CData, metaclass=_UnionType):
|
||||
_fields_: ClassVar[Sequence[tuple[str, type[_CDataType]] | tuple[str, type[_CDataType], int]]]
|
||||
_pack_: ClassVar[int]
|
||||
_anonymous_: ClassVar[Sequence[str]]
|
||||
if sys.version_info >= (3, 13):
|
||||
_align_: ClassVar[int]
|
||||
|
||||
def __init__(self, *args: Any, **kw: Any) -> None: ...
|
||||
def __getattr__(self, name: str) -> Any: ...
|
||||
def __setattr__(self, name: str, value: Any) -> None: ...
|
||||
|
||||
# This class is not exposed. It calls itself _ctypes.PyCStructType.
|
||||
@type_check_only
|
||||
class _PyCStructType(_CTypeBaseType):
|
||||
def from_address(self: type[_typeshed.Self], value: int, /) -> _typeshed.Self: ...
|
||||
def from_buffer(self: type[_typeshed.Self], obj: WriteableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_buffer_copy(self: type[_typeshed.Self], buffer: ReadableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_param(self: type[_typeshed.Self], value: Any, /) -> _typeshed.Self | _CArgObject: ...
|
||||
def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ...
|
||||
# At runtime, various attributes are created on a Structure subclass based
|
||||
# on its _fields_. This method doesn't exist, but represents those
|
||||
# dynamically created attributes.
|
||||
def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ...
|
||||
if sys.version_info < (3, 13):
|
||||
# Inherited from CType_Type starting on 3.13
|
||||
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
|
||||
class Structure(_CData, metaclass=_PyCStructType):
|
||||
_fields_: ClassVar[Sequence[tuple[str, type[_CDataType]] | tuple[str, type[_CDataType], int]]]
|
||||
_pack_: ClassVar[int]
|
||||
_anonymous_: ClassVar[Sequence[str]]
|
||||
if sys.version_info >= (3, 13):
|
||||
_align_: ClassVar[int]
|
||||
|
||||
def __init__(self, *args: Any, **kw: Any) -> None: ...
|
||||
def __getattr__(self, name: str) -> Any: ...
|
||||
def __setattr__(self, name: str, value: Any) -> None: ...
|
||||
|
||||
# This class is not exposed. It calls itself _ctypes.PyCArrayType.
|
||||
@type_check_only
|
||||
class _PyCArrayType(_CTypeBaseType):
|
||||
def from_address(self: type[_typeshed.Self], value: int, /) -> _typeshed.Self: ...
|
||||
def from_buffer(self: type[_typeshed.Self], obj: WriteableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_buffer_copy(self: type[_typeshed.Self], buffer: ReadableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
|
||||
def from_param(self: type[_typeshed.Self], value: Any, /) -> _typeshed.Self | _CArgObject: ...
|
||||
def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ...
|
||||
if sys.version_info < (3, 13):
|
||||
# Inherited from CType_Type starting on 3.13
|
||||
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
||||
|
||||
class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
|
||||
@property
|
||||
@abstractmethod
|
||||
def _length_(self) -> int: ...
|
||||
@_length_.setter
|
||||
def _length_(self, value: int) -> None: ...
|
||||
@property
|
||||
@abstractmethod
|
||||
def _type_(self) -> type[_CT]: ...
|
||||
@_type_.setter
|
||||
def _type_(self, value: type[_CT]) -> None: ...
|
||||
# Note: only available if _CT == c_char
|
||||
@property
|
||||
def raw(self) -> bytes: ...
|
||||
@raw.setter
|
||||
def raw(self, value: ReadableBuffer) -> None: ...
|
||||
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
|
||||
# TODO: These methods cannot be annotated correctly at the moment.
|
||||
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
|
||||
# here, because of a special feature of ctypes.
|
||||
# By default, when accessing an element of an Array[_CT], the returned object has type _CT.
|
||||
# However, when _CT is a "simple type" like c_int, ctypes automatically "unboxes" the object
|
||||
# and converts it to the corresponding Python primitive. For example, when accessing an element
|
||||
# of an Array[c_int], a Python int object is returned, not a c_int.
|
||||
# This behavior does *not* apply to subclasses of "simple types".
|
||||
# If MyInt is a subclass of c_int, then accessing an element of an Array[MyInt] returns
|
||||
# a MyInt, not an int.
|
||||
# This special behavior is not easy to model in a stub, so for now all places where
|
||||
# the array element type would belong are annotated with Any instead.
|
||||
def __init__(self, *args: Any) -> None: ...
|
||||
@overload
|
||||
def __getitem__(self, key: int, /) -> Any: ...
|
||||
@overload
|
||||
def __getitem__(self, key: slice, /) -> list[Any]: ...
|
||||
@overload
|
||||
def __setitem__(self, key: int, value: Any, /) -> None: ...
|
||||
@overload
|
||||
def __setitem__(self, key: slice, value: Iterable[Any], /) -> None: ...
|
||||
def __iter__(self) -> Iterator[Any]: ...
|
||||
# Can't inherit from Sized because the metaclass conflict between
|
||||
# Sized and _CData prevents using _CDataMeta.
|
||||
def __len__(self) -> int: ...
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
def addressof(obj: _CData | _CDataType, /) -> int: ...
|
||||
def alignment(obj_or_type: _CData | _CDataType | type[_CData | _CDataType], /) -> int: ...
|
||||
def get_errno() -> int: ...
|
||||
def resize(obj: _CData | _CDataType, size: int, /) -> None: ...
|
||||
def set_errno(value: int, /) -> int: ...
|
||||
def sizeof(obj_or_type: _CData | _CDataType | type[_CData | _CDataType], /) -> int: ...
|
||||
def PyObj_FromPtr(address: int, /) -> Any: ...
|
||||
def Py_DECREF(o: _T, /) -> _T: ...
|
||||
def Py_INCREF(o: _T, /) -> _T: ...
|
||||
def buffer_info(o: _CData | _CDataType | type[_CData | _CDataType], /) -> tuple[str, int, tuple[int, ...]]: ...
|
||||
def call_cdeclfunction(address: int, arguments: tuple[Any, ...], /) -> Any: ...
|
||||
def call_function(address: int, arguments: tuple[Any, ...], /) -> Any: ...
|
||||
548
crates/red_knot_vendored/vendor/typeshed/stdlib/_curses.pyi
vendored
Normal file
548
crates/red_knot_vendored/vendor/typeshed/stdlib/_curses.pyi
vendored
Normal file
@@ -0,0 +1,548 @@
|
||||
import sys
|
||||
from _typeshed import ReadOnlyBuffer, SupportsRead, SupportsWrite
|
||||
from curses import _ncurses_version
|
||||
from typing import Any, final, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
# NOTE: This module is ordinarily only available on Unix, but the windows-curses
|
||||
# package makes it available on Windows as well with the same contents.
|
||||
|
||||
# Handled by PyCurses_ConvertToChtype in _cursesmodule.c.
|
||||
_ChType: TypeAlias = str | bytes | int
|
||||
|
||||
# ACS codes are only initialized after initscr is called
|
||||
ACS_BBSS: int
|
||||
ACS_BLOCK: int
|
||||
ACS_BOARD: int
|
||||
ACS_BSBS: int
|
||||
ACS_BSSB: int
|
||||
ACS_BSSS: int
|
||||
ACS_BTEE: int
|
||||
ACS_BULLET: int
|
||||
ACS_CKBOARD: int
|
||||
ACS_DARROW: int
|
||||
ACS_DEGREE: int
|
||||
ACS_DIAMOND: int
|
||||
ACS_GEQUAL: int
|
||||
ACS_HLINE: int
|
||||
ACS_LANTERN: int
|
||||
ACS_LARROW: int
|
||||
ACS_LEQUAL: int
|
||||
ACS_LLCORNER: int
|
||||
ACS_LRCORNER: int
|
||||
ACS_LTEE: int
|
||||
ACS_NEQUAL: int
|
||||
ACS_PI: int
|
||||
ACS_PLMINUS: int
|
||||
ACS_PLUS: int
|
||||
ACS_RARROW: int
|
||||
ACS_RTEE: int
|
||||
ACS_S1: int
|
||||
ACS_S3: int
|
||||
ACS_S7: int
|
||||
ACS_S9: int
|
||||
ACS_SBBS: int
|
||||
ACS_SBSB: int
|
||||
ACS_SBSS: int
|
||||
ACS_SSBB: int
|
||||
ACS_SSBS: int
|
||||
ACS_SSSB: int
|
||||
ACS_SSSS: int
|
||||
ACS_STERLING: int
|
||||
ACS_TTEE: int
|
||||
ACS_UARROW: int
|
||||
ACS_ULCORNER: int
|
||||
ACS_URCORNER: int
|
||||
ACS_VLINE: int
|
||||
ALL_MOUSE_EVENTS: int
|
||||
A_ALTCHARSET: int
|
||||
A_ATTRIBUTES: int
|
||||
A_BLINK: int
|
||||
A_BOLD: int
|
||||
A_CHARTEXT: int
|
||||
A_COLOR: int
|
||||
A_DIM: int
|
||||
A_HORIZONTAL: int
|
||||
A_INVIS: int
|
||||
A_ITALIC: int
|
||||
A_LEFT: int
|
||||
A_LOW: int
|
||||
A_NORMAL: int
|
||||
A_PROTECT: int
|
||||
A_REVERSE: int
|
||||
A_RIGHT: int
|
||||
A_STANDOUT: int
|
||||
A_TOP: int
|
||||
A_UNDERLINE: int
|
||||
A_VERTICAL: int
|
||||
BUTTON1_CLICKED: int
|
||||
BUTTON1_DOUBLE_CLICKED: int
|
||||
BUTTON1_PRESSED: int
|
||||
BUTTON1_RELEASED: int
|
||||
BUTTON1_TRIPLE_CLICKED: int
|
||||
BUTTON2_CLICKED: int
|
||||
BUTTON2_DOUBLE_CLICKED: int
|
||||
BUTTON2_PRESSED: int
|
||||
BUTTON2_RELEASED: int
|
||||
BUTTON2_TRIPLE_CLICKED: int
|
||||
BUTTON3_CLICKED: int
|
||||
BUTTON3_DOUBLE_CLICKED: int
|
||||
BUTTON3_PRESSED: int
|
||||
BUTTON3_RELEASED: int
|
||||
BUTTON3_TRIPLE_CLICKED: int
|
||||
BUTTON4_CLICKED: int
|
||||
BUTTON4_DOUBLE_CLICKED: int
|
||||
BUTTON4_PRESSED: int
|
||||
BUTTON4_RELEASED: int
|
||||
BUTTON4_TRIPLE_CLICKED: int
|
||||
# Darwin ncurses doesn't provide BUTTON5_* constants prior to 3.12.10 and 3.13.3
|
||||
if sys.version_info >= (3, 10):
|
||||
if sys.version_info >= (3, 12) or sys.platform != "darwin":
|
||||
BUTTON5_PRESSED: int
|
||||
BUTTON5_RELEASED: int
|
||||
BUTTON5_CLICKED: int
|
||||
BUTTON5_DOUBLE_CLICKED: int
|
||||
BUTTON5_TRIPLE_CLICKED: int
|
||||
BUTTON_ALT: int
|
||||
BUTTON_CTRL: int
|
||||
BUTTON_SHIFT: int
|
||||
COLOR_BLACK: int
|
||||
COLOR_BLUE: int
|
||||
COLOR_CYAN: int
|
||||
COLOR_GREEN: int
|
||||
COLOR_MAGENTA: int
|
||||
COLOR_RED: int
|
||||
COLOR_WHITE: int
|
||||
COLOR_YELLOW: int
|
||||
ERR: int
|
||||
KEY_A1: int
|
||||
KEY_A3: int
|
||||
KEY_B2: int
|
||||
KEY_BACKSPACE: int
|
||||
KEY_BEG: int
|
||||
KEY_BREAK: int
|
||||
KEY_BTAB: int
|
||||
KEY_C1: int
|
||||
KEY_C3: int
|
||||
KEY_CANCEL: int
|
||||
KEY_CATAB: int
|
||||
KEY_CLEAR: int
|
||||
KEY_CLOSE: int
|
||||
KEY_COMMAND: int
|
||||
KEY_COPY: int
|
||||
KEY_CREATE: int
|
||||
KEY_CTAB: int
|
||||
KEY_DC: int
|
||||
KEY_DL: int
|
||||
KEY_DOWN: int
|
||||
KEY_EIC: int
|
||||
KEY_END: int
|
||||
KEY_ENTER: int
|
||||
KEY_EOL: int
|
||||
KEY_EOS: int
|
||||
KEY_EXIT: int
|
||||
KEY_F0: int
|
||||
KEY_F1: int
|
||||
KEY_F10: int
|
||||
KEY_F11: int
|
||||
KEY_F12: int
|
||||
KEY_F13: int
|
||||
KEY_F14: int
|
||||
KEY_F15: int
|
||||
KEY_F16: int
|
||||
KEY_F17: int
|
||||
KEY_F18: int
|
||||
KEY_F19: int
|
||||
KEY_F2: int
|
||||
KEY_F20: int
|
||||
KEY_F21: int
|
||||
KEY_F22: int
|
||||
KEY_F23: int
|
||||
KEY_F24: int
|
||||
KEY_F25: int
|
||||
KEY_F26: int
|
||||
KEY_F27: int
|
||||
KEY_F28: int
|
||||
KEY_F29: int
|
||||
KEY_F3: int
|
||||
KEY_F30: int
|
||||
KEY_F31: int
|
||||
KEY_F32: int
|
||||
KEY_F33: int
|
||||
KEY_F34: int
|
||||
KEY_F35: int
|
||||
KEY_F36: int
|
||||
KEY_F37: int
|
||||
KEY_F38: int
|
||||
KEY_F39: int
|
||||
KEY_F4: int
|
||||
KEY_F40: int
|
||||
KEY_F41: int
|
||||
KEY_F42: int
|
||||
KEY_F43: int
|
||||
KEY_F44: int
|
||||
KEY_F45: int
|
||||
KEY_F46: int
|
||||
KEY_F47: int
|
||||
KEY_F48: int
|
||||
KEY_F49: int
|
||||
KEY_F5: int
|
||||
KEY_F50: int
|
||||
KEY_F51: int
|
||||
KEY_F52: int
|
||||
KEY_F53: int
|
||||
KEY_F54: int
|
||||
KEY_F55: int
|
||||
KEY_F56: int
|
||||
KEY_F57: int
|
||||
KEY_F58: int
|
||||
KEY_F59: int
|
||||
KEY_F6: int
|
||||
KEY_F60: int
|
||||
KEY_F61: int
|
||||
KEY_F62: int
|
||||
KEY_F63: int
|
||||
KEY_F7: int
|
||||
KEY_F8: int
|
||||
KEY_F9: int
|
||||
KEY_FIND: int
|
||||
KEY_HELP: int
|
||||
KEY_HOME: int
|
||||
KEY_IC: int
|
||||
KEY_IL: int
|
||||
KEY_LEFT: int
|
||||
KEY_LL: int
|
||||
KEY_MARK: int
|
||||
KEY_MAX: int
|
||||
KEY_MESSAGE: int
|
||||
KEY_MIN: int
|
||||
KEY_MOUSE: int
|
||||
KEY_MOVE: int
|
||||
KEY_NEXT: int
|
||||
KEY_NPAGE: int
|
||||
KEY_OPEN: int
|
||||
KEY_OPTIONS: int
|
||||
KEY_PPAGE: int
|
||||
KEY_PREVIOUS: int
|
||||
KEY_PRINT: int
|
||||
KEY_REDO: int
|
||||
KEY_REFERENCE: int
|
||||
KEY_REFRESH: int
|
||||
KEY_REPLACE: int
|
||||
KEY_RESET: int
|
||||
KEY_RESIZE: int
|
||||
KEY_RESTART: int
|
||||
KEY_RESUME: int
|
||||
KEY_RIGHT: int
|
||||
KEY_SAVE: int
|
||||
KEY_SBEG: int
|
||||
KEY_SCANCEL: int
|
||||
KEY_SCOMMAND: int
|
||||
KEY_SCOPY: int
|
||||
KEY_SCREATE: int
|
||||
KEY_SDC: int
|
||||
KEY_SDL: int
|
||||
KEY_SELECT: int
|
||||
KEY_SEND: int
|
||||
KEY_SEOL: int
|
||||
KEY_SEXIT: int
|
||||
KEY_SF: int
|
||||
KEY_SFIND: int
|
||||
KEY_SHELP: int
|
||||
KEY_SHOME: int
|
||||
KEY_SIC: int
|
||||
KEY_SLEFT: int
|
||||
KEY_SMESSAGE: int
|
||||
KEY_SMOVE: int
|
||||
KEY_SNEXT: int
|
||||
KEY_SOPTIONS: int
|
||||
KEY_SPREVIOUS: int
|
||||
KEY_SPRINT: int
|
||||
KEY_SR: int
|
||||
KEY_SREDO: int
|
||||
KEY_SREPLACE: int
|
||||
KEY_SRESET: int
|
||||
KEY_SRIGHT: int
|
||||
KEY_SRSUME: int
|
||||
KEY_SSAVE: int
|
||||
KEY_SSUSPEND: int
|
||||
KEY_STAB: int
|
||||
KEY_SUNDO: int
|
||||
KEY_SUSPEND: int
|
||||
KEY_UNDO: int
|
||||
KEY_UP: int
|
||||
OK: int
|
||||
REPORT_MOUSE_POSITION: int
|
||||
_C_API: Any
|
||||
version: bytes
|
||||
|
||||
def baudrate() -> int: ...
|
||||
def beep() -> None: ...
|
||||
def can_change_color() -> bool: ...
|
||||
def cbreak(flag: bool = True, /) -> None: ...
|
||||
def color_content(color_number: int, /) -> tuple[int, int, int]: ...
|
||||
def color_pair(pair_number: int, /) -> int: ...
|
||||
def curs_set(visibility: int, /) -> int: ...
|
||||
def def_prog_mode() -> None: ...
|
||||
def def_shell_mode() -> None: ...
|
||||
def delay_output(ms: int, /) -> None: ...
|
||||
def doupdate() -> None: ...
|
||||
def echo(flag: bool = True, /) -> None: ...
|
||||
def endwin() -> None: ...
|
||||
def erasechar() -> bytes: ...
|
||||
def filter() -> None: ...
|
||||
def flash() -> None: ...
|
||||
def flushinp() -> None: ...
|
||||
def get_escdelay() -> int: ...
|
||||
def get_tabsize() -> int: ...
|
||||
def getmouse() -> tuple[int, int, int, int, int]: ...
|
||||
def getsyx() -> tuple[int, int]: ...
|
||||
def getwin(file: SupportsRead[bytes], /) -> window: ...
|
||||
def halfdelay(tenths: int, /) -> None: ...
|
||||
def has_colors() -> bool: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
def has_extended_color_support() -> bool: ...
|
||||
|
||||
def has_ic() -> bool: ...
|
||||
def has_il() -> bool: ...
|
||||
def has_key(key: int, /) -> bool: ...
|
||||
def init_color(color_number: int, r: int, g: int, b: int, /) -> None: ...
|
||||
def init_pair(pair_number: int, fg: int, bg: int, /) -> None: ...
|
||||
def initscr() -> window: ...
|
||||
def intrflush(flag: bool, /) -> None: ...
|
||||
def is_term_resized(nlines: int, ncols: int, /) -> bool: ...
|
||||
def isendwin() -> bool: ...
|
||||
def keyname(key: int, /) -> bytes: ...
|
||||
def killchar() -> bytes: ...
|
||||
def longname() -> bytes: ...
|
||||
def meta(yes: bool, /) -> None: ...
|
||||
def mouseinterval(interval: int, /) -> None: ...
|
||||
def mousemask(newmask: int, /) -> tuple[int, int]: ...
|
||||
def napms(ms: int, /) -> int: ...
|
||||
def newpad(nlines: int, ncols: int, /) -> window: ...
|
||||
def newwin(nlines: int, ncols: int, begin_y: int = ..., begin_x: int = ..., /) -> window: ...
|
||||
def nl(flag: bool = True, /) -> None: ...
|
||||
def nocbreak() -> None: ...
|
||||
def noecho() -> None: ...
|
||||
def nonl() -> None: ...
|
||||
def noqiflush() -> None: ...
|
||||
def noraw() -> None: ...
|
||||
def pair_content(pair_number: int, /) -> tuple[int, int]: ...
|
||||
def pair_number(attr: int, /) -> int: ...
|
||||
def putp(string: ReadOnlyBuffer, /) -> None: ...
|
||||
def qiflush(flag: bool = True, /) -> None: ...
|
||||
def raw(flag: bool = True, /) -> None: ...
|
||||
def reset_prog_mode() -> None: ...
|
||||
def reset_shell_mode() -> None: ...
|
||||
def resetty() -> None: ...
|
||||
def resize_term(nlines: int, ncols: int, /) -> None: ...
|
||||
def resizeterm(nlines: int, ncols: int, /) -> None: ...
|
||||
def savetty() -> None: ...
|
||||
def set_escdelay(ms: int, /) -> None: ...
|
||||
def set_tabsize(size: int, /) -> None: ...
|
||||
def setsyx(y: int, x: int, /) -> None: ...
|
||||
def setupterm(term: str | None = None, fd: int = -1) -> None: ...
|
||||
def start_color() -> None: ...
|
||||
def termattrs() -> int: ...
|
||||
def termname() -> bytes: ...
|
||||
def tigetflag(capname: str, /) -> int: ...
|
||||
def tigetnum(capname: str, /) -> int: ...
|
||||
def tigetstr(capname: str, /) -> bytes | None: ...
|
||||
def tparm(
|
||||
str: ReadOnlyBuffer,
|
||||
i1: int = 0,
|
||||
i2: int = 0,
|
||||
i3: int = 0,
|
||||
i4: int = 0,
|
||||
i5: int = 0,
|
||||
i6: int = 0,
|
||||
i7: int = 0,
|
||||
i8: int = 0,
|
||||
i9: int = 0,
|
||||
/,
|
||||
) -> bytes: ...
|
||||
def typeahead(fd: int, /) -> None: ...
|
||||
def unctrl(ch: _ChType, /) -> bytes: ...
|
||||
def unget_wch(ch: int | str, /) -> None: ...
|
||||
def ungetch(ch: _ChType, /) -> None: ...
|
||||
def ungetmouse(id: int, x: int, y: int, z: int, bstate: int, /) -> None: ...
|
||||
def update_lines_cols() -> None: ...
|
||||
def use_default_colors() -> None: ...
|
||||
def use_env(flag: bool, /) -> None: ...
|
||||
|
||||
class error(Exception): ...
|
||||
|
||||
@final
|
||||
class window: # undocumented
|
||||
encoding: str
|
||||
@overload
|
||||
def addch(self, ch: _ChType, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def addch(self, y: int, x: int, ch: _ChType, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def addnstr(self, str: str, n: int, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def addnstr(self, y: int, x: int, str: str, n: int, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def addstr(self, str: str, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def addstr(self, y: int, x: int, str: str, attr: int = ...) -> None: ...
|
||||
def attroff(self, attr: int, /) -> None: ...
|
||||
def attron(self, attr: int, /) -> None: ...
|
||||
def attrset(self, attr: int, /) -> None: ...
|
||||
def bkgd(self, ch: _ChType, attr: int = ..., /) -> None: ...
|
||||
def bkgdset(self, ch: _ChType, attr: int = ..., /) -> None: ...
|
||||
def border(
|
||||
self,
|
||||
ls: _ChType = ...,
|
||||
rs: _ChType = ...,
|
||||
ts: _ChType = ...,
|
||||
bs: _ChType = ...,
|
||||
tl: _ChType = ...,
|
||||
tr: _ChType = ...,
|
||||
bl: _ChType = ...,
|
||||
br: _ChType = ...,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def box(self) -> None: ...
|
||||
@overload
|
||||
def box(self, vertch: _ChType = ..., horch: _ChType = ...) -> None: ...
|
||||
@overload
|
||||
def chgat(self, attr: int) -> None: ...
|
||||
@overload
|
||||
def chgat(self, num: int, attr: int) -> None: ...
|
||||
@overload
|
||||
def chgat(self, y: int, x: int, attr: int) -> None: ...
|
||||
@overload
|
||||
def chgat(self, y: int, x: int, num: int, attr: int) -> None: ...
|
||||
def clear(self) -> None: ...
|
||||
def clearok(self, yes: int) -> None: ...
|
||||
def clrtobot(self) -> None: ...
|
||||
def clrtoeol(self) -> None: ...
|
||||
def cursyncup(self) -> None: ...
|
||||
@overload
|
||||
def delch(self) -> None: ...
|
||||
@overload
|
||||
def delch(self, y: int, x: int) -> None: ...
|
||||
def deleteln(self) -> None: ...
|
||||
@overload
|
||||
def derwin(self, begin_y: int, begin_x: int) -> window: ...
|
||||
@overload
|
||||
def derwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> window: ...
|
||||
def echochar(self, ch: _ChType, attr: int = ..., /) -> None: ...
|
||||
def enclose(self, y: int, x: int, /) -> bool: ...
|
||||
def erase(self) -> None: ...
|
||||
def getbegyx(self) -> tuple[int, int]: ...
|
||||
def getbkgd(self) -> tuple[int, int]: ...
|
||||
@overload
|
||||
def getch(self) -> int: ...
|
||||
@overload
|
||||
def getch(self, y: int, x: int) -> int: ...
|
||||
@overload
|
||||
def get_wch(self) -> int | str: ...
|
||||
@overload
|
||||
def get_wch(self, y: int, x: int) -> int | str: ...
|
||||
@overload
|
||||
def getkey(self) -> str: ...
|
||||
@overload
|
||||
def getkey(self, y: int, x: int) -> str: ...
|
||||
def getmaxyx(self) -> tuple[int, int]: ...
|
||||
def getparyx(self) -> tuple[int, int]: ...
|
||||
@overload
|
||||
def getstr(self) -> bytes: ...
|
||||
@overload
|
||||
def getstr(self, n: int) -> bytes: ...
|
||||
@overload
|
||||
def getstr(self, y: int, x: int) -> bytes: ...
|
||||
@overload
|
||||
def getstr(self, y: int, x: int, n: int) -> bytes: ...
|
||||
def getyx(self) -> tuple[int, int]: ...
|
||||
@overload
|
||||
def hline(self, ch: _ChType, n: int) -> None: ...
|
||||
@overload
|
||||
def hline(self, y: int, x: int, ch: _ChType, n: int) -> None: ...
|
||||
def idcok(self, flag: bool) -> None: ...
|
||||
def idlok(self, yes: bool) -> None: ...
|
||||
def immedok(self, flag: bool) -> None: ...
|
||||
@overload
|
||||
def inch(self) -> int: ...
|
||||
@overload
|
||||
def inch(self, y: int, x: int) -> int: ...
|
||||
@overload
|
||||
def insch(self, ch: _ChType, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def insch(self, y: int, x: int, ch: _ChType, attr: int = ...) -> None: ...
|
||||
def insdelln(self, nlines: int) -> None: ...
|
||||
def insertln(self) -> None: ...
|
||||
@overload
|
||||
def insnstr(self, str: str, n: int, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def insnstr(self, y: int, x: int, str: str, n: int, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def insstr(self, str: str, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def insstr(self, y: int, x: int, str: str, attr: int = ...) -> None: ...
|
||||
@overload
|
||||
def instr(self, n: int = ...) -> bytes: ...
|
||||
@overload
|
||||
def instr(self, y: int, x: int, n: int = ...) -> bytes: ...
|
||||
def is_linetouched(self, line: int, /) -> bool: ...
|
||||
def is_wintouched(self) -> bool: ...
|
||||
def keypad(self, yes: bool, /) -> None: ...
|
||||
def leaveok(self, yes: bool) -> None: ...
|
||||
def move(self, new_y: int, new_x: int) -> None: ...
|
||||
def mvderwin(self, y: int, x: int) -> None: ...
|
||||
def mvwin(self, new_y: int, new_x: int) -> None: ...
|
||||
def nodelay(self, yes: bool) -> None: ...
|
||||
def notimeout(self, yes: bool) -> None: ...
|
||||
@overload
|
||||
def noutrefresh(self) -> None: ...
|
||||
@overload
|
||||
def noutrefresh(self, pminrow: int, pmincol: int, sminrow: int, smincol: int, smaxrow: int, smaxcol: int) -> None: ...
|
||||
@overload
|
||||
def overlay(self, destwin: window) -> None: ...
|
||||
@overload
|
||||
def overlay(
|
||||
self, destwin: window, sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int
|
||||
) -> None: ...
|
||||
@overload
|
||||
def overwrite(self, destwin: window) -> None: ...
|
||||
@overload
|
||||
def overwrite(
|
||||
self, destwin: window, sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int
|
||||
) -> None: ...
|
||||
def putwin(self, file: SupportsWrite[bytes], /) -> None: ...
|
||||
def redrawln(self, beg: int, num: int, /) -> None: ...
|
||||
def redrawwin(self) -> None: ...
|
||||
@overload
|
||||
def refresh(self) -> None: ...
|
||||
@overload
|
||||
def refresh(self, pminrow: int, pmincol: int, sminrow: int, smincol: int, smaxrow: int, smaxcol: int) -> None: ...
|
||||
def resize(self, nlines: int, ncols: int) -> None: ...
|
||||
def scroll(self, lines: int = ...) -> None: ...
|
||||
def scrollok(self, flag: bool) -> None: ...
|
||||
def setscrreg(self, top: int, bottom: int, /) -> None: ...
|
||||
def standend(self) -> None: ...
|
||||
def standout(self) -> None: ...
|
||||
@overload
|
||||
def subpad(self, begin_y: int, begin_x: int) -> window: ...
|
||||
@overload
|
||||
def subpad(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> window: ...
|
||||
@overload
|
||||
def subwin(self, begin_y: int, begin_x: int) -> window: ...
|
||||
@overload
|
||||
def subwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> window: ...
|
||||
def syncdown(self) -> None: ...
|
||||
def syncok(self, flag: bool) -> None: ...
|
||||
def syncup(self) -> None: ...
|
||||
def timeout(self, delay: int) -> None: ...
|
||||
def touchline(self, start: int, count: int, changed: bool = ...) -> None: ...
|
||||
def touchwin(self) -> None: ...
|
||||
def untouchwin(self) -> None: ...
|
||||
@overload
|
||||
def vline(self, ch: _ChType, n: int) -> None: ...
|
||||
@overload
|
||||
def vline(self, y: int, x: int, ch: _ChType, n: int) -> None: ...
|
||||
|
||||
ncurses_version: _ncurses_version
|
||||
27
crates/red_knot_vendored/vendor/typeshed/stdlib/_curses_panel.pyi
vendored
Normal file
27
crates/red_knot_vendored/vendor/typeshed/stdlib/_curses_panel.pyi
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
from _curses import window
|
||||
from typing import final
|
||||
|
||||
__version__: str
|
||||
version: str
|
||||
|
||||
class error(Exception): ...
|
||||
|
||||
@final
|
||||
class panel:
|
||||
def above(self) -> panel: ...
|
||||
def below(self) -> panel: ...
|
||||
def bottom(self) -> None: ...
|
||||
def hidden(self) -> bool: ...
|
||||
def hide(self) -> None: ...
|
||||
def move(self, y: int, x: int, /) -> None: ...
|
||||
def replace(self, win: window, /) -> None: ...
|
||||
def set_userptr(self, obj: object, /) -> None: ...
|
||||
def show(self) -> None: ...
|
||||
def top(self) -> None: ...
|
||||
def userptr(self) -> object: ...
|
||||
def window(self) -> window: ...
|
||||
|
||||
def bottom_panel() -> panel: ...
|
||||
def new_panel(win: window, /) -> panel: ...
|
||||
def top_panel() -> panel: ...
|
||||
def update_panels() -> panel: ...
|
||||
44
crates/red_knot_vendored/vendor/typeshed/stdlib/_dbm.pyi
vendored
Normal file
44
crates/red_knot_vendored/vendor/typeshed/stdlib/_dbm.pyi
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import sys
|
||||
from _typeshed import ReadOnlyBuffer, StrOrBytesPath
|
||||
from types import TracebackType
|
||||
from typing import TypeVar, final, overload, type_check_only
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
if sys.platform != "win32":
|
||||
_T = TypeVar("_T")
|
||||
_KeyType: TypeAlias = str | ReadOnlyBuffer
|
||||
_ValueType: TypeAlias = str | ReadOnlyBuffer
|
||||
|
||||
class error(OSError): ...
|
||||
library: str
|
||||
|
||||
# Actual typename dbm, not exposed by the implementation
|
||||
@final
|
||||
@type_check_only
|
||||
class _dbm:
|
||||
def close(self) -> None: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
def clear(self) -> None: ...
|
||||
|
||||
def __getitem__(self, item: _KeyType) -> bytes: ...
|
||||
def __setitem__(self, key: _KeyType, value: _ValueType) -> None: ...
|
||||
def __delitem__(self, key: _KeyType) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
@overload
|
||||
def get(self, k: _KeyType, /) -> bytes | None: ...
|
||||
@overload
|
||||
def get(self, k: _KeyType, default: _T, /) -> bytes | _T: ...
|
||||
def keys(self) -> list[bytes]: ...
|
||||
def setdefault(self, k: _KeyType, default: _ValueType = ..., /) -> bytes: ...
|
||||
# This isn't true, but the class can't be instantiated. See #13024
|
||||
__new__: None # type: ignore[assignment]
|
||||
__init__: None # type: ignore[assignment]
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def open(filename: StrOrBytesPath, flags: str = "r", mode: int = 0o666, /) -> _dbm: ...
|
||||
else:
|
||||
def open(filename: str, flags: str = "r", mode: int = 0o666, /) -> _dbm: ...
|
||||
67
crates/red_knot_vendored/vendor/typeshed/stdlib/_decimal.pyi
vendored
Normal file
67
crates/red_knot_vendored/vendor/typeshed/stdlib/_decimal.pyi
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
import sys
|
||||
from decimal import (
|
||||
Clamped as Clamped,
|
||||
Context as Context,
|
||||
ConversionSyntax as ConversionSyntax,
|
||||
Decimal as Decimal,
|
||||
DecimalException as DecimalException,
|
||||
DecimalTuple as DecimalTuple,
|
||||
DivisionByZero as DivisionByZero,
|
||||
DivisionImpossible as DivisionImpossible,
|
||||
DivisionUndefined as DivisionUndefined,
|
||||
FloatOperation as FloatOperation,
|
||||
Inexact as Inexact,
|
||||
InvalidContext as InvalidContext,
|
||||
InvalidOperation as InvalidOperation,
|
||||
Overflow as Overflow,
|
||||
Rounded as Rounded,
|
||||
Subnormal as Subnormal,
|
||||
Underflow as Underflow,
|
||||
_ContextManager,
|
||||
)
|
||||
from typing import Final
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
_TrapType: TypeAlias = type[DecimalException]
|
||||
|
||||
__version__: Final[str]
|
||||
__libmpdec_version__: Final[str]
|
||||
|
||||
ROUND_DOWN: Final = "ROUND_DOWN"
|
||||
ROUND_HALF_UP: Final = "ROUND_HALF_UP"
|
||||
ROUND_HALF_EVEN: Final = "ROUND_HALF_EVEN"
|
||||
ROUND_CEILING: Final = "ROUND_CEILING"
|
||||
ROUND_FLOOR: Final = "ROUND_FLOOR"
|
||||
ROUND_UP: Final = "ROUND_UP"
|
||||
ROUND_HALF_DOWN: Final = "ROUND_HALF_DOWN"
|
||||
ROUND_05UP: Final = "ROUND_05UP"
|
||||
HAVE_CONTEXTVAR: Final[bool]
|
||||
HAVE_THREADS: Final[bool]
|
||||
MAX_EMAX: Final[int]
|
||||
MAX_PREC: Final[int]
|
||||
MIN_EMIN: Final[int]
|
||||
MIN_ETINY: Final[int]
|
||||
|
||||
def setcontext(context: Context, /) -> None: ...
|
||||
def getcontext() -> Context: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def localcontext(
|
||||
ctx: Context | None = None,
|
||||
*,
|
||||
prec: int | None = ...,
|
||||
rounding: str | None = ...,
|
||||
Emin: int | None = ...,
|
||||
Emax: int | None = ...,
|
||||
capitals: int | None = ...,
|
||||
clamp: int | None = ...,
|
||||
traps: dict[_TrapType, bool] | None = ...,
|
||||
flags: dict[_TrapType, bool] | None = ...,
|
||||
) -> _ContextManager: ...
|
||||
|
||||
else:
|
||||
def localcontext(ctx: Context | None = None) -> _ContextManager: ...
|
||||
|
||||
DefaultContext: Context
|
||||
BasicContext: Context
|
||||
ExtendedContext: Context
|
||||
113
crates/red_knot_vendored/vendor/typeshed/stdlib/_frozen_importlib.pyi
vendored
Normal file
113
crates/red_knot_vendored/vendor/typeshed/stdlib/_frozen_importlib.pyi
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
import importlib.abc
|
||||
import importlib.machinery
|
||||
import sys
|
||||
import types
|
||||
from _typeshed.importlib import LoaderProtocol
|
||||
from collections.abc import Mapping, Sequence
|
||||
from types import ModuleType
|
||||
from typing import Any, ClassVar
|
||||
|
||||
# Signature of `builtins.__import__` should be kept identical to `importlib.__import__`
|
||||
def __import__(
|
||||
name: str,
|
||||
globals: Mapping[str, object] | None = None,
|
||||
locals: Mapping[str, object] | None = None,
|
||||
fromlist: Sequence[str] = (),
|
||||
level: int = 0,
|
||||
) -> ModuleType: ...
|
||||
def spec_from_loader(
|
||||
name: str, loader: LoaderProtocol | None, *, origin: str | None = None, is_package: bool | None = None
|
||||
) -> importlib.machinery.ModuleSpec | None: ...
|
||||
def module_from_spec(spec: importlib.machinery.ModuleSpec) -> types.ModuleType: ...
|
||||
def _init_module_attrs(
|
||||
spec: importlib.machinery.ModuleSpec, module: types.ModuleType, *, override: bool = False
|
||||
) -> types.ModuleType: ...
|
||||
|
||||
class ModuleSpec:
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
loader: importlib.abc.Loader | None,
|
||||
*,
|
||||
origin: str | None = None,
|
||||
loader_state: Any = None,
|
||||
is_package: bool | None = None,
|
||||
) -> None: ...
|
||||
name: str
|
||||
loader: importlib.abc.Loader | None
|
||||
origin: str | None
|
||||
submodule_search_locations: list[str] | None
|
||||
loader_state: Any
|
||||
cached: str | None
|
||||
@property
|
||||
def parent(self) -> str | None: ...
|
||||
has_location: bool
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
|
||||
class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
|
||||
# MetaPathFinder
|
||||
if sys.version_info < (3, 12):
|
||||
@classmethod
|
||||
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
|
||||
|
||||
@classmethod
|
||||
def find_spec(
|
||||
cls, fullname: str, path: Sequence[str] | None = None, target: types.ModuleType | None = None
|
||||
) -> ModuleSpec | None: ...
|
||||
# InspectLoader
|
||||
@classmethod
|
||||
def is_package(cls, fullname: str) -> bool: ...
|
||||
@classmethod
|
||||
def load_module(cls, fullname: str) -> types.ModuleType: ...
|
||||
@classmethod
|
||||
def get_code(cls, fullname: str) -> None: ...
|
||||
@classmethod
|
||||
def get_source(cls, fullname: str) -> None: ...
|
||||
# Loader
|
||||
if sys.version_info < (3, 12):
|
||||
@staticmethod
|
||||
def module_repr(module: types.ModuleType) -> str: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@staticmethod
|
||||
def create_module(spec: ModuleSpec) -> types.ModuleType | None: ...
|
||||
@staticmethod
|
||||
def exec_module(module: types.ModuleType) -> None: ...
|
||||
else:
|
||||
@classmethod
|
||||
def create_module(cls, spec: ModuleSpec) -> types.ModuleType | None: ...
|
||||
@classmethod
|
||||
def exec_module(cls, module: types.ModuleType) -> None: ...
|
||||
|
||||
class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
|
||||
# MetaPathFinder
|
||||
if sys.version_info < (3, 12):
|
||||
@classmethod
|
||||
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
|
||||
|
||||
@classmethod
|
||||
def find_spec(
|
||||
cls, fullname: str, path: Sequence[str] | None = None, target: types.ModuleType | None = None
|
||||
) -> ModuleSpec | None: ...
|
||||
# InspectLoader
|
||||
@classmethod
|
||||
def is_package(cls, fullname: str) -> bool: ...
|
||||
@classmethod
|
||||
def load_module(cls, fullname: str) -> types.ModuleType: ...
|
||||
@classmethod
|
||||
def get_code(cls, fullname: str) -> None: ...
|
||||
@classmethod
|
||||
def get_source(cls, fullname: str) -> None: ...
|
||||
# Loader
|
||||
if sys.version_info < (3, 12):
|
||||
@staticmethod
|
||||
def module_repr(m: types.ModuleType) -> str: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@staticmethod
|
||||
def create_module(spec: ModuleSpec) -> types.ModuleType | None: ...
|
||||
else:
|
||||
@classmethod
|
||||
def create_module(cls, spec: ModuleSpec) -> types.ModuleType | None: ...
|
||||
|
||||
@staticmethod
|
||||
def exec_module(module: types.ModuleType) -> None: ...
|
||||
178
crates/red_knot_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi
vendored
Normal file
178
crates/red_knot_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
import _ast
|
||||
import _io
|
||||
import importlib.abc
|
||||
import importlib.machinery
|
||||
import sys
|
||||
import types
|
||||
from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath
|
||||
from _typeshed.importlib import LoaderProtocol
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableSequence, Sequence
|
||||
from importlib.machinery import ModuleSpec
|
||||
from importlib.metadata import DistributionFinder, PathDistribution
|
||||
from typing import Any, Literal
|
||||
from typing_extensions import Self, deprecated
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
import importlib.readers
|
||||
|
||||
if sys.platform == "win32":
|
||||
path_separators: Literal["\\/"]
|
||||
path_sep: Literal["\\"]
|
||||
path_sep_tuple: tuple[Literal["\\"], Literal["/"]]
|
||||
else:
|
||||
path_separators: Literal["/"]
|
||||
path_sep: Literal["/"]
|
||||
path_sep_tuple: tuple[Literal["/"]]
|
||||
|
||||
MAGIC_NUMBER: bytes
|
||||
|
||||
def cache_from_source(path: StrPath, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: ...
|
||||
def source_from_cache(path: StrPath) -> str: ...
|
||||
def decode_source(source_bytes: ReadableBuffer) -> str: ...
|
||||
def spec_from_file_location(
|
||||
name: str,
|
||||
location: StrOrBytesPath | None = None,
|
||||
*,
|
||||
loader: LoaderProtocol | None = None,
|
||||
submodule_search_locations: list[str] | None = ...,
|
||||
) -> importlib.machinery.ModuleSpec | None: ...
|
||||
|
||||
class WindowsRegistryFinder(importlib.abc.MetaPathFinder):
|
||||
if sys.version_info < (3, 12):
|
||||
@classmethod
|
||||
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
|
||||
|
||||
@classmethod
|
||||
def find_spec(
|
||||
cls, fullname: str, path: Sequence[str] | None = None, target: types.ModuleType | None = None
|
||||
) -> ModuleSpec | None: ...
|
||||
|
||||
class PathFinder(importlib.abc.MetaPathFinder):
|
||||
if sys.version_info >= (3, 10):
|
||||
@staticmethod
|
||||
def invalidate_caches() -> None: ...
|
||||
else:
|
||||
@classmethod
|
||||
def invalidate_caches(cls) -> None: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@staticmethod
|
||||
def find_distributions(context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
|
||||
else:
|
||||
@classmethod
|
||||
def find_distributions(cls, context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
|
||||
|
||||
@classmethod
|
||||
def find_spec(
|
||||
cls, fullname: str, path: Sequence[str] | None = None, target: types.ModuleType | None = None
|
||||
) -> ModuleSpec | None: ...
|
||||
if sys.version_info < (3, 12):
|
||||
@classmethod
|
||||
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
|
||||
|
||||
SOURCE_SUFFIXES: list[str]
|
||||
DEBUG_BYTECODE_SUFFIXES: list[str]
|
||||
OPTIMIZED_BYTECODE_SUFFIXES: list[str]
|
||||
BYTECODE_SUFFIXES: list[str]
|
||||
EXTENSION_SUFFIXES: list[str]
|
||||
|
||||
class FileFinder(importlib.abc.PathEntryFinder):
|
||||
path: str
|
||||
def __init__(self, path: str, *loader_details: tuple[type[importlib.abc.Loader], list[str]]) -> None: ...
|
||||
@classmethod
|
||||
def path_hook(
|
||||
cls, *loader_details: tuple[type[importlib.abc.Loader], list[str]]
|
||||
) -> Callable[[str], importlib.abc.PathEntryFinder]: ...
|
||||
|
||||
class _LoaderBasics:
|
||||
def is_package(self, fullname: str) -> bool: ...
|
||||
def create_module(self, spec: ModuleSpec) -> types.ModuleType | None: ...
|
||||
def exec_module(self, module: types.ModuleType) -> None: ...
|
||||
def load_module(self, fullname: str) -> types.ModuleType: ...
|
||||
|
||||
class SourceLoader(_LoaderBasics):
|
||||
def path_mtime(self, path: str) -> float: ...
|
||||
def set_data(self, path: str, data: bytes) -> None: ...
|
||||
def get_source(self, fullname: str) -> str | None: ...
|
||||
def path_stats(self, path: str) -> Mapping[str, Any]: ...
|
||||
def source_to_code(
|
||||
self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: ReadableBuffer | StrPath
|
||||
) -> types.CodeType: ...
|
||||
def get_code(self, fullname: str) -> types.CodeType | None: ...
|
||||
|
||||
class FileLoader:
|
||||
name: str
|
||||
path: str
|
||||
def __init__(self, fullname: str, path: str) -> None: ...
|
||||
def get_data(self, path: str) -> bytes: ...
|
||||
def get_filename(self, name: str | None = None) -> str: ...
|
||||
def load_module(self, name: str | None = None) -> types.ModuleType: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
def get_resource_reader(self, name: str | None = None) -> importlib.readers.FileReader: ...
|
||||
else:
|
||||
def get_resource_reader(self, name: str | None = None) -> Self | None: ...
|
||||
def open_resource(self, resource: str) -> _io.FileIO: ...
|
||||
def resource_path(self, resource: str) -> str: ...
|
||||
def is_resource(self, name: str) -> bool: ...
|
||||
def contents(self) -> Iterator[str]: ...
|
||||
|
||||
class SourceFileLoader(importlib.abc.FileLoader, FileLoader, importlib.abc.SourceLoader, SourceLoader): # type: ignore[misc] # incompatible method arguments in base classes
|
||||
def set_data(self, path: str, data: ReadableBuffer, *, _mode: int = 0o666) -> None: ...
|
||||
def path_stats(self, path: str) -> Mapping[str, Any]: ...
|
||||
|
||||
class SourcelessFileLoader(importlib.abc.FileLoader, FileLoader, _LoaderBasics):
|
||||
def get_code(self, fullname: str) -> types.CodeType | None: ...
|
||||
def get_source(self, fullname: str) -> None: ...
|
||||
|
||||
class ExtensionFileLoader(FileLoader, _LoaderBasics, importlib.abc.ExecutionLoader):
|
||||
def __init__(self, name: str, path: str) -> None: ...
|
||||
def get_filename(self, name: str | None = None) -> str: ...
|
||||
def get_source(self, fullname: str) -> None: ...
|
||||
def create_module(self, spec: ModuleSpec) -> types.ModuleType: ...
|
||||
def exec_module(self, module: types.ModuleType) -> None: ...
|
||||
def get_code(self, fullname: str) -> None: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
class NamespaceLoader(importlib.abc.InspectLoader):
|
||||
def __init__(
|
||||
self, name: str, path: MutableSequence[str], path_finder: Callable[[str, tuple[str, ...]], ModuleSpec]
|
||||
) -> None: ...
|
||||
def is_package(self, fullname: str) -> Literal[True]: ...
|
||||
def get_source(self, fullname: str) -> Literal[""]: ...
|
||||
def get_code(self, fullname: str) -> types.CodeType: ...
|
||||
def create_module(self, spec: ModuleSpec) -> None: ...
|
||||
def exec_module(self, module: types.ModuleType) -> None: ...
|
||||
@deprecated("load_module() is deprecated; use exec_module() instead")
|
||||
def load_module(self, fullname: str) -> types.ModuleType: ...
|
||||
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
|
||||
if sys.version_info < (3, 12):
|
||||
@staticmethod
|
||||
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
|
||||
def module_repr(module: types.ModuleType) -> str: ...
|
||||
|
||||
_NamespaceLoader = NamespaceLoader
|
||||
else:
|
||||
class _NamespaceLoader:
|
||||
def __init__(
|
||||
self, name: str, path: MutableSequence[str], path_finder: Callable[[str, tuple[str, ...]], ModuleSpec]
|
||||
) -> None: ...
|
||||
def is_package(self, fullname: str) -> Literal[True]: ...
|
||||
def get_source(self, fullname: str) -> Literal[""]: ...
|
||||
def get_code(self, fullname: str) -> types.CodeType: ...
|
||||
def create_module(self, spec: ModuleSpec) -> None: ...
|
||||
def exec_module(self, module: types.ModuleType) -> None: ...
|
||||
@deprecated("load_module() is deprecated; use exec_module() instead")
|
||||
def load_module(self, fullname: str) -> types.ModuleType: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@staticmethod
|
||||
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
|
||||
def module_repr(module: types.ModuleType) -> str: ...
|
||||
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
|
||||
else:
|
||||
@classmethod
|
||||
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
|
||||
def module_repr(cls, module: types.ModuleType) -> str: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
class AppleFrameworkLoader(ExtensionFileLoader, importlib.abc.ExecutionLoader): ...
|
||||
47
crates/red_knot_vendored/vendor/typeshed/stdlib/_gdbm.pyi
vendored
Normal file
47
crates/red_knot_vendored/vendor/typeshed/stdlib/_gdbm.pyi
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import sys
|
||||
from _typeshed import ReadOnlyBuffer, StrOrBytesPath
|
||||
from types import TracebackType
|
||||
from typing import TypeVar, overload
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
if sys.platform != "win32":
|
||||
_T = TypeVar("_T")
|
||||
_KeyType: TypeAlias = str | ReadOnlyBuffer
|
||||
_ValueType: TypeAlias = str | ReadOnlyBuffer
|
||||
|
||||
open_flags: str
|
||||
|
||||
class error(OSError): ...
|
||||
# Actual typename gdbm, not exposed by the implementation
|
||||
class _gdbm:
|
||||
def firstkey(self) -> bytes | None: ...
|
||||
def nextkey(self, key: _KeyType) -> bytes | None: ...
|
||||
def reorganize(self) -> None: ...
|
||||
def sync(self) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
def clear(self) -> None: ...
|
||||
|
||||
def __getitem__(self, item: _KeyType) -> bytes: ...
|
||||
def __setitem__(self, key: _KeyType, value: _ValueType) -> None: ...
|
||||
def __delitem__(self, key: _KeyType) -> None: ...
|
||||
def __contains__(self, key: _KeyType) -> bool: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
@overload
|
||||
def get(self, k: _KeyType) -> bytes | None: ...
|
||||
@overload
|
||||
def get(self, k: _KeyType, default: _T) -> bytes | _T: ...
|
||||
def keys(self) -> list[bytes]: ...
|
||||
def setdefault(self, k: _KeyType, default: _ValueType = ...) -> bytes: ...
|
||||
# Don't exist at runtime
|
||||
__new__: None # type: ignore[assignment]
|
||||
__init__: None # type: ignore[assignment]
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def open(filename: StrOrBytesPath, flags: str = "r", mode: int = 0o666, /) -> _gdbm: ...
|
||||
else:
|
||||
def open(filename: str, flags: str = "r", mode: int = 0o666, /) -> _gdbm: ...
|
||||
82
crates/red_knot_vendored/vendor/typeshed/stdlib/_hashlib.pyi
vendored
Normal file
82
crates/red_knot_vendored/vendor/typeshed/stdlib/_hashlib.pyi
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer
|
||||
from collections.abc import Callable
|
||||
from types import ModuleType
|
||||
from typing import AnyStr, Protocol, final, overload, type_check_only
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
_DigestMod: TypeAlias = str | Callable[[], _HashObject] | ModuleType | None
|
||||
|
||||
openssl_md_meth_names: frozenset[str]
|
||||
|
||||
@type_check_only
|
||||
class _HashObject(Protocol):
|
||||
@property
|
||||
def digest_size(self) -> int: ...
|
||||
@property
|
||||
def block_size(self) -> int: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
def copy(self) -> Self: ...
|
||||
def digest(self) -> bytes: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def update(self, obj: ReadableBuffer, /) -> None: ...
|
||||
|
||||
class HASH:
|
||||
@property
|
||||
def digest_size(self) -> int: ...
|
||||
@property
|
||||
def block_size(self) -> int: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
def copy(self) -> Self: ...
|
||||
def digest(self) -> bytes: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def update(self, obj: ReadableBuffer, /) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
class UnsupportedDigestmodError(ValueError): ...
|
||||
|
||||
class HASHXOF(HASH):
|
||||
def digest(self, length: int) -> bytes: ... # type: ignore[override]
|
||||
def hexdigest(self, length: int) -> str: ... # type: ignore[override]
|
||||
|
||||
@final
|
||||
class HMAC:
|
||||
@property
|
||||
def digest_size(self) -> int: ...
|
||||
@property
|
||||
def block_size(self) -> int: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
def copy(self) -> Self: ...
|
||||
def digest(self) -> bytes: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def update(self, msg: ReadableBuffer) -> None: ...
|
||||
|
||||
@overload
|
||||
def compare_digest(a: ReadableBuffer, b: ReadableBuffer, /) -> bool: ...
|
||||
@overload
|
||||
def compare_digest(a: AnyStr, b: AnyStr, /) -> bool: ...
|
||||
def get_fips_mode() -> int: ...
|
||||
def hmac_new(key: bytes | bytearray, msg: ReadableBuffer = b"", digestmod: _DigestMod = None) -> HMAC: ...
|
||||
def new(name: str, string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_md5(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha1(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha224(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha384(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha512(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha3_224(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha3_256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha3_384(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_sha3_512(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
|
||||
def openssl_shake_128(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASHXOF: ...
|
||||
def openssl_shake_256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASHXOF: ...
|
||||
def hmac_digest(key: bytes | bytearray, msg: ReadableBuffer, digest: str) -> bytes: ...
|
||||
def pbkdf2_hmac(
|
||||
hash_name: str, password: ReadableBuffer, salt: ReadableBuffer, iterations: int, dklen: int | None = None
|
||||
) -> bytes: ...
|
||||
def scrypt(
|
||||
password: ReadableBuffer, *, salt: ReadableBuffer, n: int, r: int, p: int, maxmem: int = 0, dklen: int = 64
|
||||
) -> bytes: ...
|
||||
11
crates/red_knot_vendored/vendor/typeshed/stdlib/_heapq.pyi
vendored
Normal file
11
crates/red_knot_vendored/vendor/typeshed/stdlib/_heapq.pyi
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
from typing import Any, Final, TypeVar
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
__about__: Final[str]
|
||||
|
||||
def heapify(heap: list[Any], /) -> None: ...
|
||||
def heappop(heap: list[_T], /) -> _T: ...
|
||||
def heappush(heap: list[_T], item: _T, /) -> None: ...
|
||||
def heappushpop(heap: list[_T], item: _T, /) -> _T: ...
|
||||
def heapreplace(heap: list[_T], item: _T, /) -> _T: ...
|
||||
28
crates/red_knot_vendored/vendor/typeshed/stdlib/_imp.pyi
vendored
Normal file
28
crates/red_knot_vendored/vendor/typeshed/stdlib/_imp.pyi
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import sys
|
||||
import types
|
||||
from _typeshed import ReadableBuffer
|
||||
from importlib.machinery import ModuleSpec
|
||||
from typing import Any
|
||||
|
||||
check_hash_based_pycs: str
|
||||
|
||||
def source_hash(key: int, source: ReadableBuffer) -> bytes: ...
|
||||
def create_builtin(spec: ModuleSpec, /) -> types.ModuleType: ...
|
||||
def create_dynamic(spec: ModuleSpec, file: Any = None, /) -> types.ModuleType: ...
|
||||
def acquire_lock() -> None: ...
|
||||
def exec_builtin(mod: types.ModuleType, /) -> int: ...
|
||||
def exec_dynamic(mod: types.ModuleType, /) -> int: ...
|
||||
def extension_suffixes() -> list[str]: ...
|
||||
def init_frozen(name: str, /) -> types.ModuleType: ...
|
||||
def is_builtin(name: str, /) -> int: ...
|
||||
def is_frozen(name: str, /) -> bool: ...
|
||||
def is_frozen_package(name: str, /) -> bool: ...
|
||||
def lock_held() -> bool: ...
|
||||
def release_lock() -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def find_frozen(name: str, /, *, withdata: bool = False) -> tuple[memoryview | None, bool, str | None] | None: ...
|
||||
def get_frozen_object(name: str, data: ReadableBuffer | None = None, /) -> types.CodeType: ...
|
||||
|
||||
else:
|
||||
def get_frozen_object(name: str, /) -> types.CodeType: ...
|
||||
86
crates/red_knot_vendored/vendor/typeshed/stdlib/_interpchannels.pyi
vendored
Normal file
86
crates/red_knot_vendored/vendor/typeshed/stdlib/_interpchannels.pyi
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
from _typeshed import structseq
|
||||
from typing import Any, Final, Literal, SupportsIndex, final
|
||||
from typing_extensions import Buffer, Self
|
||||
|
||||
class ChannelError(RuntimeError): ...
|
||||
class ChannelClosedError(ChannelError): ...
|
||||
class ChannelEmptyError(ChannelError): ...
|
||||
class ChannelNotEmptyError(ChannelError): ...
|
||||
class ChannelNotFoundError(ChannelError): ...
|
||||
|
||||
# Mark as final, since instantiating ChannelID is not supported.
|
||||
@final
|
||||
class ChannelID:
|
||||
@property
|
||||
def end(self) -> Literal["send", "recv", "both"]: ...
|
||||
@property
|
||||
def send(self) -> Self: ...
|
||||
@property
|
||||
def recv(self) -> Self: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
def __ge__(self, other: ChannelID) -> bool: ...
|
||||
def __gt__(self, other: ChannelID) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def __index__(self) -> int: ...
|
||||
def __int__(self) -> int: ...
|
||||
def __le__(self, other: ChannelID) -> bool: ...
|
||||
def __lt__(self, other: ChannelID) -> bool: ...
|
||||
def __ne__(self, other: object) -> bool: ...
|
||||
|
||||
@final
|
||||
class ChannelInfo(structseq[int], tuple[bool, bool, bool, int, int, int, int, int]):
|
||||
__match_args__: Final = (
|
||||
"open",
|
||||
"closing",
|
||||
"closed",
|
||||
"count",
|
||||
"num_interp_send",
|
||||
"num_interp_send_released",
|
||||
"num_interp_recv",
|
||||
"num_interp_recv_released",
|
||||
)
|
||||
@property
|
||||
def open(self) -> bool: ...
|
||||
@property
|
||||
def closing(self) -> bool: ...
|
||||
@property
|
||||
def closed(self) -> bool: ...
|
||||
@property
|
||||
def count(self) -> int: ... # type: ignore[override]
|
||||
@property
|
||||
def num_interp_send(self) -> int: ...
|
||||
@property
|
||||
def num_interp_send_released(self) -> int: ...
|
||||
@property
|
||||
def num_interp_recv(self) -> int: ...
|
||||
@property
|
||||
def num_interp_recv_released(self) -> int: ...
|
||||
@property
|
||||
def num_interp_both(self) -> int: ...
|
||||
@property
|
||||
def num_interp_both_recv_released(self) -> int: ...
|
||||
@property
|
||||
def num_interp_both_send_released(self) -> int: ...
|
||||
@property
|
||||
def num_interp_both_released(self) -> int: ...
|
||||
@property
|
||||
def recv_associated(self) -> bool: ...
|
||||
@property
|
||||
def recv_released(self) -> bool: ...
|
||||
@property
|
||||
def send_associated(self) -> bool: ...
|
||||
@property
|
||||
def send_released(self) -> bool: ...
|
||||
|
||||
def create(unboundop: Literal[1, 2, 3]) -> ChannelID: ...
|
||||
def destroy(cid: SupportsIndex) -> None: ...
|
||||
def list_all() -> list[ChannelID]: ...
|
||||
def list_interpreters(cid: SupportsIndex, *, send: bool) -> list[int]: ...
|
||||
def send(cid: SupportsIndex, obj: object, *, blocking: bool = True, timeout: float | None = None) -> None: ...
|
||||
def send_buffer(cid: SupportsIndex, obj: Buffer, *, blocking: bool = True, timeout: float | None = None) -> None: ...
|
||||
def recv(cid: SupportsIndex, default: object = ...) -> tuple[Any, Literal[1, 2, 3]]: ...
|
||||
def close(cid: SupportsIndex, *, send: bool = False, recv: bool = False) -> None: ...
|
||||
def get_count(cid: SupportsIndex) -> int: ...
|
||||
def get_info(cid: SupportsIndex) -> ChannelInfo: ...
|
||||
def get_channel_defaults(cid: SupportsIndex) -> Literal[1, 2, 3]: ...
|
||||
def release(cid: SupportsIndex, *, send: bool = False, recv: bool = False, force: bool = False) -> None: ...
|
||||
19
crates/red_knot_vendored/vendor/typeshed/stdlib/_interpqueues.pyi
vendored
Normal file
19
crates/red_knot_vendored/vendor/typeshed/stdlib/_interpqueues.pyi
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
from typing import Any, Literal, SupportsIndex
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
_UnboundOp: TypeAlias = Literal[1, 2, 3]
|
||||
|
||||
class QueueError(RuntimeError): ...
|
||||
class QueueNotFoundError(QueueError): ...
|
||||
|
||||
def bind(qid: SupportsIndex) -> None: ...
|
||||
def create(maxsize: SupportsIndex, fmt: SupportsIndex, unboundop: _UnboundOp) -> int: ...
|
||||
def destroy(qid: SupportsIndex) -> None: ...
|
||||
def get(qid: SupportsIndex) -> tuple[Any, int, _UnboundOp | None]: ...
|
||||
def get_count(qid: SupportsIndex) -> int: ...
|
||||
def get_maxsize(qid: SupportsIndex) -> int: ...
|
||||
def get_queue_defaults(qid: SupportsIndex) -> tuple[int, _UnboundOp]: ...
|
||||
def is_full(qid: SupportsIndex) -> bool: ...
|
||||
def list_all() -> list[tuple[int, int, _UnboundOp]]: ...
|
||||
def put(qid: SupportsIndex, obj: Any, fmt: SupportsIndex, unboundop: _UnboundOp) -> None: ...
|
||||
def release(qid: SupportsIndex) -> None: ...
|
||||
52
crates/red_knot_vendored/vendor/typeshed/stdlib/_interpreters.pyi
vendored
Normal file
52
crates/red_knot_vendored/vendor/typeshed/stdlib/_interpreters.pyi
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import types
|
||||
from collections.abc import Callable, Mapping
|
||||
from typing import Final, Literal, SupportsIndex
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
_Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty", ""]
|
||||
|
||||
class InterpreterError(Exception): ...
|
||||
class InterpreterNotFoundError(InterpreterError): ...
|
||||
class NotShareableError(ValueError): ...
|
||||
|
||||
class CrossInterpreterBufferView:
|
||||
def __buffer__(self, flags: int, /) -> memoryview: ...
|
||||
|
||||
def new_config(name: _Configs = "isolated", /, **overides: object) -> types.SimpleNamespace: ...
|
||||
def create(config: types.SimpleNamespace | _Configs | None = "isolated", *, reqrefs: bool = False) -> int: ...
|
||||
def destroy(id: SupportsIndex, *, restrict: bool = False) -> None: ...
|
||||
def list_all(*, require_ready: bool) -> list[tuple[int, int]]: ...
|
||||
def get_current() -> tuple[int, int]: ...
|
||||
def get_main() -> tuple[int, int]: ...
|
||||
def is_running(id: SupportsIndex, *, restrict: bool = False) -> bool: ...
|
||||
def get_config(id: SupportsIndex, *, restrict: bool = False) -> types.SimpleNamespace: ...
|
||||
def whence(id: SupportsIndex) -> int: ...
|
||||
def exec(
|
||||
id: SupportsIndex, code: str | types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
|
||||
) -> None | types.SimpleNamespace: ...
|
||||
def call(
|
||||
id: SupportsIndex,
|
||||
callable: Callable[..., object],
|
||||
args: tuple[object, ...] | None = None,
|
||||
kwargs: dict[str, object] | None = None,
|
||||
*,
|
||||
restrict: bool = False,
|
||||
) -> object: ...
|
||||
def run_string(
|
||||
id: SupportsIndex, script: str | types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
|
||||
) -> None: ...
|
||||
def run_func(
|
||||
id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
|
||||
) -> None: ...
|
||||
def set___main___attrs(id: SupportsIndex, updates: Mapping[str, object], *, restrict: bool = False) -> None: ...
|
||||
def incref(id: SupportsIndex, *, implieslink: bool = False, restrict: bool = False) -> None: ...
|
||||
def decref(id: SupportsIndex, *, restrict: bool = False) -> None: ...
|
||||
def is_shareable(obj: object) -> bool: ...
|
||||
def capture_exception(exc: BaseException | None = None) -> types.SimpleNamespace: ...
|
||||
|
||||
WHENCE_UNKNOWN: Final = 0
|
||||
WHENCE_RUNTIME: Final = 1
|
||||
WHENCE_LEGACY_CAPI: Final = 2
|
||||
WHENCE_CAPI: Final = 3
|
||||
WHENCE_XI: Final = 4
|
||||
WHENCE_STDLIB: Final = 5
|
||||
216
crates/red_knot_vendored/vendor/typeshed/stdlib/_io.pyi
vendored
Normal file
216
crates/red_knot_vendored/vendor/typeshed/stdlib/_io.pyi
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
import builtins
|
||||
import codecs
|
||||
import sys
|
||||
from _typeshed import FileDescriptorOrPath, MaybeNone, ReadableBuffer, WriteableBuffer
|
||||
from collections.abc import Callable, Iterable, Iterator
|
||||
from io import BufferedIOBase, RawIOBase, TextIOBase, UnsupportedOperation as UnsupportedOperation
|
||||
from os import _Opener
|
||||
from types import TracebackType
|
||||
from typing import IO, Any, BinaryIO, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload, type_check_only
|
||||
from typing_extensions import Self
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
DEFAULT_BUFFER_SIZE: Final = 8192
|
||||
|
||||
open = builtins.open
|
||||
|
||||
def open_code(path: str) -> IO[bytes]: ...
|
||||
|
||||
BlockingIOError = builtins.BlockingIOError
|
||||
|
||||
class _IOBase:
|
||||
def __iter__(self) -> Iterator[bytes]: ...
|
||||
def __next__(self) -> bytes: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def fileno(self) -> int: ...
|
||||
def flush(self) -> None: ...
|
||||
def isatty(self) -> bool: ...
|
||||
def readable(self) -> bool: ...
|
||||
read: Callable[..., Any]
|
||||
def readlines(self, hint: int = -1, /) -> list[bytes]: ...
|
||||
def seek(self, offset: int, whence: int = 0, /) -> int: ...
|
||||
def seekable(self) -> bool: ...
|
||||
def tell(self) -> int: ...
|
||||
def truncate(self, size: int | None = None, /) -> int: ...
|
||||
def writable(self) -> bool: ...
|
||||
write: Callable[..., Any]
|
||||
def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: ...
|
||||
def readline(self, size: int | None = -1, /) -> bytes: ...
|
||||
def __del__(self) -> None: ...
|
||||
@property
|
||||
def closed(self) -> bool: ...
|
||||
def _checkClosed(self) -> None: ... # undocumented
|
||||
|
||||
class _RawIOBase(_IOBase):
|
||||
def readall(self) -> bytes: ...
|
||||
# The following methods can return None if the file is in non-blocking mode
|
||||
# and no data is available.
|
||||
def readinto(self, buffer: WriteableBuffer, /) -> int | MaybeNone: ...
|
||||
def write(self, b: ReadableBuffer, /) -> int | MaybeNone: ...
|
||||
def read(self, size: int = -1, /) -> bytes | MaybeNone: ...
|
||||
|
||||
class _BufferedIOBase(_IOBase):
|
||||
def detach(self) -> RawIOBase: ...
|
||||
def readinto(self, buffer: WriteableBuffer, /) -> int: ...
|
||||
def write(self, buffer: ReadableBuffer, /) -> int: ...
|
||||
def readinto1(self, buffer: WriteableBuffer, /) -> int: ...
|
||||
def read(self, size: int | None = -1, /) -> bytes: ...
|
||||
def read1(self, size: int = -1, /) -> bytes: ...
|
||||
|
||||
class FileIO(RawIOBase, _RawIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes
|
||||
mode: str
|
||||
# The type of "name" equals the argument passed in to the constructor,
|
||||
# but that can make FileIO incompatible with other I/O types that assume
|
||||
# "name" is a str. In the future, making FileIO generic might help.
|
||||
name: Any
|
||||
def __init__(
|
||||
self, file: FileDescriptorOrPath, mode: str = "r", closefd: bool = True, opener: _Opener | None = None
|
||||
) -> None: ...
|
||||
@property
|
||||
def closefd(self) -> bool: ...
|
||||
def seek(self, pos: int, whence: int = 0, /) -> int: ...
|
||||
def read(self, size: int | None = -1, /) -> bytes | MaybeNone: ...
|
||||
|
||||
class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes
|
||||
def __init__(self, initial_bytes: ReadableBuffer = b"") -> None: ...
|
||||
# BytesIO does not contain a "name" field. This workaround is necessary
|
||||
# to allow BytesIO sub-classes to add this field, as it is defined
|
||||
# as a read-only property on IO[].
|
||||
name: Any
|
||||
def getvalue(self) -> bytes: ...
|
||||
def getbuffer(self) -> memoryview: ...
|
||||
def read1(self, size: int | None = -1, /) -> bytes: ...
|
||||
def readlines(self, size: int | None = None, /) -> list[bytes]: ...
|
||||
def seek(self, pos: int, whence: int = 0, /) -> int: ...
|
||||
|
||||
class BufferedReader(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes
|
||||
raw: RawIOBase
|
||||
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
|
||||
def peek(self, size: int = 0, /) -> bytes: ...
|
||||
def seek(self, target: int, whence: int = 0, /) -> int: ...
|
||||
def truncate(self, pos: int | None = None, /) -> int: ...
|
||||
|
||||
class BufferedWriter(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes
|
||||
raw: RawIOBase
|
||||
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
|
||||
def write(self, buffer: ReadableBuffer, /) -> int: ...
|
||||
def seek(self, target: int, whence: int = 0, /) -> int: ...
|
||||
def truncate(self, pos: int | None = None, /) -> int: ...
|
||||
|
||||
class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes
|
||||
mode: str
|
||||
name: Any
|
||||
raw: RawIOBase
|
||||
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
|
||||
def seek(self, target: int, whence: int = 0, /) -> int: ... # stubtest needs this
|
||||
def peek(self, size: int = 0, /) -> bytes: ...
|
||||
def truncate(self, pos: int | None = None, /) -> int: ...
|
||||
|
||||
class BufferedRWPair(BufferedIOBase, _BufferedIOBase):
|
||||
def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = 8192, /) -> None: ...
|
||||
def peek(self, size: int = 0, /) -> bytes: ...
|
||||
|
||||
class _TextIOBase(_IOBase):
|
||||
encoding: str
|
||||
errors: str | None
|
||||
newlines: str | tuple[str, ...] | None
|
||||
def __iter__(self) -> Iterator[str]: ... # type: ignore[override]
|
||||
def __next__(self) -> str: ... # type: ignore[override]
|
||||
def detach(self) -> BinaryIO: ...
|
||||
def write(self, s: str, /) -> int: ...
|
||||
def writelines(self, lines: Iterable[str], /) -> None: ... # type: ignore[override]
|
||||
def readline(self, size: int = -1, /) -> str: ... # type: ignore[override]
|
||||
def readlines(self, hint: int = -1, /) -> list[str]: ... # type: ignore[override]
|
||||
def read(self, size: int | None = -1, /) -> str: ...
|
||||
|
||||
@type_check_only
|
||||
class _WrappedBuffer(Protocol):
|
||||
# "name" is wrapped by TextIOWrapper. Its type is inconsistent between
|
||||
# the various I/O types, see the comments on TextIOWrapper.name and
|
||||
# TextIO.name.
|
||||
@property
|
||||
def name(self) -> Any: ...
|
||||
@property
|
||||
def closed(self) -> bool: ...
|
||||
def read(self, size: int = ..., /) -> ReadableBuffer: ...
|
||||
# Optional: def read1(self, size: int, /) -> ReadableBuffer: ...
|
||||
def write(self, b: bytes, /) -> object: ...
|
||||
def flush(self) -> object: ...
|
||||
def close(self) -> object: ...
|
||||
def seekable(self) -> bool: ...
|
||||
def readable(self) -> bool: ...
|
||||
def writable(self) -> bool: ...
|
||||
def truncate(self, size: int, /) -> int: ...
|
||||
def fileno(self) -> int: ...
|
||||
def isatty(self) -> bool: ...
|
||||
# Optional: Only needs to be present if seekable() returns True.
|
||||
# def seek(self, offset: Literal[0], whence: Literal[2]) -> int: ...
|
||||
# def tell(self) -> int: ...
|
||||
|
||||
_BufferT_co = TypeVar("_BufferT_co", bound=_WrappedBuffer, default=_WrappedBuffer, covariant=True)
|
||||
|
||||
class TextIOWrapper(TextIOBase, _TextIOBase, TextIO, Generic[_BufferT_co]): # type: ignore[misc] # incompatible definitions of write in the base classes
|
||||
def __init__(
|
||||
self,
|
||||
buffer: _BufferT_co,
|
||||
encoding: str | None = None,
|
||||
errors: str | None = None,
|
||||
newline: str | None = None,
|
||||
line_buffering: bool = False,
|
||||
write_through: bool = False,
|
||||
) -> None: ...
|
||||
# Equals the "buffer" argument passed in to the constructor.
|
||||
@property
|
||||
def buffer(self) -> _BufferT_co: ... # type: ignore[override]
|
||||
@property
|
||||
def line_buffering(self) -> bool: ...
|
||||
@property
|
||||
def write_through(self) -> bool: ...
|
||||
def reconfigure(
|
||||
self,
|
||||
*,
|
||||
encoding: str | None = None,
|
||||
errors: str | None = None,
|
||||
newline: str | None = None,
|
||||
line_buffering: bool | None = None,
|
||||
write_through: bool | None = None,
|
||||
) -> None: ...
|
||||
def readline(self, size: int = -1, /) -> str: ... # type: ignore[override]
|
||||
# Equals the "buffer" argument passed in to the constructor.
|
||||
def detach(self) -> _BufferT_co: ... # type: ignore[override]
|
||||
# TextIOWrapper's version of seek only supports a limited subset of
|
||||
# operations.
|
||||
def seek(self, cookie: int, whence: int = 0, /) -> int: ...
|
||||
def truncate(self, pos: int | None = None, /) -> int: ...
|
||||
|
||||
class StringIO(TextIOBase, _TextIOBase, TextIO): # type: ignore[misc] # incompatible definitions of write in the base classes
|
||||
def __init__(self, initial_value: str | None = "", newline: str | None = "\n") -> None: ...
|
||||
# StringIO does not contain a "name" field. This workaround is necessary
|
||||
# to allow StringIO sub-classes to add this field, as it is defined
|
||||
# as a read-only property on IO[].
|
||||
name: Any
|
||||
def getvalue(self) -> str: ...
|
||||
@property
|
||||
def line_buffering(self) -> bool: ...
|
||||
def seek(self, pos: int, whence: int = 0, /) -> int: ...
|
||||
def truncate(self, pos: int | None = None, /) -> int: ...
|
||||
|
||||
class IncrementalNewlineDecoder:
|
||||
def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = "strict") -> None: ...
|
||||
def decode(self, input: ReadableBuffer | str, final: bool = False) -> str: ...
|
||||
@property
|
||||
def newlines(self) -> str | tuple[str, ...] | None: ...
|
||||
def getstate(self) -> tuple[bytes, int]: ...
|
||||
def reset(self) -> None: ...
|
||||
def setstate(self, state: tuple[bytes, int], /) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
@overload
|
||||
def text_encoding(encoding: None, stacklevel: int = 2, /) -> Literal["locale", "utf-8"]: ...
|
||||
@overload
|
||||
def text_encoding(encoding: _T, stacklevel: int = 2, /) -> _T: ...
|
||||
51
crates/red_knot_vendored/vendor/typeshed/stdlib/_json.pyi
vendored
Normal file
51
crates/red_knot_vendored/vendor/typeshed/stdlib/_json.pyi
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
from collections.abc import Callable
|
||||
from typing import Any, final
|
||||
from typing_extensions import Self
|
||||
|
||||
@final
|
||||
class make_encoder:
|
||||
@property
|
||||
def sort_keys(self) -> bool: ...
|
||||
@property
|
||||
def skipkeys(self) -> bool: ...
|
||||
@property
|
||||
def key_separator(self) -> str: ...
|
||||
@property
|
||||
def indent(self) -> int | None: ...
|
||||
@property
|
||||
def markers(self) -> dict[int, Any] | None: ...
|
||||
@property
|
||||
def default(self) -> Callable[[Any], Any]: ...
|
||||
@property
|
||||
def encoder(self) -> Callable[[str], str]: ...
|
||||
@property
|
||||
def item_separator(self) -> str: ...
|
||||
def __new__(
|
||||
cls,
|
||||
markers: dict[int, Any] | None,
|
||||
default: Callable[[Any], Any],
|
||||
encoder: Callable[[str], str],
|
||||
indent: int | None,
|
||||
key_separator: str,
|
||||
item_separator: str,
|
||||
sort_keys: bool,
|
||||
skipkeys: bool,
|
||||
allow_nan: bool,
|
||||
) -> Self: ...
|
||||
def __call__(self, obj: object, _current_indent_level: int) -> Any: ...
|
||||
|
||||
@final
|
||||
class make_scanner:
|
||||
object_hook: Any
|
||||
object_pairs_hook: Any
|
||||
parse_int: Any
|
||||
parse_constant: Any
|
||||
parse_float: Any
|
||||
strict: bool
|
||||
# TODO: 'context' needs the attrs above (ducktype), but not __call__.
|
||||
def __new__(cls, context: make_scanner) -> Self: ...
|
||||
def __call__(self, string: str, index: int) -> tuple[Any, int]: ...
|
||||
|
||||
def encode_basestring(s: str, /) -> str: ...
|
||||
def encode_basestring_ascii(s: str, /) -> str: ...
|
||||
def scanstring(string: str, end: int, strict: bool = ...) -> tuple[str, int]: ...
|
||||
121
crates/red_knot_vendored/vendor/typeshed/stdlib/_locale.pyi
vendored
Normal file
121
crates/red_knot_vendored/vendor/typeshed/stdlib/_locale.pyi
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
import sys
|
||||
from _typeshed import StrPath
|
||||
from typing import Final, Literal, TypedDict, type_check_only
|
||||
|
||||
@type_check_only
|
||||
class _LocaleConv(TypedDict):
|
||||
decimal_point: str
|
||||
grouping: list[int]
|
||||
thousands_sep: str
|
||||
int_curr_symbol: str
|
||||
currency_symbol: str
|
||||
p_cs_precedes: Literal[0, 1, 127]
|
||||
n_cs_precedes: Literal[0, 1, 127]
|
||||
p_sep_by_space: Literal[0, 1, 127]
|
||||
n_sep_by_space: Literal[0, 1, 127]
|
||||
mon_decimal_point: str
|
||||
frac_digits: int
|
||||
int_frac_digits: int
|
||||
mon_thousands_sep: str
|
||||
mon_grouping: list[int]
|
||||
positive_sign: str
|
||||
negative_sign: str
|
||||
p_sign_posn: Literal[0, 1, 2, 3, 4, 127]
|
||||
n_sign_posn: Literal[0, 1, 2, 3, 4, 127]
|
||||
|
||||
LC_CTYPE: Final[int]
|
||||
LC_COLLATE: Final[int]
|
||||
LC_TIME: Final[int]
|
||||
LC_MONETARY: Final[int]
|
||||
LC_NUMERIC: Final[int]
|
||||
LC_ALL: Final[int]
|
||||
CHAR_MAX: Final = 127
|
||||
|
||||
def setlocale(category: int, locale: str | None = None, /) -> str: ...
|
||||
def localeconv() -> _LocaleConv: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def getencoding() -> str: ...
|
||||
|
||||
def strcoll(os1: str, os2: str, /) -> int: ...
|
||||
def strxfrm(string: str, /) -> str: ...
|
||||
|
||||
# native gettext functions
|
||||
# https://docs.python.org/3/library/locale.html#access-to-message-catalogs
|
||||
# https://github.com/python/cpython/blob/f4c03484da59049eb62a9bf7777b963e2267d187/Modules/_localemodule.c#L626
|
||||
if sys.platform != "win32":
|
||||
LC_MESSAGES: int
|
||||
|
||||
ABDAY_1: Final[int]
|
||||
ABDAY_2: Final[int]
|
||||
ABDAY_3: Final[int]
|
||||
ABDAY_4: Final[int]
|
||||
ABDAY_5: Final[int]
|
||||
ABDAY_6: Final[int]
|
||||
ABDAY_7: Final[int]
|
||||
|
||||
ABMON_1: Final[int]
|
||||
ABMON_2: Final[int]
|
||||
ABMON_3: Final[int]
|
||||
ABMON_4: Final[int]
|
||||
ABMON_5: Final[int]
|
||||
ABMON_6: Final[int]
|
||||
ABMON_7: Final[int]
|
||||
ABMON_8: Final[int]
|
||||
ABMON_9: Final[int]
|
||||
ABMON_10: Final[int]
|
||||
ABMON_11: Final[int]
|
||||
ABMON_12: Final[int]
|
||||
|
||||
DAY_1: Final[int]
|
||||
DAY_2: Final[int]
|
||||
DAY_3: Final[int]
|
||||
DAY_4: Final[int]
|
||||
DAY_5: Final[int]
|
||||
DAY_6: Final[int]
|
||||
DAY_7: Final[int]
|
||||
|
||||
ERA: Final[int]
|
||||
ERA_D_T_FMT: Final[int]
|
||||
ERA_D_FMT: Final[int]
|
||||
ERA_T_FMT: Final[int]
|
||||
|
||||
MON_1: Final[int]
|
||||
MON_2: Final[int]
|
||||
MON_3: Final[int]
|
||||
MON_4: Final[int]
|
||||
MON_5: Final[int]
|
||||
MON_6: Final[int]
|
||||
MON_7: Final[int]
|
||||
MON_8: Final[int]
|
||||
MON_9: Final[int]
|
||||
MON_10: Final[int]
|
||||
MON_11: Final[int]
|
||||
MON_12: Final[int]
|
||||
|
||||
CODESET: Final[int]
|
||||
D_T_FMT: Final[int]
|
||||
D_FMT: Final[int]
|
||||
T_FMT: Final[int]
|
||||
T_FMT_AMPM: Final[int]
|
||||
AM_STR: Final[int]
|
||||
PM_STR: Final[int]
|
||||
|
||||
RADIXCHAR: Final[int]
|
||||
THOUSEP: Final[int]
|
||||
YESEXPR: Final[int]
|
||||
NOEXPR: Final[int]
|
||||
CRNCYSTR: Final[int]
|
||||
ALT_DIGITS: Final[int]
|
||||
|
||||
def nl_langinfo(key: int, /) -> str: ...
|
||||
|
||||
# This is dependent on `libintl.h` which is a part of `gettext`
|
||||
# system dependency. These functions might be missing.
|
||||
# But, we always say that they are present.
|
||||
def gettext(msg: str, /) -> str: ...
|
||||
def dgettext(domain: str | None, msg: str, /) -> str: ...
|
||||
def dcgettext(domain: str | None, msg: str, category: int, /) -> str: ...
|
||||
def textdomain(domain: str | None, /) -> str: ...
|
||||
def bindtextdomain(domain: str, dir: StrPath | None, /) -> str: ...
|
||||
def bind_textdomain_codeset(domain: str, codeset: str | None, /) -> str | None: ...
|
||||
35
crates/red_knot_vendored/vendor/typeshed/stdlib/_lsprof.pyi
vendored
Normal file
35
crates/red_knot_vendored/vendor/typeshed/stdlib/_lsprof.pyi
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import sys
|
||||
from _typeshed import structseq
|
||||
from collections.abc import Callable
|
||||
from types import CodeType
|
||||
from typing import Any, Final, final
|
||||
|
||||
class Profiler:
|
||||
def __init__(
|
||||
self, timer: Callable[[], float] | None = None, timeunit: float = 0.0, subcalls: bool = True, builtins: bool = True
|
||||
) -> None: ...
|
||||
def getstats(self) -> list[profiler_entry]: ...
|
||||
def enable(self, subcalls: bool = True, builtins: bool = True) -> None: ...
|
||||
def disable(self) -> None: ...
|
||||
def clear(self) -> None: ...
|
||||
|
||||
@final
|
||||
class profiler_entry(structseq[Any], tuple[CodeType | str, int, int, float, float, list[profiler_subentry]]):
|
||||
if sys.version_info >= (3, 10):
|
||||
__match_args__: Final = ("code", "callcount", "reccallcount", "totaltime", "inlinetime", "calls")
|
||||
code: CodeType | str
|
||||
callcount: int
|
||||
reccallcount: int
|
||||
totaltime: float
|
||||
inlinetime: float
|
||||
calls: list[profiler_subentry]
|
||||
|
||||
@final
|
||||
class profiler_subentry(structseq[Any], tuple[CodeType | str, int, int, float, float]):
|
||||
if sys.version_info >= (3, 10):
|
||||
__match_args__: Final = ("code", "callcount", "reccallcount", "totaltime", "inlinetime")
|
||||
code: CodeType | str
|
||||
callcount: int
|
||||
reccallcount: int
|
||||
totaltime: float
|
||||
inlinetime: float
|
||||
71
crates/red_knot_vendored/vendor/typeshed/stdlib/_lzma.pyi
vendored
Normal file
71
crates/red_knot_vendored/vendor/typeshed/stdlib/_lzma.pyi
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import Any, Final, final
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
_FilterChain: TypeAlias = Sequence[Mapping[str, Any]]
|
||||
|
||||
FORMAT_AUTO: Final = 0
|
||||
FORMAT_XZ: Final = 1
|
||||
FORMAT_ALONE: Final = 2
|
||||
FORMAT_RAW: Final = 3
|
||||
CHECK_NONE: Final = 0
|
||||
CHECK_CRC32: Final = 1
|
||||
CHECK_CRC64: Final = 4
|
||||
CHECK_SHA256: Final = 10
|
||||
CHECK_ID_MAX: Final = 15
|
||||
CHECK_UNKNOWN: Final = 16
|
||||
FILTER_LZMA1: int # v big number
|
||||
FILTER_LZMA2: Final = 33
|
||||
FILTER_DELTA: Final = 3
|
||||
FILTER_X86: Final = 4
|
||||
FILTER_IA64: Final = 6
|
||||
FILTER_ARM: Final = 7
|
||||
FILTER_ARMTHUMB: Final = 8
|
||||
FILTER_SPARC: Final = 9
|
||||
FILTER_POWERPC: Final = 5
|
||||
MF_HC3: Final = 3
|
||||
MF_HC4: Final = 4
|
||||
MF_BT2: Final = 18
|
||||
MF_BT3: Final = 19
|
||||
MF_BT4: Final = 20
|
||||
MODE_FAST: Final = 1
|
||||
MODE_NORMAL: Final = 2
|
||||
PRESET_DEFAULT: Final = 6
|
||||
PRESET_EXTREME: int # v big number
|
||||
|
||||
@final
|
||||
class LZMADecompressor:
|
||||
if sys.version_info >= (3, 12):
|
||||
def __new__(cls, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> Self: ...
|
||||
else:
|
||||
def __init__(self, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> None: ...
|
||||
|
||||
def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
|
||||
@property
|
||||
def check(self) -> int: ...
|
||||
@property
|
||||
def eof(self) -> bool: ...
|
||||
@property
|
||||
def unused_data(self) -> bytes: ...
|
||||
@property
|
||||
def needs_input(self) -> bool: ...
|
||||
|
||||
@final
|
||||
class LZMACompressor:
|
||||
if sys.version_info >= (3, 12):
|
||||
def __new__(
|
||||
cls, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
|
||||
) -> Self: ...
|
||||
else:
|
||||
def __init__(
|
||||
self, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
|
||||
) -> None: ...
|
||||
|
||||
def compress(self, data: ReadableBuffer, /) -> bytes: ...
|
||||
def flush(self) -> bytes: ...
|
||||
|
||||
class LZMAError(Exception): ...
|
||||
|
||||
def is_check_supported(check_id: int, /) -> bool: ...
|
||||
16
crates/red_knot_vendored/vendor/typeshed/stdlib/_markupbase.pyi
vendored
Normal file
16
crates/red_knot_vendored/vendor/typeshed/stdlib/_markupbase.pyi
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
class ParserBase:
|
||||
def reset(self) -> None: ...
|
||||
def getpos(self) -> tuple[int, int]: ...
|
||||
def unknown_decl(self, data: str) -> None: ...
|
||||
def parse_comment(self, i: int, report: int = 1) -> int: ... # undocumented
|
||||
def parse_declaration(self, i: int) -> int: ... # undocumented
|
||||
def parse_marked_section(self, i: int, report: int = 1) -> int: ... # undocumented
|
||||
def updatepos(self, i: int, j: int) -> int: ... # undocumented
|
||||
if sys.version_info < (3, 10):
|
||||
# Removed from ParserBase: https://bugs.python.org/issue31844
|
||||
def error(self, message: str) -> Any: ... # undocumented
|
||||
lineno: int # undocumented
|
||||
offset: int # undocumented
|
||||
92
crates/red_knot_vendored/vendor/typeshed/stdlib/_msi.pyi
vendored
Normal file
92
crates/red_knot_vendored/vendor/typeshed/stdlib/_msi.pyi
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
import sys
|
||||
|
||||
if sys.platform == "win32":
|
||||
class MSIError(Exception): ...
|
||||
# Actual typename View, not exposed by the implementation
|
||||
class _View:
|
||||
def Execute(self, params: _Record | None = ...) -> None: ...
|
||||
def GetColumnInfo(self, kind: int) -> _Record: ...
|
||||
def Fetch(self) -> _Record: ...
|
||||
def Modify(self, mode: int, record: _Record) -> None: ...
|
||||
def Close(self) -> None: ...
|
||||
# Don't exist at runtime
|
||||
__new__: None # type: ignore[assignment]
|
||||
__init__: None # type: ignore[assignment]
|
||||
|
||||
# Actual typename SummaryInformation, not exposed by the implementation
|
||||
class _SummaryInformation:
|
||||
def GetProperty(self, field: int) -> int | bytes | None: ...
|
||||
def GetPropertyCount(self) -> int: ...
|
||||
def SetProperty(self, field: int, value: int | str) -> None: ...
|
||||
def Persist(self) -> None: ...
|
||||
# Don't exist at runtime
|
||||
__new__: None # type: ignore[assignment]
|
||||
__init__: None # type: ignore[assignment]
|
||||
|
||||
# Actual typename Database, not exposed by the implementation
|
||||
class _Database:
|
||||
def OpenView(self, sql: str) -> _View: ...
|
||||
def Commit(self) -> None: ...
|
||||
def GetSummaryInformation(self, updateCount: int) -> _SummaryInformation: ...
|
||||
def Close(self) -> None: ...
|
||||
# Don't exist at runtime
|
||||
__new__: None # type: ignore[assignment]
|
||||
__init__: None # type: ignore[assignment]
|
||||
|
||||
# Actual typename Record, not exposed by the implementation
|
||||
class _Record:
|
||||
def GetFieldCount(self) -> int: ...
|
||||
def GetInteger(self, field: int) -> int: ...
|
||||
def GetString(self, field: int) -> str: ...
|
||||
def SetString(self, field: int, str: str) -> None: ...
|
||||
def SetStream(self, field: int, stream: str) -> None: ...
|
||||
def SetInteger(self, field: int, int: int) -> None: ...
|
||||
def ClearData(self) -> None: ...
|
||||
# Don't exist at runtime
|
||||
__new__: None # type: ignore[assignment]
|
||||
__init__: None # type: ignore[assignment]
|
||||
|
||||
def UuidCreate() -> str: ...
|
||||
def FCICreate(cabname: str, files: list[str], /) -> None: ...
|
||||
def OpenDatabase(path: str, persist: int, /) -> _Database: ...
|
||||
def CreateRecord(count: int, /) -> _Record: ...
|
||||
|
||||
MSICOLINFO_NAMES: int
|
||||
MSICOLINFO_TYPES: int
|
||||
MSIDBOPEN_CREATE: int
|
||||
MSIDBOPEN_CREATEDIRECT: int
|
||||
MSIDBOPEN_DIRECT: int
|
||||
MSIDBOPEN_PATCHFILE: int
|
||||
MSIDBOPEN_READONLY: int
|
||||
MSIDBOPEN_TRANSACT: int
|
||||
MSIMODIFY_ASSIGN: int
|
||||
MSIMODIFY_DELETE: int
|
||||
MSIMODIFY_INSERT: int
|
||||
MSIMODIFY_INSERT_TEMPORARY: int
|
||||
MSIMODIFY_MERGE: int
|
||||
MSIMODIFY_REFRESH: int
|
||||
MSIMODIFY_REPLACE: int
|
||||
MSIMODIFY_SEEK: int
|
||||
MSIMODIFY_UPDATE: int
|
||||
MSIMODIFY_VALIDATE: int
|
||||
MSIMODIFY_VALIDATE_DELETE: int
|
||||
MSIMODIFY_VALIDATE_FIELD: int
|
||||
MSIMODIFY_VALIDATE_NEW: int
|
||||
|
||||
PID_APPNAME: int
|
||||
PID_AUTHOR: int
|
||||
PID_CHARCOUNT: int
|
||||
PID_CODEPAGE: int
|
||||
PID_COMMENTS: int
|
||||
PID_CREATE_DTM: int
|
||||
PID_KEYWORDS: int
|
||||
PID_LASTAUTHOR: int
|
||||
PID_LASTPRINTED: int
|
||||
PID_LASTSAVE_DTM: int
|
||||
PID_PAGECOUNT: int
|
||||
PID_REVNUMBER: int
|
||||
PID_SECURITY: int
|
||||
PID_SUBJECT: int
|
||||
PID_TEMPLATE: int
|
||||
PID_TITLE: int
|
||||
PID_WORDCOUNT: int
|
||||
44
crates/red_knot_vendored/vendor/typeshed/stdlib/_multibytecodec.pyi
vendored
Normal file
44
crates/red_knot_vendored/vendor/typeshed/stdlib/_multibytecodec.pyi
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
from _typeshed import ReadableBuffer
|
||||
from codecs import _ReadableStream, _WritableStream
|
||||
from collections.abc import Iterable
|
||||
from typing import final, type_check_only
|
||||
|
||||
# This class is not exposed. It calls itself _multibytecodec.MultibyteCodec.
|
||||
@final
|
||||
@type_check_only
|
||||
class _MultibyteCodec:
|
||||
def decode(self, input: ReadableBuffer, errors: str | None = None) -> str: ...
|
||||
def encode(self, input: str, errors: str | None = None) -> bytes: ...
|
||||
|
||||
class MultibyteIncrementalDecoder:
|
||||
errors: str
|
||||
def __init__(self, errors: str = "strict") -> None: ...
|
||||
def decode(self, input: ReadableBuffer, final: bool = False) -> str: ...
|
||||
def getstate(self) -> tuple[bytes, int]: ...
|
||||
def reset(self) -> None: ...
|
||||
def setstate(self, state: tuple[bytes, int], /) -> None: ...
|
||||
|
||||
class MultibyteIncrementalEncoder:
|
||||
errors: str
|
||||
def __init__(self, errors: str = "strict") -> None: ...
|
||||
def encode(self, input: str, final: bool = False) -> bytes: ...
|
||||
def getstate(self) -> int: ...
|
||||
def reset(self) -> None: ...
|
||||
def setstate(self, state: int, /) -> None: ...
|
||||
|
||||
class MultibyteStreamReader:
|
||||
errors: str
|
||||
stream: _ReadableStream
|
||||
def __init__(self, stream: _ReadableStream, errors: str = "strict") -> None: ...
|
||||
def read(self, sizeobj: int | None = None, /) -> str: ...
|
||||
def readline(self, sizeobj: int | None = None, /) -> str: ...
|
||||
def readlines(self, sizehintobj: int | None = None, /) -> list[str]: ...
|
||||
def reset(self) -> None: ...
|
||||
|
||||
class MultibyteStreamWriter:
|
||||
errors: str
|
||||
stream: _WritableStream
|
||||
def __init__(self, stream: _WritableStream, errors: str = "strict") -> None: ...
|
||||
def reset(self) -> None: ...
|
||||
def write(self, strobj: str, /) -> None: ...
|
||||
def writelines(self, lines: Iterable[str], /) -> None: ...
|
||||
115
crates/red_knot_vendored/vendor/typeshed/stdlib/_operator.pyi
vendored
Normal file
115
crates/red_knot_vendored/vendor/typeshed/stdlib/_operator.pyi
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
import sys
|
||||
from _typeshed import SupportsGetItem
|
||||
from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence
|
||||
from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller
|
||||
from typing import Any, AnyStr, Protocol, SupportsAbs, SupportsIndex, TypeVar, overload
|
||||
from typing_extensions import ParamSpec, TypeAlias, TypeIs
|
||||
|
||||
_R = TypeVar("_R")
|
||||
_T = TypeVar("_T")
|
||||
_T_co = TypeVar("_T_co", covariant=True)
|
||||
_K = TypeVar("_K")
|
||||
_V = TypeVar("_V")
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
# The following protocols return "Any" instead of bool, since the comparison
|
||||
# operators can be overloaded to return an arbitrary object. For example,
|
||||
# the numpy.array comparison dunders return another numpy.array.
|
||||
|
||||
class _SupportsDunderLT(Protocol):
|
||||
def __lt__(self, other: Any, /) -> Any: ...
|
||||
|
||||
class _SupportsDunderGT(Protocol):
|
||||
def __gt__(self, other: Any, /) -> Any: ...
|
||||
|
||||
class _SupportsDunderLE(Protocol):
|
||||
def __le__(self, other: Any, /) -> Any: ...
|
||||
|
||||
class _SupportsDunderGE(Protocol):
|
||||
def __ge__(self, other: Any, /) -> Any: ...
|
||||
|
||||
_SupportsComparison: TypeAlias = _SupportsDunderLE | _SupportsDunderGE | _SupportsDunderGT | _SupportsDunderLT
|
||||
|
||||
class _SupportsInversion(Protocol[_T_co]):
|
||||
def __invert__(self) -> _T_co: ...
|
||||
|
||||
class _SupportsNeg(Protocol[_T_co]):
|
||||
def __neg__(self) -> _T_co: ...
|
||||
|
||||
class _SupportsPos(Protocol[_T_co]):
|
||||
def __pos__(self) -> _T_co: ...
|
||||
|
||||
# All four comparison functions must have the same signature, or we get false-positive errors
|
||||
def lt(a: _SupportsComparison, b: _SupportsComparison, /) -> Any: ...
|
||||
def le(a: _SupportsComparison, b: _SupportsComparison, /) -> Any: ...
|
||||
def eq(a: object, b: object, /) -> Any: ...
|
||||
def ne(a: object, b: object, /) -> Any: ...
|
||||
def ge(a: _SupportsComparison, b: _SupportsComparison, /) -> Any: ...
|
||||
def gt(a: _SupportsComparison, b: _SupportsComparison, /) -> Any: ...
|
||||
def not_(a: object, /) -> bool: ...
|
||||
def truth(a: object, /) -> bool: ...
|
||||
def is_(a: object, b: object, /) -> bool: ...
|
||||
def is_not(a: object, b: object, /) -> bool: ...
|
||||
def abs(a: SupportsAbs[_T], /) -> _T: ...
|
||||
def add(a: Any, b: Any, /) -> Any: ...
|
||||
def and_(a: Any, b: Any, /) -> Any: ...
|
||||
def floordiv(a: Any, b: Any, /) -> Any: ...
|
||||
def index(a: SupportsIndex, /) -> int: ...
|
||||
def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ...
|
||||
def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ...
|
||||
def lshift(a: Any, b: Any, /) -> Any: ...
|
||||
def mod(a: Any, b: Any, /) -> Any: ...
|
||||
def mul(a: Any, b: Any, /) -> Any: ...
|
||||
def matmul(a: Any, b: Any, /) -> Any: ...
|
||||
def neg(a: _SupportsNeg[_T_co], /) -> _T_co: ...
|
||||
def or_(a: Any, b: Any, /) -> Any: ...
|
||||
def pos(a: _SupportsPos[_T_co], /) -> _T_co: ...
|
||||
def pow(a: Any, b: Any, /) -> Any: ...
|
||||
def rshift(a: Any, b: Any, /) -> Any: ...
|
||||
def sub(a: Any, b: Any, /) -> Any: ...
|
||||
def truediv(a: Any, b: Any, /) -> Any: ...
|
||||
def xor(a: Any, b: Any, /) -> Any: ...
|
||||
def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ...
|
||||
def contains(a: Container[object], b: object, /) -> bool: ...
|
||||
def countOf(a: Iterable[object], b: object, /) -> int: ...
|
||||
@overload
|
||||
def delitem(a: MutableSequence[Any], b: SupportsIndex, /) -> None: ...
|
||||
@overload
|
||||
def delitem(a: MutableSequence[Any], b: slice, /) -> None: ...
|
||||
@overload
|
||||
def delitem(a: MutableMapping[_K, Any], b: _K, /) -> None: ...
|
||||
@overload
|
||||
def getitem(a: Sequence[_T], b: slice, /) -> Sequence[_T]: ...
|
||||
@overload
|
||||
def getitem(a: SupportsGetItem[_K, _V], b: _K, /) -> _V: ...
|
||||
def indexOf(a: Iterable[_T], b: _T, /) -> int: ...
|
||||
@overload
|
||||
def setitem(a: MutableSequence[_T], b: SupportsIndex, c: _T, /) -> None: ...
|
||||
@overload
|
||||
def setitem(a: MutableSequence[_T], b: slice, c: Sequence[_T], /) -> None: ...
|
||||
@overload
|
||||
def setitem(a: MutableMapping[_K, _V], b: _K, c: _V, /) -> None: ...
|
||||
def length_hint(obj: object, default: int = 0, /) -> int: ...
|
||||
def iadd(a: Any, b: Any, /) -> Any: ...
|
||||
def iand(a: Any, b: Any, /) -> Any: ...
|
||||
def iconcat(a: Any, b: Any, /) -> Any: ...
|
||||
def ifloordiv(a: Any, b: Any, /) -> Any: ...
|
||||
def ilshift(a: Any, b: Any, /) -> Any: ...
|
||||
def imod(a: Any, b: Any, /) -> Any: ...
|
||||
def imul(a: Any, b: Any, /) -> Any: ...
|
||||
def imatmul(a: Any, b: Any, /) -> Any: ...
|
||||
def ior(a: Any, b: Any, /) -> Any: ...
|
||||
def ipow(a: Any, b: Any, /) -> Any: ...
|
||||
def irshift(a: Any, b: Any, /) -> Any: ...
|
||||
def isub(a: Any, b: Any, /) -> Any: ...
|
||||
def itruediv(a: Any, b: Any, /) -> Any: ...
|
||||
def ixor(a: Any, b: Any, /) -> Any: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def call(obj: Callable[_P, _R], /, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
|
||||
|
||||
def _compare_digest(a: AnyStr, b: AnyStr, /) -> bool: ...
|
||||
|
||||
if sys.version_info >= (3, 14):
|
||||
def is_none(a: object, /) -> TypeIs[None]: ...
|
||||
def is_not_none(a: _T | None, /) -> TypeIs[_T]: ...
|
||||
34
crates/red_knot_vendored/vendor/typeshed/stdlib/_osx_support.pyi
vendored
Normal file
34
crates/red_knot_vendored/vendor/typeshed/stdlib/_osx_support.pyi
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
from collections.abc import Iterable, Sequence
|
||||
from typing import Final, TypeVar
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_K = TypeVar("_K")
|
||||
_V = TypeVar("_V")
|
||||
|
||||
__all__ = ["compiler_fixup", "customize_config_vars", "customize_compiler", "get_platform_osx"]
|
||||
|
||||
_UNIVERSAL_CONFIG_VARS: Final[tuple[str, ...]] # undocumented
|
||||
_COMPILER_CONFIG_VARS: Final[tuple[str, ...]] # undocumented
|
||||
_INITPRE: Final[str] # undocumented
|
||||
|
||||
def _find_executable(executable: str, path: str | None = None) -> str | None: ... # undocumented
|
||||
def _read_output(commandstring: str, capture_stderr: bool = False) -> str | None: ... # undocumented
|
||||
def _find_build_tool(toolname: str) -> str: ... # undocumented
|
||||
|
||||
_SYSTEM_VERSION: Final[str | None] # undocumented
|
||||
|
||||
def _get_system_version() -> str: ... # undocumented
|
||||
def _remove_original_values(_config_vars: dict[str, str]) -> None: ... # undocumented
|
||||
def _save_modified_value(_config_vars: dict[str, str], cv: str, newvalue: str) -> None: ... # undocumented
|
||||
def _supports_universal_builds() -> bool: ... # undocumented
|
||||
def _find_appropriate_compiler(_config_vars: dict[str, str]) -> dict[str, str]: ... # undocumented
|
||||
def _remove_universal_flags(_config_vars: dict[str, str]) -> dict[str, str]: ... # undocumented
|
||||
def _remove_unsupported_archs(_config_vars: dict[str, str]) -> dict[str, str]: ... # undocumented
|
||||
def _override_all_archs(_config_vars: dict[str, str]) -> dict[str, str]: ... # undocumented
|
||||
def _check_for_unavailable_sdk(_config_vars: dict[str, str]) -> dict[str, str]: ... # undocumented
|
||||
def compiler_fixup(compiler_so: Iterable[str], cc_args: Sequence[str]) -> list[str]: ...
|
||||
def customize_config_vars(_config_vars: dict[str, str]) -> dict[str, str]: ...
|
||||
def customize_compiler(_config_vars: dict[str, str]) -> dict[str, str]: ...
|
||||
def get_platform_osx(
|
||||
_config_vars: dict[str, str], osname: _T, release: _K, machine: _V
|
||||
) -> tuple[str | _T, str | _K, str | _V]: ...
|
||||
104
crates/red_knot_vendored/vendor/typeshed/stdlib/_pickle.pyi
vendored
Normal file
104
crates/red_knot_vendored/vendor/typeshed/stdlib/_pickle.pyi
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
from _typeshed import ReadableBuffer, SupportsWrite
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping
|
||||
from pickle import PickleBuffer as PickleBuffer
|
||||
from typing import Any, Protocol, type_check_only
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
class _ReadableFileobj(Protocol):
|
||||
def read(self, n: int, /) -> bytes: ...
|
||||
def readline(self) -> bytes: ...
|
||||
|
||||
_BufferCallback: TypeAlias = Callable[[PickleBuffer], Any] | None
|
||||
|
||||
_ReducedType: TypeAlias = (
|
||||
str
|
||||
| tuple[Callable[..., Any], tuple[Any, ...]]
|
||||
| tuple[Callable[..., Any], tuple[Any, ...], Any]
|
||||
| tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None]
|
||||
| tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None]
|
||||
)
|
||||
|
||||
def dump(
|
||||
obj: Any,
|
||||
file: SupportsWrite[bytes],
|
||||
protocol: int | None = None,
|
||||
*,
|
||||
fix_imports: bool = True,
|
||||
buffer_callback: _BufferCallback = None,
|
||||
) -> None: ...
|
||||
def dumps(
|
||||
obj: Any, protocol: int | None = None, *, fix_imports: bool = True, buffer_callback: _BufferCallback = None
|
||||
) -> bytes: ...
|
||||
def load(
|
||||
file: _ReadableFileobj,
|
||||
*,
|
||||
fix_imports: bool = True,
|
||||
encoding: str = "ASCII",
|
||||
errors: str = "strict",
|
||||
buffers: Iterable[Any] | None = (),
|
||||
) -> Any: ...
|
||||
def loads(
|
||||
data: ReadableBuffer,
|
||||
/,
|
||||
*,
|
||||
fix_imports: bool = True,
|
||||
encoding: str = "ASCII",
|
||||
errors: str = "strict",
|
||||
buffers: Iterable[Any] | None = (),
|
||||
) -> Any: ...
|
||||
|
||||
class PickleError(Exception): ...
|
||||
class PicklingError(PickleError): ...
|
||||
class UnpicklingError(PickleError): ...
|
||||
|
||||
@type_check_only
|
||||
class PicklerMemoProxy:
|
||||
def clear(self, /) -> None: ...
|
||||
def copy(self, /) -> dict[int, tuple[int, Any]]: ...
|
||||
|
||||
class Pickler:
|
||||
fast: bool
|
||||
dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
|
||||
reducer_override: Callable[[Any], Any]
|
||||
bin: bool # undocumented
|
||||
def __init__(
|
||||
self,
|
||||
file: SupportsWrite[bytes],
|
||||
protocol: int | None = None,
|
||||
fix_imports: bool = True,
|
||||
buffer_callback: _BufferCallback = None,
|
||||
) -> None: ...
|
||||
@property
|
||||
def memo(self) -> PicklerMemoProxy: ...
|
||||
@memo.setter
|
||||
def memo(self, value: PicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
|
||||
def dump(self, obj: Any, /) -> None: ...
|
||||
def clear_memo(self) -> None: ...
|
||||
|
||||
# this method has no default implementation for Python < 3.13
|
||||
def persistent_id(self, obj: Any, /) -> Any: ...
|
||||
|
||||
@type_check_only
|
||||
class UnpicklerMemoProxy:
|
||||
def clear(self, /) -> None: ...
|
||||
def copy(self, /) -> dict[int, tuple[int, Any]]: ...
|
||||
|
||||
class Unpickler:
|
||||
def __init__(
|
||||
self,
|
||||
file: _ReadableFileobj,
|
||||
*,
|
||||
fix_imports: bool = True,
|
||||
encoding: str = "ASCII",
|
||||
errors: str = "strict",
|
||||
buffers: Iterable[Any] | None = (),
|
||||
) -> None: ...
|
||||
@property
|
||||
def memo(self) -> UnpicklerMemoProxy: ...
|
||||
@memo.setter
|
||||
def memo(self, value: UnpicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
|
||||
def load(self) -> Any: ...
|
||||
def find_class(self, module_name: str, global_name: str, /) -> Any: ...
|
||||
|
||||
# this method has no default implementation for Python < 3.13
|
||||
def persistent_load(self, pid: Any, /) -> Any: ...
|
||||
32
crates/red_knot_vendored/vendor/typeshed/stdlib/_posixsubprocess.pyi
vendored
Normal file
32
crates/red_knot_vendored/vendor/typeshed/stdlib/_posixsubprocess.pyi
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import sys
|
||||
from _typeshed import StrOrBytesPath
|
||||
from collections.abc import Callable, Sequence
|
||||
from typing import SupportsIndex
|
||||
|
||||
if sys.platform != "win32":
|
||||
def fork_exec(
|
||||
args: Sequence[StrOrBytesPath] | None,
|
||||
executable_list: Sequence[bytes],
|
||||
close_fds: bool,
|
||||
pass_fds: tuple[int, ...],
|
||||
cwd: str,
|
||||
env: Sequence[bytes] | None,
|
||||
p2cread: int,
|
||||
p2cwrite: int,
|
||||
c2pread: int,
|
||||
c2pwrite: int,
|
||||
errread: int,
|
||||
errwrite: int,
|
||||
errpipe_read: int,
|
||||
errpipe_write: int,
|
||||
restore_signals: int,
|
||||
call_setsid: int,
|
||||
pgid_to_set: int,
|
||||
gid: SupportsIndex | None,
|
||||
extra_groups: list[int] | None,
|
||||
uid: SupportsIndex | None,
|
||||
child_umask: int,
|
||||
preexec_fn: Callable[[], None],
|
||||
allow_vfork: bool,
|
||||
/,
|
||||
) -> int: ...
|
||||
14
crates/red_knot_vendored/vendor/typeshed/stdlib/_py_abc.pyi
vendored
Normal file
14
crates/red_knot_vendored/vendor/typeshed/stdlib/_py_abc.pyi
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import _typeshed
|
||||
from typing import Any, NewType, TypeVar
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
_CacheToken = NewType("_CacheToken", int)
|
||||
|
||||
def get_cache_token() -> _CacheToken: ...
|
||||
|
||||
class ABCMeta(type):
|
||||
def __new__(
|
||||
mcls: type[_typeshed.Self], name: str, bases: tuple[type[Any], ...], namespace: dict[str, Any], /
|
||||
) -> _typeshed.Self: ...
|
||||
def register(cls, subclass: type[_T]) -> type[_T]: ...
|
||||
43
crates/red_knot_vendored/vendor/typeshed/stdlib/_pydecimal.pyi
vendored
Normal file
43
crates/red_knot_vendored/vendor/typeshed/stdlib/_pydecimal.pyi
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
# This is a slight lie, the implementations aren't exactly identical
|
||||
# However, in all likelihood, the differences are inconsequential
|
||||
from _decimal import *
|
||||
|
||||
__all__ = [
|
||||
"Decimal",
|
||||
"Context",
|
||||
"DecimalTuple",
|
||||
"DefaultContext",
|
||||
"BasicContext",
|
||||
"ExtendedContext",
|
||||
"DecimalException",
|
||||
"Clamped",
|
||||
"InvalidOperation",
|
||||
"DivisionByZero",
|
||||
"Inexact",
|
||||
"Rounded",
|
||||
"Subnormal",
|
||||
"Overflow",
|
||||
"Underflow",
|
||||
"FloatOperation",
|
||||
"DivisionImpossible",
|
||||
"InvalidContext",
|
||||
"ConversionSyntax",
|
||||
"DivisionUndefined",
|
||||
"ROUND_DOWN",
|
||||
"ROUND_HALF_UP",
|
||||
"ROUND_HALF_EVEN",
|
||||
"ROUND_CEILING",
|
||||
"ROUND_FLOOR",
|
||||
"ROUND_UP",
|
||||
"ROUND_HALF_DOWN",
|
||||
"ROUND_05UP",
|
||||
"setcontext",
|
||||
"getcontext",
|
||||
"localcontext",
|
||||
"MAX_PREC",
|
||||
"MAX_EMAX",
|
||||
"MIN_EMIN",
|
||||
"MIN_ETINY",
|
||||
"HAVE_THREADS",
|
||||
"HAVE_CONTEXTVAR",
|
||||
]
|
||||
16
crates/red_knot_vendored/vendor/typeshed/stdlib/_queue.pyi
vendored
Normal file
16
crates/red_knot_vendored/vendor/typeshed/stdlib/_queue.pyi
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
from types import GenericAlias
|
||||
from typing import Any, Generic, TypeVar
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
class Empty(Exception): ...
|
||||
|
||||
class SimpleQueue(Generic[_T]):
|
||||
def __init__(self) -> None: ...
|
||||
def empty(self) -> bool: ...
|
||||
def get(self, block: bool = True, timeout: float | None = None) -> _T: ...
|
||||
def get_nowait(self) -> _T: ...
|
||||
def put(self, item: _T, block: bool = True, timeout: float | None = None) -> None: ...
|
||||
def put_nowait(self, item: _T) -> None: ...
|
||||
def qsize(self) -> int: ...
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
12
crates/red_knot_vendored/vendor/typeshed/stdlib/_random.pyi
vendored
Normal file
12
crates/red_knot_vendored/vendor/typeshed/stdlib/_random.pyi
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
# Actually Tuple[(int,) * 625]
|
||||
_State: TypeAlias = tuple[int, ...]
|
||||
|
||||
class Random:
|
||||
def __init__(self, seed: object = ...) -> None: ...
|
||||
def seed(self, n: object = None, /) -> None: ...
|
||||
def getstate(self) -> _State: ...
|
||||
def setstate(self, state: _State, /) -> None: ...
|
||||
def random(self) -> float: ...
|
||||
def getrandbits(self, k: int, /) -> int: ...
|
||||
17
crates/red_knot_vendored/vendor/typeshed/stdlib/_sitebuiltins.pyi
vendored
Normal file
17
crates/red_knot_vendored/vendor/typeshed/stdlib/_sitebuiltins.pyi
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import sys
|
||||
from collections.abc import Iterable
|
||||
from typing import ClassVar, Literal, NoReturn
|
||||
|
||||
class Quitter:
|
||||
name: str
|
||||
eof: str
|
||||
def __init__(self, name: str, eof: str) -> None: ...
|
||||
def __call__(self, code: sys._ExitCode = None) -> NoReturn: ...
|
||||
|
||||
class _Printer:
|
||||
MAXLINES: ClassVar[Literal[23]]
|
||||
def __init__(self, name: str, data: str, files: Iterable[str] = (), dirs: Iterable[str] = ()) -> None: ...
|
||||
def __call__(self) -> None: ...
|
||||
|
||||
class _Helper:
|
||||
def __call__(self, request: object = ...) -> None: ...
|
||||
834
crates/red_knot_vendored/vendor/typeshed/stdlib/_socket.pyi
vendored
Normal file
834
crates/red_knot_vendored/vendor/typeshed/stdlib/_socket.pyi
vendored
Normal file
@@ -0,0 +1,834 @@
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer, WriteableBuffer
|
||||
from collections.abc import Iterable
|
||||
from socket import error as error, gaierror as gaierror, herror as herror, timeout as timeout
|
||||
from typing import Any, SupportsIndex, overload
|
||||
from typing_extensions import CapsuleType, TypeAlias
|
||||
|
||||
_CMSG: TypeAlias = tuple[int, int, bytes]
|
||||
_CMSGArg: TypeAlias = tuple[int, int, ReadableBuffer]
|
||||
|
||||
# Addresses can be either tuples of varying lengths (AF_INET, AF_INET6,
|
||||
# AF_NETLINK, AF_TIPC) or strings/buffers (AF_UNIX).
|
||||
# See getsockaddrarg() in socketmodule.c.
|
||||
_Address: TypeAlias = tuple[Any, ...] | str | ReadableBuffer
|
||||
_RetAddress: TypeAlias = Any
|
||||
|
||||
# ===== Constants =====
|
||||
# This matches the order in the CPython documentation
|
||||
# https://docs.python.org/3/library/socket.html#constants
|
||||
|
||||
if sys.platform != "win32":
|
||||
AF_UNIX: int
|
||||
|
||||
AF_INET: int
|
||||
AF_INET6: int
|
||||
|
||||
AF_UNSPEC: int
|
||||
|
||||
SOCK_STREAM: int
|
||||
SOCK_DGRAM: int
|
||||
SOCK_RAW: int
|
||||
SOCK_RDM: int
|
||||
SOCK_SEQPACKET: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 2.6.27
|
||||
SOCK_CLOEXEC: int
|
||||
SOCK_NONBLOCK: int
|
||||
|
||||
# --------------------
|
||||
# Many constants of these forms, documented in the Unix documentation on
|
||||
# sockets and/or the IP protocol, are also defined in the socket module.
|
||||
# SO_*
|
||||
# socket.SOMAXCONN
|
||||
# MSG_*
|
||||
# SOL_*
|
||||
# SCM_*
|
||||
# IPPROTO_*
|
||||
# IPPORT_*
|
||||
# INADDR_*
|
||||
# IP_*
|
||||
# IPV6_*
|
||||
# EAI_*
|
||||
# AI_*
|
||||
# NI_*
|
||||
# TCP_*
|
||||
# --------------------
|
||||
|
||||
SO_ACCEPTCONN: int
|
||||
SO_BROADCAST: int
|
||||
SO_DEBUG: int
|
||||
SO_DONTROUTE: int
|
||||
SO_ERROR: int
|
||||
SO_KEEPALIVE: int
|
||||
SO_LINGER: int
|
||||
SO_OOBINLINE: int
|
||||
SO_RCVBUF: int
|
||||
SO_RCVLOWAT: int
|
||||
SO_RCVTIMEO: int
|
||||
SO_REUSEADDR: int
|
||||
SO_SNDBUF: int
|
||||
SO_SNDLOWAT: int
|
||||
SO_SNDTIMEO: int
|
||||
SO_TYPE: int
|
||||
if sys.platform != "linux":
|
||||
SO_USELOOPBACK: int
|
||||
if sys.platform == "win32":
|
||||
SO_EXCLUSIVEADDRUSE: int
|
||||
if sys.platform != "win32":
|
||||
SO_REUSEPORT: int
|
||||
if sys.platform != "darwin" or sys.version_info >= (3, 13):
|
||||
SO_BINDTODEVICE: int
|
||||
|
||||
if sys.platform != "win32" and sys.platform != "darwin":
|
||||
SO_DOMAIN: int
|
||||
SO_MARK: int
|
||||
SO_PASSCRED: int
|
||||
SO_PASSSEC: int
|
||||
SO_PEERCRED: int
|
||||
SO_PEERSEC: int
|
||||
SO_PRIORITY: int
|
||||
SO_PROTOCOL: int
|
||||
if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux":
|
||||
SO_SETFIB: int
|
||||
if sys.platform == "linux" and sys.version_info >= (3, 13):
|
||||
SO_BINDTOIFINDEX: int
|
||||
|
||||
SOMAXCONN: int
|
||||
|
||||
MSG_CTRUNC: int
|
||||
MSG_DONTROUTE: int
|
||||
MSG_OOB: int
|
||||
MSG_PEEK: int
|
||||
MSG_TRUNC: int
|
||||
MSG_WAITALL: int
|
||||
if sys.platform != "win32":
|
||||
MSG_DONTWAIT: int
|
||||
MSG_EOR: int
|
||||
MSG_NOSIGNAL: int # Sometimes this exists on darwin, sometimes not
|
||||
if sys.platform != "darwin":
|
||||
MSG_ERRQUEUE: int
|
||||
if sys.platform == "win32":
|
||||
MSG_BCAST: int
|
||||
MSG_MCAST: int
|
||||
if sys.platform != "win32" and sys.platform != "darwin":
|
||||
MSG_CMSG_CLOEXEC: int
|
||||
MSG_CONFIRM: int
|
||||
MSG_FASTOPEN: int
|
||||
MSG_MORE: int
|
||||
if sys.platform != "win32" and sys.platform != "linux":
|
||||
MSG_EOF: int
|
||||
if sys.platform != "win32" and sys.platform != "linux" and sys.platform != "darwin":
|
||||
MSG_NOTIFICATION: int
|
||||
MSG_BTAG: int # Not FreeBSD either
|
||||
MSG_ETAG: int # Not FreeBSD either
|
||||
|
||||
SOL_IP: int
|
||||
SOL_SOCKET: int
|
||||
SOL_TCP: int
|
||||
SOL_UDP: int
|
||||
if sys.platform != "win32" and sys.platform != "darwin":
|
||||
# Defined in socket.h for Linux, but these aren't always present for
|
||||
# some reason.
|
||||
SOL_ATALK: int
|
||||
SOL_AX25: int
|
||||
SOL_HCI: int
|
||||
SOL_IPX: int
|
||||
SOL_NETROM: int
|
||||
SOL_ROSE: int
|
||||
|
||||
if sys.platform != "win32":
|
||||
SCM_RIGHTS: int
|
||||
if sys.platform != "win32" and sys.platform != "darwin":
|
||||
SCM_CREDENTIALS: int
|
||||
if sys.platform != "win32" and sys.platform != "linux":
|
||||
SCM_CREDS: int
|
||||
|
||||
IPPROTO_ICMP: int
|
||||
IPPROTO_IP: int
|
||||
IPPROTO_RAW: int
|
||||
IPPROTO_TCP: int
|
||||
IPPROTO_UDP: int
|
||||
IPPROTO_AH: int
|
||||
IPPROTO_DSTOPTS: int
|
||||
IPPROTO_EGP: int
|
||||
IPPROTO_ESP: int
|
||||
IPPROTO_FRAGMENT: int
|
||||
IPPROTO_HOPOPTS: int
|
||||
IPPROTO_ICMPV6: int
|
||||
IPPROTO_IDP: int
|
||||
IPPROTO_IGMP: int
|
||||
IPPROTO_IPV6: int
|
||||
IPPROTO_NONE: int
|
||||
IPPROTO_PIM: int
|
||||
IPPROTO_PUP: int
|
||||
IPPROTO_ROUTING: int
|
||||
IPPROTO_SCTP: int
|
||||
if sys.platform != "linux":
|
||||
IPPROTO_GGP: int
|
||||
IPPROTO_IPV4: int
|
||||
IPPROTO_MAX: int
|
||||
IPPROTO_ND: int
|
||||
if sys.platform == "win32":
|
||||
IPPROTO_CBT: int
|
||||
IPPROTO_ICLFXBM: int
|
||||
IPPROTO_IGP: int
|
||||
IPPROTO_L2TP: int
|
||||
IPPROTO_PGM: int
|
||||
IPPROTO_RDP: int
|
||||
IPPROTO_ST: int
|
||||
if sys.platform != "win32":
|
||||
IPPROTO_GRE: int
|
||||
IPPROTO_IPIP: int
|
||||
IPPROTO_RSVP: int
|
||||
IPPROTO_TP: int
|
||||
if sys.platform != "win32" and sys.platform != "linux":
|
||||
IPPROTO_EON: int
|
||||
IPPROTO_HELLO: int
|
||||
IPPROTO_IPCOMP: int
|
||||
IPPROTO_XTP: int
|
||||
if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux":
|
||||
IPPROTO_BIP: int # Not FreeBSD either
|
||||
IPPROTO_MOBILE: int # Not FreeBSD either
|
||||
IPPROTO_VRRP: int # Not FreeBSD either
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 2.6.20, FreeBSD >= 10.1
|
||||
IPPROTO_UDPLITE: int
|
||||
if sys.version_info >= (3, 10) and sys.platform == "linux":
|
||||
IPPROTO_MPTCP: int
|
||||
|
||||
IPPORT_RESERVED: int
|
||||
IPPORT_USERRESERVED: int
|
||||
|
||||
INADDR_ALLHOSTS_GROUP: int
|
||||
INADDR_ANY: int
|
||||
INADDR_BROADCAST: int
|
||||
INADDR_LOOPBACK: int
|
||||
INADDR_MAX_LOCAL_GROUP: int
|
||||
INADDR_NONE: int
|
||||
INADDR_UNSPEC_GROUP: int
|
||||
|
||||
IP_ADD_MEMBERSHIP: int
|
||||
IP_DROP_MEMBERSHIP: int
|
||||
IP_HDRINCL: int
|
||||
IP_MULTICAST_IF: int
|
||||
IP_MULTICAST_LOOP: int
|
||||
IP_MULTICAST_TTL: int
|
||||
IP_OPTIONS: int
|
||||
if sys.platform != "linux":
|
||||
IP_RECVDSTADDR: int
|
||||
if sys.version_info >= (3, 10):
|
||||
IP_RECVTOS: int
|
||||
IP_TOS: int
|
||||
IP_TTL: int
|
||||
if sys.platform != "win32":
|
||||
IP_DEFAULT_MULTICAST_LOOP: int
|
||||
IP_DEFAULT_MULTICAST_TTL: int
|
||||
IP_MAX_MEMBERSHIPS: int
|
||||
IP_RECVOPTS: int
|
||||
IP_RECVRETOPTS: int
|
||||
IP_RETOPTS: int
|
||||
if sys.platform != "win32" and sys.platform != "darwin":
|
||||
IP_TRANSPARENT: int
|
||||
if sys.platform != "win32" and sys.platform != "darwin" and sys.version_info >= (3, 11):
|
||||
IP_BIND_ADDRESS_NO_PORT: int
|
||||
if sys.version_info >= (3, 12):
|
||||
IP_ADD_SOURCE_MEMBERSHIP: int
|
||||
IP_BLOCK_SOURCE: int
|
||||
IP_DROP_SOURCE_MEMBERSHIP: int
|
||||
IP_PKTINFO: int
|
||||
IP_UNBLOCK_SOURCE: int
|
||||
|
||||
IPV6_CHECKSUM: int
|
||||
IPV6_JOIN_GROUP: int
|
||||
IPV6_LEAVE_GROUP: int
|
||||
IPV6_MULTICAST_HOPS: int
|
||||
IPV6_MULTICAST_IF: int
|
||||
IPV6_MULTICAST_LOOP: int
|
||||
IPV6_RECVTCLASS: int
|
||||
IPV6_TCLASS: int
|
||||
IPV6_UNICAST_HOPS: int
|
||||
IPV6_V6ONLY: int
|
||||
IPV6_DONTFRAG: int
|
||||
IPV6_HOPLIMIT: int
|
||||
IPV6_HOPOPTS: int
|
||||
IPV6_PKTINFO: int
|
||||
IPV6_RECVRTHDR: int
|
||||
IPV6_RTHDR: int
|
||||
if sys.platform != "win32":
|
||||
IPV6_RTHDR_TYPE_0: int
|
||||
IPV6_DSTOPTS: int
|
||||
IPV6_NEXTHOP: int
|
||||
IPV6_PATHMTU: int
|
||||
IPV6_RECVDSTOPTS: int
|
||||
IPV6_RECVHOPLIMIT: int
|
||||
IPV6_RECVHOPOPTS: int
|
||||
IPV6_RECVPATHMTU: int
|
||||
IPV6_RECVPKTINFO: int
|
||||
IPV6_RTHDRDSTOPTS: int
|
||||
|
||||
if sys.platform != "win32" and sys.platform != "linux":
|
||||
IPV6_USE_MIN_MTU: int
|
||||
|
||||
EAI_AGAIN: int
|
||||
EAI_BADFLAGS: int
|
||||
EAI_FAIL: int
|
||||
EAI_FAMILY: int
|
||||
EAI_MEMORY: int
|
||||
EAI_NODATA: int
|
||||
EAI_NONAME: int
|
||||
EAI_SERVICE: int
|
||||
EAI_SOCKTYPE: int
|
||||
if sys.platform != "win32":
|
||||
EAI_ADDRFAMILY: int
|
||||
EAI_OVERFLOW: int
|
||||
EAI_SYSTEM: int
|
||||
if sys.platform != "win32" and sys.platform != "linux":
|
||||
EAI_BADHINTS: int
|
||||
EAI_MAX: int
|
||||
EAI_PROTOCOL: int
|
||||
|
||||
AI_ADDRCONFIG: int
|
||||
AI_ALL: int
|
||||
AI_CANONNAME: int
|
||||
AI_NUMERICHOST: int
|
||||
AI_NUMERICSERV: int
|
||||
AI_PASSIVE: int
|
||||
AI_V4MAPPED: int
|
||||
if sys.platform != "win32" and sys.platform != "linux":
|
||||
AI_DEFAULT: int
|
||||
AI_MASK: int
|
||||
AI_V4MAPPED_CFG: int
|
||||
|
||||
NI_DGRAM: int
|
||||
NI_MAXHOST: int
|
||||
NI_MAXSERV: int
|
||||
NI_NAMEREQD: int
|
||||
NI_NOFQDN: int
|
||||
NI_NUMERICHOST: int
|
||||
NI_NUMERICSERV: int
|
||||
if sys.platform == "linux" and sys.version_info >= (3, 13):
|
||||
NI_IDN: int
|
||||
|
||||
TCP_FASTOPEN: int
|
||||
TCP_KEEPCNT: int
|
||||
TCP_KEEPINTVL: int
|
||||
TCP_MAXSEG: int
|
||||
TCP_NODELAY: int
|
||||
if sys.platform != "win32":
|
||||
TCP_NOTSENT_LOWAT: int
|
||||
if sys.platform != "darwin":
|
||||
TCP_KEEPIDLE: int
|
||||
if sys.version_info >= (3, 10) and sys.platform == "darwin":
|
||||
TCP_KEEPALIVE: int
|
||||
if sys.version_info >= (3, 11) and sys.platform == "darwin":
|
||||
TCP_CONNECTION_INFO: int
|
||||
|
||||
if sys.platform != "win32" and sys.platform != "darwin":
|
||||
TCP_CONGESTION: int
|
||||
TCP_CORK: int
|
||||
TCP_DEFER_ACCEPT: int
|
||||
TCP_INFO: int
|
||||
TCP_LINGER2: int
|
||||
TCP_QUICKACK: int
|
||||
TCP_SYNCNT: int
|
||||
TCP_USER_TIMEOUT: int
|
||||
TCP_WINDOW_CLAMP: int
|
||||
if sys.platform == "linux" and sys.version_info >= (3, 12):
|
||||
TCP_CC_INFO: int
|
||||
TCP_FASTOPEN_CONNECT: int
|
||||
TCP_FASTOPEN_KEY: int
|
||||
TCP_FASTOPEN_NO_COOKIE: int
|
||||
TCP_INQ: int
|
||||
TCP_MD5SIG: int
|
||||
TCP_MD5SIG_EXT: int
|
||||
TCP_QUEUE_SEQ: int
|
||||
TCP_REPAIR: int
|
||||
TCP_REPAIR_OPTIONS: int
|
||||
TCP_REPAIR_QUEUE: int
|
||||
TCP_REPAIR_WINDOW: int
|
||||
TCP_SAVED_SYN: int
|
||||
TCP_SAVE_SYN: int
|
||||
TCP_THIN_DUPACK: int
|
||||
TCP_THIN_LINEAR_TIMEOUTS: int
|
||||
TCP_TIMESTAMP: int
|
||||
TCP_TX_DELAY: int
|
||||
TCP_ULP: int
|
||||
TCP_ZEROCOPY_RECEIVE: int
|
||||
|
||||
# --------------------
|
||||
# Specifically documented constants
|
||||
# --------------------
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 2.6.25, NetBSD >= 8
|
||||
AF_CAN: int
|
||||
PF_CAN: int
|
||||
SOL_CAN_BASE: int
|
||||
SOL_CAN_RAW: int
|
||||
CAN_EFF_FLAG: int
|
||||
CAN_EFF_MASK: int
|
||||
CAN_ERR_FLAG: int
|
||||
CAN_ERR_MASK: int
|
||||
CAN_RAW: int
|
||||
CAN_RAW_FILTER: int
|
||||
CAN_RAW_LOOPBACK: int
|
||||
CAN_RAW_RECV_OWN_MSGS: int
|
||||
CAN_RTR_FLAG: int
|
||||
CAN_SFF_MASK: int
|
||||
if sys.version_info < (3, 11):
|
||||
CAN_RAW_ERR_FILTER: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 2.6.25
|
||||
CAN_BCM: int
|
||||
CAN_BCM_TX_SETUP: int
|
||||
CAN_BCM_TX_DELETE: int
|
||||
CAN_BCM_TX_READ: int
|
||||
CAN_BCM_TX_SEND: int
|
||||
CAN_BCM_RX_SETUP: int
|
||||
CAN_BCM_RX_DELETE: int
|
||||
CAN_BCM_RX_READ: int
|
||||
CAN_BCM_TX_STATUS: int
|
||||
CAN_BCM_TX_EXPIRED: int
|
||||
CAN_BCM_RX_STATUS: int
|
||||
CAN_BCM_RX_TIMEOUT: int
|
||||
CAN_BCM_RX_CHANGED: int
|
||||
CAN_BCM_SETTIMER: int
|
||||
CAN_BCM_STARTTIMER: int
|
||||
CAN_BCM_TX_COUNTEVT: int
|
||||
CAN_BCM_TX_ANNOUNCE: int
|
||||
CAN_BCM_TX_CP_CAN_ID: int
|
||||
CAN_BCM_RX_FILTER_ID: int
|
||||
CAN_BCM_RX_CHECK_DLC: int
|
||||
CAN_BCM_RX_NO_AUTOTIMER: int
|
||||
CAN_BCM_RX_ANNOUNCE_RESUME: int
|
||||
CAN_BCM_TX_RESET_MULTI_IDX: int
|
||||
CAN_BCM_RX_RTR_FRAME: int
|
||||
CAN_BCM_CAN_FD_FRAME: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 3.6
|
||||
CAN_RAW_FD_FRAMES: int
|
||||
# Availability: Linux >= 4.1
|
||||
CAN_RAW_JOIN_FILTERS: int
|
||||
# Availability: Linux >= 2.6.25
|
||||
CAN_ISOTP: int
|
||||
# Availability: Linux >= 5.4
|
||||
CAN_J1939: int
|
||||
|
||||
J1939_MAX_UNICAST_ADDR: int
|
||||
J1939_IDLE_ADDR: int
|
||||
J1939_NO_ADDR: int
|
||||
J1939_NO_NAME: int
|
||||
J1939_PGN_REQUEST: int
|
||||
J1939_PGN_ADDRESS_CLAIMED: int
|
||||
J1939_PGN_ADDRESS_COMMANDED: int
|
||||
J1939_PGN_PDU1_MAX: int
|
||||
J1939_PGN_MAX: int
|
||||
J1939_NO_PGN: int
|
||||
|
||||
SO_J1939_FILTER: int
|
||||
SO_J1939_PROMISC: int
|
||||
SO_J1939_SEND_PRIO: int
|
||||
SO_J1939_ERRQUEUE: int
|
||||
|
||||
SCM_J1939_DEST_ADDR: int
|
||||
SCM_J1939_DEST_NAME: int
|
||||
SCM_J1939_PRIO: int
|
||||
SCM_J1939_ERRQUEUE: int
|
||||
|
||||
J1939_NLA_PAD: int
|
||||
J1939_NLA_BYTES_ACKED: int
|
||||
J1939_EE_INFO_NONE: int
|
||||
J1939_EE_INFO_TX_ABORT: int
|
||||
J1939_FILTER_MAX: int
|
||||
|
||||
if sys.version_info >= (3, 12) and sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin":
|
||||
# Availability: FreeBSD >= 14.0
|
||||
AF_DIVERT: int
|
||||
PF_DIVERT: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 2.2
|
||||
AF_PACKET: int
|
||||
PF_PACKET: int
|
||||
PACKET_BROADCAST: int
|
||||
PACKET_FASTROUTE: int
|
||||
PACKET_HOST: int
|
||||
PACKET_LOOPBACK: int
|
||||
PACKET_MULTICAST: int
|
||||
PACKET_OTHERHOST: int
|
||||
PACKET_OUTGOING: int
|
||||
|
||||
if sys.version_info >= (3, 12) and sys.platform == "linux":
|
||||
ETH_P_ALL: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 2.6.30
|
||||
AF_RDS: int
|
||||
PF_RDS: int
|
||||
SOL_RDS: int
|
||||
# These are present in include/linux/rds.h but don't always show up
|
||||
# here.
|
||||
RDS_CANCEL_SENT_TO: int
|
||||
RDS_CMSG_RDMA_ARGS: int
|
||||
RDS_CMSG_RDMA_DEST: int
|
||||
RDS_CMSG_RDMA_MAP: int
|
||||
RDS_CMSG_RDMA_STATUS: int
|
||||
RDS_CONG_MONITOR: int
|
||||
RDS_FREE_MR: int
|
||||
RDS_GET_MR: int
|
||||
RDS_GET_MR_FOR_DEST: int
|
||||
RDS_RDMA_DONTWAIT: int
|
||||
RDS_RDMA_FENCE: int
|
||||
RDS_RDMA_INVALIDATE: int
|
||||
RDS_RDMA_NOTIFY_ME: int
|
||||
RDS_RDMA_READWRITE: int
|
||||
RDS_RDMA_SILENT: int
|
||||
RDS_RDMA_USE_ONCE: int
|
||||
RDS_RECVERR: int
|
||||
|
||||
# This is supported by CPython but doesn't seem to be a real thing.
|
||||
# The closest existing constant in rds.h is RDS_CMSG_CONG_UPDATE
|
||||
# RDS_CMSG_RDMA_UPDATE: int
|
||||
|
||||
if sys.platform == "win32":
|
||||
SIO_RCVALL: int
|
||||
SIO_KEEPALIVE_VALS: int
|
||||
SIO_LOOPBACK_FAST_PATH: int
|
||||
RCVALL_MAX: int
|
||||
RCVALL_OFF: int
|
||||
RCVALL_ON: int
|
||||
RCVALL_SOCKETLEVELONLY: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
AF_TIPC: int
|
||||
SOL_TIPC: int
|
||||
TIPC_ADDR_ID: int
|
||||
TIPC_ADDR_NAME: int
|
||||
TIPC_ADDR_NAMESEQ: int
|
||||
TIPC_CFG_SRV: int
|
||||
TIPC_CLUSTER_SCOPE: int
|
||||
TIPC_CONN_TIMEOUT: int
|
||||
TIPC_CRITICAL_IMPORTANCE: int
|
||||
TIPC_DEST_DROPPABLE: int
|
||||
TIPC_HIGH_IMPORTANCE: int
|
||||
TIPC_IMPORTANCE: int
|
||||
TIPC_LOW_IMPORTANCE: int
|
||||
TIPC_MEDIUM_IMPORTANCE: int
|
||||
TIPC_NODE_SCOPE: int
|
||||
TIPC_PUBLISHED: int
|
||||
TIPC_SRC_DROPPABLE: int
|
||||
TIPC_SUBSCR_TIMEOUT: int
|
||||
TIPC_SUB_CANCEL: int
|
||||
TIPC_SUB_PORTS: int
|
||||
TIPC_SUB_SERVICE: int
|
||||
TIPC_TOP_SRV: int
|
||||
TIPC_WAIT_FOREVER: int
|
||||
TIPC_WITHDRAWN: int
|
||||
TIPC_ZONE_SCOPE: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 2.6.38
|
||||
AF_ALG: int
|
||||
SOL_ALG: int
|
||||
ALG_OP_DECRYPT: int
|
||||
ALG_OP_ENCRYPT: int
|
||||
ALG_OP_SIGN: int
|
||||
ALG_OP_VERIFY: int
|
||||
ALG_SET_AEAD_ASSOCLEN: int
|
||||
ALG_SET_AEAD_AUTHSIZE: int
|
||||
ALG_SET_IV: int
|
||||
ALG_SET_KEY: int
|
||||
ALG_SET_OP: int
|
||||
ALG_SET_PUBKEY: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Availability: Linux >= 4.8 (or maybe 3.9, CPython docs are confusing)
|
||||
AF_VSOCK: int
|
||||
IOCTL_VM_SOCKETS_GET_LOCAL_CID: int
|
||||
VMADDR_CID_ANY: int
|
||||
VMADDR_CID_HOST: int
|
||||
VMADDR_PORT_ANY: int
|
||||
SO_VM_SOCKETS_BUFFER_MAX_SIZE: int
|
||||
SO_VM_SOCKETS_BUFFER_SIZE: int
|
||||
SO_VM_SOCKETS_BUFFER_MIN_SIZE: int
|
||||
VM_SOCKETS_INVALID_VERSION: int # undocumented
|
||||
|
||||
# Documented as only available on BSD, macOS, but empirically sometimes
|
||||
# available on Windows
|
||||
if sys.platform != "linux":
|
||||
AF_LINK: int
|
||||
|
||||
has_ipv6: bool
|
||||
|
||||
if sys.platform != "darwin" and sys.platform != "linux":
|
||||
BDADDR_ANY: str
|
||||
BDADDR_LOCAL: str
|
||||
|
||||
if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux":
|
||||
HCI_FILTER: int # not in NetBSD or DragonFlyBSD
|
||||
HCI_TIME_STAMP: int # not in FreeBSD, NetBSD, or DragonFlyBSD
|
||||
HCI_DATA_DIR: int # not in FreeBSD, NetBSD, or DragonFlyBSD
|
||||
|
||||
if sys.platform == "linux":
|
||||
AF_QIPCRTR: int # Availability: Linux >= 4.7
|
||||
|
||||
if sys.version_info >= (3, 11) and sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin":
|
||||
# FreeBSD
|
||||
SCM_CREDS2: int
|
||||
LOCAL_CREDS: int
|
||||
LOCAL_CREDS_PERSISTENT: int
|
||||
|
||||
if sys.version_info >= (3, 11) and sys.platform == "linux":
|
||||
SO_INCOMING_CPU: int # Availability: Linux >= 3.9
|
||||
|
||||
if sys.version_info >= (3, 12) and sys.platform == "win32":
|
||||
# Availability: Windows
|
||||
AF_HYPERV: int
|
||||
HV_PROTOCOL_RAW: int
|
||||
HVSOCKET_CONNECT_TIMEOUT: int
|
||||
HVSOCKET_CONNECT_TIMEOUT_MAX: int
|
||||
HVSOCKET_CONNECTED_SUSPEND: int
|
||||
HVSOCKET_ADDRESS_FLAG_PASSTHRU: int
|
||||
HV_GUID_ZERO: str
|
||||
HV_GUID_WILDCARD: str
|
||||
HV_GUID_BROADCAST: str
|
||||
HV_GUID_CHILDREN: str
|
||||
HV_GUID_LOOPBACK: str
|
||||
HV_GUID_PARENT: str
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
if sys.platform != "win32":
|
||||
# Availability: Linux, FreeBSD, macOS
|
||||
ETHERTYPE_ARP: int
|
||||
ETHERTYPE_IP: int
|
||||
ETHERTYPE_IPV6: int
|
||||
ETHERTYPE_VLAN: int
|
||||
|
||||
# --------------------
|
||||
# Semi-documented constants
|
||||
# These are alluded to under the "Socket families" section in the docs
|
||||
# https://docs.python.org/3/library/socket.html#socket-families
|
||||
# --------------------
|
||||
|
||||
if sys.platform == "linux":
|
||||
# Netlink is defined by Linux
|
||||
AF_NETLINK: int
|
||||
NETLINK_CRYPTO: int
|
||||
NETLINK_DNRTMSG: int
|
||||
NETLINK_FIREWALL: int
|
||||
NETLINK_IP6_FW: int
|
||||
NETLINK_NFLOG: int
|
||||
NETLINK_ROUTE: int
|
||||
NETLINK_USERSOCK: int
|
||||
NETLINK_XFRM: int
|
||||
# Technically still supported by CPython
|
||||
# NETLINK_ARPD: int # linux 2.0 to 2.6.12 (EOL August 2005)
|
||||
# NETLINK_ROUTE6: int # linux 2.2 to 2.6.12 (EOL August 2005)
|
||||
# NETLINK_SKIP: int # linux 2.0 to 2.6.12 (EOL August 2005)
|
||||
# NETLINK_TAPBASE: int # linux 2.2 to 2.6.12 (EOL August 2005)
|
||||
# NETLINK_TCPDIAG: int # linux 2.6.0 to 2.6.13 (EOL December 2005)
|
||||
# NETLINK_W1: int # linux 2.6.13 to 2.6.17 (EOL October 2006)
|
||||
|
||||
if sys.platform == "darwin":
|
||||
PF_SYSTEM: int
|
||||
SYSPROTO_CONTROL: int
|
||||
|
||||
if sys.platform != "darwin" and sys.platform != "linux":
|
||||
AF_BLUETOOTH: int
|
||||
|
||||
if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux":
|
||||
# Linux and some BSD support is explicit in the docs
|
||||
# Windows and macOS do not support in practice
|
||||
BTPROTO_HCI: int
|
||||
BTPROTO_L2CAP: int
|
||||
BTPROTO_SCO: int # not in FreeBSD
|
||||
if sys.platform != "darwin" and sys.platform != "linux":
|
||||
BTPROTO_RFCOMM: int
|
||||
|
||||
if sys.platform == "linux":
|
||||
UDPLITE_RECV_CSCOV: int
|
||||
UDPLITE_SEND_CSCOV: int
|
||||
|
||||
# --------------------
|
||||
# Documented under socket.shutdown
|
||||
# --------------------
|
||||
SHUT_RD: int
|
||||
SHUT_RDWR: int
|
||||
SHUT_WR: int
|
||||
|
||||
# --------------------
|
||||
# Undocumented constants
|
||||
# --------------------
|
||||
|
||||
# Undocumented address families
|
||||
AF_APPLETALK: int
|
||||
AF_DECnet: int
|
||||
AF_IPX: int
|
||||
AF_SNA: int
|
||||
|
||||
if sys.platform != "win32":
|
||||
AF_ROUTE: int
|
||||
|
||||
if sys.platform == "darwin":
|
||||
AF_SYSTEM: int
|
||||
|
||||
if sys.platform != "darwin":
|
||||
AF_IRDA: int
|
||||
|
||||
if sys.platform != "win32" and sys.platform != "darwin":
|
||||
AF_ASH: int
|
||||
AF_ATMPVC: int
|
||||
AF_ATMSVC: int
|
||||
AF_AX25: int
|
||||
AF_BRIDGE: int
|
||||
AF_ECONET: int
|
||||
AF_KEY: int
|
||||
AF_LLC: int
|
||||
AF_NETBEUI: int
|
||||
AF_NETROM: int
|
||||
AF_PPPOX: int
|
||||
AF_ROSE: int
|
||||
AF_SECURITY: int
|
||||
AF_WANPIPE: int
|
||||
AF_X25: int
|
||||
|
||||
# Miscellaneous undocumented
|
||||
|
||||
if sys.platform != "win32" and sys.platform != "linux":
|
||||
LOCAL_PEERCRED: int
|
||||
|
||||
if sys.platform != "win32" and sys.platform != "darwin":
|
||||
# Defined in linux socket.h, but this isn't always present for
|
||||
# some reason.
|
||||
IPX_TYPE: int
|
||||
|
||||
# ===== Classes =====
|
||||
|
||||
class socket:
|
||||
@property
|
||||
def family(self) -> int: ...
|
||||
@property
|
||||
def type(self) -> int: ...
|
||||
@property
|
||||
def proto(self) -> int: ...
|
||||
# F811: "Redefinition of unused `timeout`"
|
||||
@property
|
||||
def timeout(self) -> float | None: ... # noqa: F811
|
||||
if sys.platform == "win32":
|
||||
def __init__(
|
||||
self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | bytes | None = ...
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | None = ...) -> None: ...
|
||||
|
||||
def bind(self, address: _Address, /) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def connect(self, address: _Address, /) -> None: ...
|
||||
def connect_ex(self, address: _Address, /) -> int: ...
|
||||
def detach(self) -> int: ...
|
||||
def fileno(self) -> int: ...
|
||||
def getpeername(self) -> _RetAddress: ...
|
||||
def getsockname(self) -> _RetAddress: ...
|
||||
@overload
|
||||
def getsockopt(self, level: int, optname: int, /) -> int: ...
|
||||
@overload
|
||||
def getsockopt(self, level: int, optname: int, buflen: int, /) -> bytes: ...
|
||||
def getblocking(self) -> bool: ...
|
||||
def gettimeout(self) -> float | None: ...
|
||||
if sys.platform == "win32":
|
||||
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool, /) -> None: ...
|
||||
|
||||
def listen(self, backlog: int = ..., /) -> None: ...
|
||||
def recv(self, bufsize: int, flags: int = ..., /) -> bytes: ...
|
||||
def recvfrom(self, bufsize: int, flags: int = ..., /) -> tuple[bytes, _RetAddress]: ...
|
||||
if sys.platform != "win32":
|
||||
def recvmsg(self, bufsize: int, ancbufsize: int = ..., flags: int = ..., /) -> tuple[bytes, list[_CMSG], int, Any]: ...
|
||||
def recvmsg_into(
|
||||
self, buffers: Iterable[WriteableBuffer], ancbufsize: int = ..., flags: int = ..., /
|
||||
) -> tuple[int, list[_CMSG], int, Any]: ...
|
||||
|
||||
def recvfrom_into(self, buffer: WriteableBuffer, nbytes: int = ..., flags: int = ...) -> tuple[int, _RetAddress]: ...
|
||||
def recv_into(self, buffer: WriteableBuffer, nbytes: int = ..., flags: int = ...) -> int: ...
|
||||
def send(self, data: ReadableBuffer, flags: int = ..., /) -> int: ...
|
||||
def sendall(self, data: ReadableBuffer, flags: int = ..., /) -> None: ...
|
||||
@overload
|
||||
def sendto(self, data: ReadableBuffer, address: _Address, /) -> int: ...
|
||||
@overload
|
||||
def sendto(self, data: ReadableBuffer, flags: int, address: _Address, /) -> int: ...
|
||||
if sys.platform != "win32":
|
||||
def sendmsg(
|
||||
self,
|
||||
buffers: Iterable[ReadableBuffer],
|
||||
ancdata: Iterable[_CMSGArg] = ...,
|
||||
flags: int = ...,
|
||||
address: _Address | None = ...,
|
||||
/,
|
||||
) -> int: ...
|
||||
if sys.platform == "linux":
|
||||
def sendmsg_afalg(
|
||||
self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ...
|
||||
) -> int: ...
|
||||
|
||||
def setblocking(self, flag: bool, /) -> None: ...
|
||||
def settimeout(self, value: float | None, /) -> None: ...
|
||||
@overload
|
||||
def setsockopt(self, level: int, optname: int, value: int | ReadableBuffer, /) -> None: ...
|
||||
@overload
|
||||
def setsockopt(self, level: int, optname: int, value: None, optlen: int, /) -> None: ...
|
||||
if sys.platform == "win32":
|
||||
def share(self, process_id: int, /) -> bytes: ...
|
||||
|
||||
def shutdown(self, how: int, /) -> None: ...
|
||||
|
||||
SocketType = socket
|
||||
|
||||
# ===== Functions =====
|
||||
|
||||
def close(fd: SupportsIndex, /) -> None: ...
|
||||
def dup(fd: SupportsIndex, /) -> int: ...
|
||||
|
||||
# the 5th tuple item is an address
|
||||
def getaddrinfo(
|
||||
host: bytes | str | None,
|
||||
port: bytes | str | int | None,
|
||||
family: int = ...,
|
||||
type: int = ...,
|
||||
proto: int = ...,
|
||||
flags: int = ...,
|
||||
) -> list[tuple[int, int, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]: ...
|
||||
def gethostbyname(hostname: str, /) -> str: ...
|
||||
def gethostbyname_ex(hostname: str, /) -> tuple[str, list[str], list[str]]: ...
|
||||
def gethostname() -> str: ...
|
||||
def gethostbyaddr(ip_address: str, /) -> tuple[str, list[str], list[str]]: ...
|
||||
def getnameinfo(sockaddr: tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes], flags: int, /) -> tuple[str, str]: ...
|
||||
def getprotobyname(protocolname: str, /) -> int: ...
|
||||
def getservbyname(servicename: str, protocolname: str = ..., /) -> int: ...
|
||||
def getservbyport(port: int, protocolname: str = ..., /) -> str: ...
|
||||
def ntohl(x: int, /) -> int: ... # param & ret val are 32-bit ints
|
||||
def ntohs(x: int, /) -> int: ... # param & ret val are 16-bit ints
|
||||
def htonl(x: int, /) -> int: ... # param & ret val are 32-bit ints
|
||||
def htons(x: int, /) -> int: ... # param & ret val are 16-bit ints
|
||||
def inet_aton(ip_addr: str, /) -> bytes: ... # ret val 4 bytes in length
|
||||
def inet_ntoa(packed_ip: ReadableBuffer, /) -> str: ...
|
||||
def inet_pton(address_family: int, ip_string: str, /) -> bytes: ...
|
||||
def inet_ntop(address_family: int, packed_ip: ReadableBuffer, /) -> str: ...
|
||||
def getdefaulttimeout() -> float | None: ...
|
||||
|
||||
# F811: "Redefinition of unused `timeout`"
|
||||
def setdefaulttimeout(timeout: float | None, /) -> None: ... # noqa: F811
|
||||
|
||||
if sys.platform != "win32":
|
||||
def sethostname(name: str, /) -> None: ...
|
||||
def CMSG_LEN(length: int, /) -> int: ...
|
||||
def CMSG_SPACE(length: int, /) -> int: ...
|
||||
def socketpair(family: int = ..., type: int = ..., proto: int = ..., /) -> tuple[socket, socket]: ...
|
||||
|
||||
def if_nameindex() -> list[tuple[int, str]]: ...
|
||||
def if_nametoindex(oname: str, /) -> int: ...
|
||||
def if_indextoname(index: int, /) -> str: ...
|
||||
|
||||
CAPI: CapsuleType
|
||||
312
crates/red_knot_vendored/vendor/typeshed/stdlib/_sqlite3.pyi
vendored
Normal file
312
crates/red_knot_vendored/vendor/typeshed/stdlib/_sqlite3.pyi
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer, StrOrBytesPath
|
||||
from collections.abc import Callable
|
||||
from sqlite3 import (
|
||||
Connection as Connection,
|
||||
Cursor as Cursor,
|
||||
DatabaseError as DatabaseError,
|
||||
DataError as DataError,
|
||||
Error as Error,
|
||||
IntegrityError as IntegrityError,
|
||||
InterfaceError as InterfaceError,
|
||||
InternalError as InternalError,
|
||||
NotSupportedError as NotSupportedError,
|
||||
OperationalError as OperationalError,
|
||||
PrepareProtocol as PrepareProtocol,
|
||||
ProgrammingError as ProgrammingError,
|
||||
Row as Row,
|
||||
Warning as Warning,
|
||||
)
|
||||
from typing import Any, Final, Literal, TypeVar, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from sqlite3 import Blob as Blob
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_ConnectionT = TypeVar("_ConnectionT", bound=Connection)
|
||||
_SqliteData: TypeAlias = str | ReadableBuffer | int | float | None
|
||||
_Adapter: TypeAlias = Callable[[_T], _SqliteData]
|
||||
_Converter: TypeAlias = Callable[[bytes], Any]
|
||||
|
||||
PARSE_COLNAMES: Final[int]
|
||||
PARSE_DECLTYPES: Final[int]
|
||||
SQLITE_ALTER_TABLE: Final[int]
|
||||
SQLITE_ANALYZE: Final[int]
|
||||
SQLITE_ATTACH: Final[int]
|
||||
SQLITE_CREATE_INDEX: Final[int]
|
||||
SQLITE_CREATE_TABLE: Final[int]
|
||||
SQLITE_CREATE_TEMP_INDEX: Final[int]
|
||||
SQLITE_CREATE_TEMP_TABLE: Final[int]
|
||||
SQLITE_CREATE_TEMP_TRIGGER: Final[int]
|
||||
SQLITE_CREATE_TEMP_VIEW: Final[int]
|
||||
SQLITE_CREATE_TRIGGER: Final[int]
|
||||
SQLITE_CREATE_VIEW: Final[int]
|
||||
SQLITE_CREATE_VTABLE: Final[int]
|
||||
SQLITE_DELETE: Final[int]
|
||||
SQLITE_DENY: Final[int]
|
||||
SQLITE_DETACH: Final[int]
|
||||
SQLITE_DONE: Final[int]
|
||||
SQLITE_DROP_INDEX: Final[int]
|
||||
SQLITE_DROP_TABLE: Final[int]
|
||||
SQLITE_DROP_TEMP_INDEX: Final[int]
|
||||
SQLITE_DROP_TEMP_TABLE: Final[int]
|
||||
SQLITE_DROP_TEMP_TRIGGER: Final[int]
|
||||
SQLITE_DROP_TEMP_VIEW: Final[int]
|
||||
SQLITE_DROP_TRIGGER: Final[int]
|
||||
SQLITE_DROP_VIEW: Final[int]
|
||||
SQLITE_DROP_VTABLE: Final[int]
|
||||
SQLITE_FUNCTION: Final[int]
|
||||
SQLITE_IGNORE: Final[int]
|
||||
SQLITE_INSERT: Final[int]
|
||||
SQLITE_OK: Final[int]
|
||||
SQLITE_PRAGMA: Final[int]
|
||||
SQLITE_READ: Final[int]
|
||||
SQLITE_RECURSIVE: Final[int]
|
||||
SQLITE_REINDEX: Final[int]
|
||||
SQLITE_SAVEPOINT: Final[int]
|
||||
SQLITE_SELECT: Final[int]
|
||||
SQLITE_TRANSACTION: Final[int]
|
||||
SQLITE_UPDATE: Final[int]
|
||||
adapters: dict[tuple[type[Any], type[Any]], _Adapter[Any]]
|
||||
converters: dict[str, _Converter]
|
||||
sqlite_version: str
|
||||
|
||||
if sys.version_info < (3, 12):
|
||||
version: str
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
LEGACY_TRANSACTION_CONTROL: Final[int]
|
||||
SQLITE_DBCONFIG_DEFENSIVE: Final[int]
|
||||
SQLITE_DBCONFIG_DQS_DDL: Final[int]
|
||||
SQLITE_DBCONFIG_DQS_DML: Final[int]
|
||||
SQLITE_DBCONFIG_ENABLE_FKEY: Final[int]
|
||||
SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: Final[int]
|
||||
SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: Final[int]
|
||||
SQLITE_DBCONFIG_ENABLE_QPSG: Final[int]
|
||||
SQLITE_DBCONFIG_ENABLE_TRIGGER: Final[int]
|
||||
SQLITE_DBCONFIG_ENABLE_VIEW: Final[int]
|
||||
SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: Final[int]
|
||||
SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: Final[int]
|
||||
SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: Final[int]
|
||||
SQLITE_DBCONFIG_RESET_DATABASE: Final[int]
|
||||
SQLITE_DBCONFIG_TRIGGER_EQP: Final[int]
|
||||
SQLITE_DBCONFIG_TRUSTED_SCHEMA: Final[int]
|
||||
SQLITE_DBCONFIG_WRITABLE_SCHEMA: Final[int]
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
SQLITE_ABORT: Final[int]
|
||||
SQLITE_ABORT_ROLLBACK: Final[int]
|
||||
SQLITE_AUTH: Final[int]
|
||||
SQLITE_AUTH_USER: Final[int]
|
||||
SQLITE_BUSY: Final[int]
|
||||
SQLITE_BUSY_RECOVERY: Final[int]
|
||||
SQLITE_BUSY_SNAPSHOT: Final[int]
|
||||
SQLITE_BUSY_TIMEOUT: Final[int]
|
||||
SQLITE_CANTOPEN: Final[int]
|
||||
SQLITE_CANTOPEN_CONVPATH: Final[int]
|
||||
SQLITE_CANTOPEN_DIRTYWAL: Final[int]
|
||||
SQLITE_CANTOPEN_FULLPATH: Final[int]
|
||||
SQLITE_CANTOPEN_ISDIR: Final[int]
|
||||
SQLITE_CANTOPEN_NOTEMPDIR: Final[int]
|
||||
SQLITE_CANTOPEN_SYMLINK: Final[int]
|
||||
SQLITE_CONSTRAINT: Final[int]
|
||||
SQLITE_CONSTRAINT_CHECK: Final[int]
|
||||
SQLITE_CONSTRAINT_COMMITHOOK: Final[int]
|
||||
SQLITE_CONSTRAINT_FOREIGNKEY: Final[int]
|
||||
SQLITE_CONSTRAINT_FUNCTION: Final[int]
|
||||
SQLITE_CONSTRAINT_NOTNULL: Final[int]
|
||||
SQLITE_CONSTRAINT_PINNED: Final[int]
|
||||
SQLITE_CONSTRAINT_PRIMARYKEY: Final[int]
|
||||
SQLITE_CONSTRAINT_ROWID: Final[int]
|
||||
SQLITE_CONSTRAINT_TRIGGER: Final[int]
|
||||
SQLITE_CONSTRAINT_UNIQUE: Final[int]
|
||||
SQLITE_CONSTRAINT_VTAB: Final[int]
|
||||
SQLITE_CORRUPT: Final[int]
|
||||
SQLITE_CORRUPT_INDEX: Final[int]
|
||||
SQLITE_CORRUPT_SEQUENCE: Final[int]
|
||||
SQLITE_CORRUPT_VTAB: Final[int]
|
||||
SQLITE_EMPTY: Final[int]
|
||||
SQLITE_ERROR: Final[int]
|
||||
SQLITE_ERROR_MISSING_COLLSEQ: Final[int]
|
||||
SQLITE_ERROR_RETRY: Final[int]
|
||||
SQLITE_ERROR_SNAPSHOT: Final[int]
|
||||
SQLITE_FORMAT: Final[int]
|
||||
SQLITE_FULL: Final[int]
|
||||
SQLITE_INTERNAL: Final[int]
|
||||
SQLITE_INTERRUPT: Final[int]
|
||||
SQLITE_IOERR: Final[int]
|
||||
SQLITE_IOERR_ACCESS: Final[int]
|
||||
SQLITE_IOERR_AUTH: Final[int]
|
||||
SQLITE_IOERR_BEGIN_ATOMIC: Final[int]
|
||||
SQLITE_IOERR_BLOCKED: Final[int]
|
||||
SQLITE_IOERR_CHECKRESERVEDLOCK: Final[int]
|
||||
SQLITE_IOERR_CLOSE: Final[int]
|
||||
SQLITE_IOERR_COMMIT_ATOMIC: Final[int]
|
||||
SQLITE_IOERR_CONVPATH: Final[int]
|
||||
SQLITE_IOERR_CORRUPTFS: Final[int]
|
||||
SQLITE_IOERR_DATA: Final[int]
|
||||
SQLITE_IOERR_DELETE: Final[int]
|
||||
SQLITE_IOERR_DELETE_NOENT: Final[int]
|
||||
SQLITE_IOERR_DIR_CLOSE: Final[int]
|
||||
SQLITE_IOERR_DIR_FSYNC: Final[int]
|
||||
SQLITE_IOERR_FSTAT: Final[int]
|
||||
SQLITE_IOERR_FSYNC: Final[int]
|
||||
SQLITE_IOERR_GETTEMPPATH: Final[int]
|
||||
SQLITE_IOERR_LOCK: Final[int]
|
||||
SQLITE_IOERR_MMAP: Final[int]
|
||||
SQLITE_IOERR_NOMEM: Final[int]
|
||||
SQLITE_IOERR_RDLOCK: Final[int]
|
||||
SQLITE_IOERR_READ: Final[int]
|
||||
SQLITE_IOERR_ROLLBACK_ATOMIC: Final[int]
|
||||
SQLITE_IOERR_SEEK: Final[int]
|
||||
SQLITE_IOERR_SHMLOCK: Final[int]
|
||||
SQLITE_IOERR_SHMMAP: Final[int]
|
||||
SQLITE_IOERR_SHMOPEN: Final[int]
|
||||
SQLITE_IOERR_SHMSIZE: Final[int]
|
||||
SQLITE_IOERR_SHORT_READ: Final[int]
|
||||
SQLITE_IOERR_TRUNCATE: Final[int]
|
||||
SQLITE_IOERR_UNLOCK: Final[int]
|
||||
SQLITE_IOERR_VNODE: Final[int]
|
||||
SQLITE_IOERR_WRITE: Final[int]
|
||||
SQLITE_LIMIT_ATTACHED: Final[int]
|
||||
SQLITE_LIMIT_COLUMN: Final[int]
|
||||
SQLITE_LIMIT_COMPOUND_SELECT: Final[int]
|
||||
SQLITE_LIMIT_EXPR_DEPTH: Final[int]
|
||||
SQLITE_LIMIT_FUNCTION_ARG: Final[int]
|
||||
SQLITE_LIMIT_LENGTH: Final[int]
|
||||
SQLITE_LIMIT_LIKE_PATTERN_LENGTH: Final[int]
|
||||
SQLITE_LIMIT_SQL_LENGTH: Final[int]
|
||||
SQLITE_LIMIT_TRIGGER_DEPTH: Final[int]
|
||||
SQLITE_LIMIT_VARIABLE_NUMBER: Final[int]
|
||||
SQLITE_LIMIT_VDBE_OP: Final[int]
|
||||
SQLITE_LIMIT_WORKER_THREADS: Final[int]
|
||||
SQLITE_LOCKED: Final[int]
|
||||
SQLITE_LOCKED_SHAREDCACHE: Final[int]
|
||||
SQLITE_LOCKED_VTAB: Final[int]
|
||||
SQLITE_MISMATCH: Final[int]
|
||||
SQLITE_MISUSE: Final[int]
|
||||
SQLITE_NOLFS: Final[int]
|
||||
SQLITE_NOMEM: Final[int]
|
||||
SQLITE_NOTADB: Final[int]
|
||||
SQLITE_NOTFOUND: Final[int]
|
||||
SQLITE_NOTICE: Final[int]
|
||||
SQLITE_NOTICE_RECOVER_ROLLBACK: Final[int]
|
||||
SQLITE_NOTICE_RECOVER_WAL: Final[int]
|
||||
SQLITE_OK_LOAD_PERMANENTLY: Final[int]
|
||||
SQLITE_OK_SYMLINK: Final[int]
|
||||
SQLITE_PERM: Final[int]
|
||||
SQLITE_PROTOCOL: Final[int]
|
||||
SQLITE_RANGE: Final[int]
|
||||
SQLITE_READONLY: Final[int]
|
||||
SQLITE_READONLY_CANTINIT: Final[int]
|
||||
SQLITE_READONLY_CANTLOCK: Final[int]
|
||||
SQLITE_READONLY_DBMOVED: Final[int]
|
||||
SQLITE_READONLY_DIRECTORY: Final[int]
|
||||
SQLITE_READONLY_RECOVERY: Final[int]
|
||||
SQLITE_READONLY_ROLLBACK: Final[int]
|
||||
SQLITE_ROW: Final[int]
|
||||
SQLITE_SCHEMA: Final[int]
|
||||
SQLITE_TOOBIG: Final[int]
|
||||
SQLITE_WARNING: Final[int]
|
||||
SQLITE_WARNING_AUTOINDEX: Final[int]
|
||||
threadsafety: Final[int]
|
||||
|
||||
# Can take or return anything depending on what's in the registry.
|
||||
@overload
|
||||
def adapt(obj: Any, proto: Any, /) -> Any: ...
|
||||
@overload
|
||||
def adapt(obj: Any, proto: Any, alt: _T, /) -> Any | _T: ...
|
||||
def complete_statement(statement: str) -> bool: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
@overload
|
||||
def connect(
|
||||
database: StrOrBytesPath,
|
||||
timeout: float = 5.0,
|
||||
detect_types: int = 0,
|
||||
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None = "DEFERRED",
|
||||
check_same_thread: bool = True,
|
||||
cached_statements: int = 128,
|
||||
uri: bool = False,
|
||||
*,
|
||||
autocommit: bool = ...,
|
||||
) -> Connection: ...
|
||||
@overload
|
||||
def connect(
|
||||
database: StrOrBytesPath,
|
||||
timeout: float,
|
||||
detect_types: int,
|
||||
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None,
|
||||
check_same_thread: bool,
|
||||
factory: type[_ConnectionT],
|
||||
cached_statements: int = 128,
|
||||
uri: bool = False,
|
||||
*,
|
||||
autocommit: bool = ...,
|
||||
) -> _ConnectionT: ...
|
||||
@overload
|
||||
def connect(
|
||||
database: StrOrBytesPath,
|
||||
timeout: float = 5.0,
|
||||
detect_types: int = 0,
|
||||
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None = "DEFERRED",
|
||||
check_same_thread: bool = True,
|
||||
*,
|
||||
factory: type[_ConnectionT],
|
||||
cached_statements: int = 128,
|
||||
uri: bool = False,
|
||||
autocommit: bool = ...,
|
||||
) -> _ConnectionT: ...
|
||||
|
||||
else:
|
||||
@overload
|
||||
def connect(
|
||||
database: StrOrBytesPath,
|
||||
timeout: float = 5.0,
|
||||
detect_types: int = 0,
|
||||
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None = "DEFERRED",
|
||||
check_same_thread: bool = True,
|
||||
cached_statements: int = 128,
|
||||
uri: bool = False,
|
||||
) -> Connection: ...
|
||||
@overload
|
||||
def connect(
|
||||
database: StrOrBytesPath,
|
||||
timeout: float,
|
||||
detect_types: int,
|
||||
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None,
|
||||
check_same_thread: bool,
|
||||
factory: type[_ConnectionT],
|
||||
cached_statements: int = 128,
|
||||
uri: bool = False,
|
||||
) -> _ConnectionT: ...
|
||||
@overload
|
||||
def connect(
|
||||
database: StrOrBytesPath,
|
||||
timeout: float = 5.0,
|
||||
detect_types: int = 0,
|
||||
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None = "DEFERRED",
|
||||
check_same_thread: bool = True,
|
||||
*,
|
||||
factory: type[_ConnectionT],
|
||||
cached_statements: int = 128,
|
||||
uri: bool = False,
|
||||
) -> _ConnectionT: ...
|
||||
|
||||
def enable_callback_tracebacks(enable: bool, /) -> None: ...
|
||||
|
||||
if sys.version_info < (3, 12):
|
||||
# takes a pos-or-keyword argument because there is a C wrapper
|
||||
def enable_shared_cache(do_enable: int) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
def register_adapter(type: type[_T], adapter: _Adapter[_T], /) -> None: ...
|
||||
def register_converter(typename: str, converter: _Converter, /) -> None: ...
|
||||
|
||||
else:
|
||||
def register_adapter(type: type[_T], caster: _Adapter[_T], /) -> None: ...
|
||||
def register_converter(name: str, converter: _Converter, /) -> None: ...
|
||||
|
||||
if sys.version_info < (3, 10):
|
||||
OptimizedUnicode = str
|
||||
291
crates/red_knot_vendored/vendor/typeshed/stdlib/_ssl.pyi
vendored
Normal file
291
crates/red_knot_vendored/vendor/typeshed/stdlib/_ssl.pyi
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer, StrOrBytesPath
|
||||
from collections.abc import Callable
|
||||
from ssl import (
|
||||
SSLCertVerificationError as SSLCertVerificationError,
|
||||
SSLContext,
|
||||
SSLEOFError as SSLEOFError,
|
||||
SSLError as SSLError,
|
||||
SSLObject,
|
||||
SSLSyscallError as SSLSyscallError,
|
||||
SSLWantReadError as SSLWantReadError,
|
||||
SSLWantWriteError as SSLWantWriteError,
|
||||
SSLZeroReturnError as SSLZeroReturnError,
|
||||
)
|
||||
from typing import Any, ClassVar, Literal, TypedDict, final, overload
|
||||
from typing_extensions import NotRequired, Self, TypeAlias
|
||||
|
||||
_PasswordType: TypeAlias = Callable[[], str | bytes | bytearray] | str | bytes | bytearray
|
||||
_PCTRTT: TypeAlias = tuple[tuple[str, str], ...]
|
||||
_PCTRTTT: TypeAlias = tuple[_PCTRTT, ...]
|
||||
_PeerCertRetDictType: TypeAlias = dict[str, str | _PCTRTTT | _PCTRTT]
|
||||
|
||||
class _Cipher(TypedDict):
|
||||
aead: bool
|
||||
alg_bits: int
|
||||
auth: str
|
||||
description: str
|
||||
digest: str | None
|
||||
id: int
|
||||
kea: str
|
||||
name: str
|
||||
protocol: str
|
||||
strength_bits: int
|
||||
symmetric: str
|
||||
|
||||
class _CertInfo(TypedDict):
|
||||
subject: tuple[tuple[tuple[str, str], ...], ...]
|
||||
issuer: tuple[tuple[tuple[str, str], ...], ...]
|
||||
version: int
|
||||
serialNumber: str
|
||||
notBefore: str
|
||||
notAfter: str
|
||||
subjectAltName: NotRequired[tuple[tuple[str, str], ...] | None]
|
||||
OCSP: NotRequired[tuple[str, ...] | None]
|
||||
caIssuers: NotRequired[tuple[str, ...] | None]
|
||||
crlDistributionPoints: NotRequired[tuple[str, ...] | None]
|
||||
|
||||
def RAND_add(string: str | ReadableBuffer, entropy: float, /) -> None: ...
|
||||
def RAND_bytes(n: int, /) -> bytes: ...
|
||||
|
||||
if sys.version_info < (3, 12):
|
||||
def RAND_pseudo_bytes(n: int, /) -> tuple[bytes, bool]: ...
|
||||
|
||||
if sys.version_info < (3, 10):
|
||||
def RAND_egd(path: str) -> None: ...
|
||||
|
||||
def RAND_status() -> bool: ...
|
||||
def get_default_verify_paths() -> tuple[str, str, str, str]: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
_EnumRetType: TypeAlias = list[tuple[bytes, str, set[str] | bool]]
|
||||
def enum_certificates(store_name: str) -> _EnumRetType: ...
|
||||
def enum_crls(store_name: str) -> _EnumRetType: ...
|
||||
|
||||
def txt2obj(txt: str, name: bool = False) -> tuple[int, str, str, str]: ...
|
||||
def nid2obj(nid: int, /) -> tuple[int, str, str, str]: ...
|
||||
|
||||
class _SSLContext:
|
||||
check_hostname: bool
|
||||
keylog_filename: str | None
|
||||
maximum_version: int
|
||||
minimum_version: int
|
||||
num_tickets: int
|
||||
options: int
|
||||
post_handshake_auth: bool
|
||||
protocol: int
|
||||
if sys.version_info >= (3, 10):
|
||||
security_level: int
|
||||
sni_callback: Callable[[SSLObject, str, SSLContext], None | int] | None
|
||||
verify_flags: int
|
||||
verify_mode: int
|
||||
def __new__(cls, protocol: int, /) -> Self: ...
|
||||
def cert_store_stats(self) -> dict[str, int]: ...
|
||||
@overload
|
||||
def get_ca_certs(self, binary_form: Literal[False] = False) -> list[_PeerCertRetDictType]: ...
|
||||
@overload
|
||||
def get_ca_certs(self, binary_form: Literal[True]) -> list[bytes]: ...
|
||||
@overload
|
||||
def get_ca_certs(self, binary_form: bool = False) -> Any: ...
|
||||
def get_ciphers(self) -> list[_Cipher]: ...
|
||||
def load_cert_chain(
|
||||
self, certfile: StrOrBytesPath, keyfile: StrOrBytesPath | None = None, password: _PasswordType | None = None
|
||||
) -> None: ...
|
||||
def load_dh_params(self, path: str, /) -> None: ...
|
||||
def load_verify_locations(
|
||||
self,
|
||||
cafile: StrOrBytesPath | None = None,
|
||||
capath: StrOrBytesPath | None = None,
|
||||
cadata: str | ReadableBuffer | None = None,
|
||||
) -> None: ...
|
||||
def session_stats(self) -> dict[str, int]: ...
|
||||
def set_ciphers(self, cipherlist: str, /) -> None: ...
|
||||
def set_default_verify_paths(self) -> None: ...
|
||||
def set_ecdh_curve(self, name: str, /) -> None: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
def set_psk_client_callback(self, callback: Callable[[str | None], tuple[str | None, bytes]] | None) -> None: ...
|
||||
def set_psk_server_callback(
|
||||
self, callback: Callable[[str | None], bytes] | None, identity_hint: str | None = None
|
||||
) -> None: ...
|
||||
|
||||
@final
|
||||
class MemoryBIO:
|
||||
eof: bool
|
||||
pending: int
|
||||
def __new__(self) -> Self: ...
|
||||
def read(self, size: int = -1, /) -> bytes: ...
|
||||
def write(self, b: ReadableBuffer, /) -> int: ...
|
||||
def write_eof(self) -> None: ...
|
||||
|
||||
@final
|
||||
class SSLSession:
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
@property
|
||||
def has_ticket(self) -> bool: ...
|
||||
@property
|
||||
def id(self) -> bytes: ...
|
||||
@property
|
||||
def ticket_lifetime_hint(self) -> int: ...
|
||||
@property
|
||||
def time(self) -> int: ...
|
||||
@property
|
||||
def timeout(self) -> int: ...
|
||||
|
||||
# _ssl.Certificate is weird: it can't be instantiated or subclassed.
|
||||
# Instances can only be created via methods of the private _ssl._SSLSocket class,
|
||||
# for which the relevant method signatures are:
|
||||
#
|
||||
# class _SSLSocket:
|
||||
# def get_unverified_chain(self) -> list[Certificate] | None: ...
|
||||
# def get_verified_chain(self) -> list[Certificate] | None: ...
|
||||
#
|
||||
# You can find a _ssl._SSLSocket object as the _sslobj attribute of a ssl.SSLSocket object
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
@final
|
||||
class Certificate:
|
||||
def get_info(self) -> _CertInfo: ...
|
||||
@overload
|
||||
def public_bytes(self) -> str: ...
|
||||
@overload
|
||||
def public_bytes(self, format: Literal[1] = 1, /) -> str: ... # ENCODING_PEM
|
||||
@overload
|
||||
def public_bytes(self, format: Literal[2], /) -> bytes: ... # ENCODING_DER
|
||||
@overload
|
||||
def public_bytes(self, format: int, /) -> str | bytes: ...
|
||||
|
||||
if sys.version_info < (3, 12):
|
||||
err_codes_to_names: dict[tuple[int, int], str]
|
||||
err_names_to_codes: dict[str, tuple[int, int]]
|
||||
lib_codes_to_names: dict[int, str]
|
||||
|
||||
_DEFAULT_CIPHERS: str
|
||||
|
||||
# SSL error numbers
|
||||
SSL_ERROR_ZERO_RETURN: int
|
||||
SSL_ERROR_WANT_READ: int
|
||||
SSL_ERROR_WANT_WRITE: int
|
||||
SSL_ERROR_WANT_X509_LOOKUP: int
|
||||
SSL_ERROR_SYSCALL: int
|
||||
SSL_ERROR_SSL: int
|
||||
SSL_ERROR_WANT_CONNECT: int
|
||||
SSL_ERROR_EOF: int
|
||||
SSL_ERROR_INVALID_ERROR_CODE: int
|
||||
|
||||
# verify modes
|
||||
CERT_NONE: int
|
||||
CERT_OPTIONAL: int
|
||||
CERT_REQUIRED: int
|
||||
|
||||
# verify flags
|
||||
VERIFY_DEFAULT: int
|
||||
VERIFY_CRL_CHECK_LEAF: int
|
||||
VERIFY_CRL_CHECK_CHAIN: int
|
||||
VERIFY_X509_STRICT: int
|
||||
VERIFY_X509_TRUSTED_FIRST: int
|
||||
if sys.version_info >= (3, 10):
|
||||
VERIFY_ALLOW_PROXY_CERTS: int
|
||||
VERIFY_X509_PARTIAL_CHAIN: int
|
||||
|
||||
# alert descriptions
|
||||
ALERT_DESCRIPTION_CLOSE_NOTIFY: int
|
||||
ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: int
|
||||
ALERT_DESCRIPTION_BAD_RECORD_MAC: int
|
||||
ALERT_DESCRIPTION_RECORD_OVERFLOW: int
|
||||
ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: int
|
||||
ALERT_DESCRIPTION_HANDSHAKE_FAILURE: int
|
||||
ALERT_DESCRIPTION_BAD_CERTIFICATE: int
|
||||
ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: int
|
||||
ALERT_DESCRIPTION_CERTIFICATE_REVOKED: int
|
||||
ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: int
|
||||
ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: int
|
||||
ALERT_DESCRIPTION_ILLEGAL_PARAMETER: int
|
||||
ALERT_DESCRIPTION_UNKNOWN_CA: int
|
||||
ALERT_DESCRIPTION_ACCESS_DENIED: int
|
||||
ALERT_DESCRIPTION_DECODE_ERROR: int
|
||||
ALERT_DESCRIPTION_DECRYPT_ERROR: int
|
||||
ALERT_DESCRIPTION_PROTOCOL_VERSION: int
|
||||
ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: int
|
||||
ALERT_DESCRIPTION_INTERNAL_ERROR: int
|
||||
ALERT_DESCRIPTION_USER_CANCELLED: int
|
||||
ALERT_DESCRIPTION_NO_RENEGOTIATION: int
|
||||
ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: int
|
||||
ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: int
|
||||
ALERT_DESCRIPTION_UNRECOGNIZED_NAME: int
|
||||
ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: int
|
||||
ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: int
|
||||
ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: int
|
||||
|
||||
# protocol versions
|
||||
PROTOCOL_SSLv23: int
|
||||
PROTOCOL_TLS: int
|
||||
PROTOCOL_TLS_CLIENT: int
|
||||
PROTOCOL_TLS_SERVER: int
|
||||
PROTOCOL_TLSv1: int
|
||||
PROTOCOL_TLSv1_1: int
|
||||
PROTOCOL_TLSv1_2: int
|
||||
|
||||
# protocol options
|
||||
OP_ALL: int
|
||||
OP_NO_SSLv2: int
|
||||
OP_NO_SSLv3: int
|
||||
OP_NO_TLSv1: int
|
||||
OP_NO_TLSv1_1: int
|
||||
OP_NO_TLSv1_2: int
|
||||
OP_NO_TLSv1_3: int
|
||||
OP_CIPHER_SERVER_PREFERENCE: int
|
||||
OP_SINGLE_DH_USE: int
|
||||
OP_NO_TICKET: int
|
||||
OP_SINGLE_ECDH_USE: int
|
||||
OP_NO_COMPRESSION: int
|
||||
OP_ENABLE_MIDDLEBOX_COMPAT: int
|
||||
OP_NO_RENEGOTIATION: int
|
||||
if sys.version_info >= (3, 11) or sys.platform == "linux":
|
||||
OP_IGNORE_UNEXPECTED_EOF: int
|
||||
if sys.version_info >= (3, 12):
|
||||
OP_LEGACY_SERVER_CONNECT: int
|
||||
OP_ENABLE_KTLS: int
|
||||
|
||||
# host flags
|
||||
HOSTFLAG_ALWAYS_CHECK_SUBJECT: int
|
||||
HOSTFLAG_NEVER_CHECK_SUBJECT: int
|
||||
HOSTFLAG_NO_WILDCARDS: int
|
||||
HOSTFLAG_NO_PARTIAL_WILDCARDS: int
|
||||
HOSTFLAG_MULTI_LABEL_WILDCARDS: int
|
||||
HOSTFLAG_SINGLE_LABEL_SUBDOMAINS: int
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
# certificate file types
|
||||
# Typed as Literal so the overload on Certificate.public_bytes can work properly.
|
||||
ENCODING_PEM: Literal[1]
|
||||
ENCODING_DER: Literal[2]
|
||||
|
||||
# protocol versions
|
||||
PROTO_MINIMUM_SUPPORTED: int
|
||||
PROTO_MAXIMUM_SUPPORTED: int
|
||||
PROTO_SSLv3: int
|
||||
PROTO_TLSv1: int
|
||||
PROTO_TLSv1_1: int
|
||||
PROTO_TLSv1_2: int
|
||||
PROTO_TLSv1_3: int
|
||||
|
||||
# feature support
|
||||
HAS_SNI: bool
|
||||
HAS_TLS_UNIQUE: bool
|
||||
HAS_ECDH: bool
|
||||
HAS_NPN: bool
|
||||
if sys.version_info >= (3, 13):
|
||||
HAS_PSK: bool
|
||||
HAS_ALPN: bool
|
||||
HAS_SSLv2: bool
|
||||
HAS_SSLv3: bool
|
||||
HAS_TLSv1: bool
|
||||
HAS_TLSv1_1: bool
|
||||
HAS_TLSv1_2: bool
|
||||
HAS_TLSv1_3: bool
|
||||
|
||||
# version info
|
||||
OPENSSL_VERSION_NUMBER: int
|
||||
OPENSSL_VERSION_INFO: tuple[int, int, int, int, int]
|
||||
OPENSSL_VERSION: str
|
||||
_OPENSSL_API_VERSION: tuple[int, int, int, int, int]
|
||||
119
crates/red_knot_vendored/vendor/typeshed/stdlib/_stat.pyi
vendored
Normal file
119
crates/red_knot_vendored/vendor/typeshed/stdlib/_stat.pyi
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
import sys
|
||||
from typing import Final
|
||||
|
||||
SF_APPEND: Final = 0x00040000
|
||||
SF_ARCHIVED: Final = 0x00010000
|
||||
SF_IMMUTABLE: Final = 0x00020000
|
||||
SF_NOUNLINK: Final = 0x00100000
|
||||
SF_SNAPSHOT: Final = 0x00200000
|
||||
|
||||
ST_MODE: Final = 0
|
||||
ST_INO: Final = 1
|
||||
ST_DEV: Final = 2
|
||||
ST_NLINK: Final = 3
|
||||
ST_UID: Final = 4
|
||||
ST_GID: Final = 5
|
||||
ST_SIZE: Final = 6
|
||||
ST_ATIME: Final = 7
|
||||
ST_MTIME: Final = 8
|
||||
ST_CTIME: Final = 9
|
||||
|
||||
S_IFIFO: Final = 0o010000
|
||||
S_IFLNK: Final = 0o120000
|
||||
S_IFREG: Final = 0o100000
|
||||
S_IFSOCK: Final = 0o140000
|
||||
S_IFBLK: Final = 0o060000
|
||||
S_IFCHR: Final = 0o020000
|
||||
S_IFDIR: Final = 0o040000
|
||||
|
||||
# These are 0 on systems that don't support the specific kind of file.
|
||||
# Example: Linux doesn't support door files, so S_IFDOOR is 0 on linux.
|
||||
S_IFDOOR: Final[int]
|
||||
S_IFPORT: Final[int]
|
||||
S_IFWHT: Final[int]
|
||||
|
||||
S_ISUID: Final = 0o4000
|
||||
S_ISGID: Final = 0o2000
|
||||
S_ISVTX: Final = 0o1000
|
||||
|
||||
S_IRWXU: Final = 0o0700
|
||||
S_IRUSR: Final = 0o0400
|
||||
S_IWUSR: Final = 0o0200
|
||||
S_IXUSR: Final = 0o0100
|
||||
|
||||
S_IRWXG: Final = 0o0070
|
||||
S_IRGRP: Final = 0o0040
|
||||
S_IWGRP: Final = 0o0020
|
||||
S_IXGRP: Final = 0o0010
|
||||
|
||||
S_IRWXO: Final = 0o0007
|
||||
S_IROTH: Final = 0o0004
|
||||
S_IWOTH: Final = 0o0002
|
||||
S_IXOTH: Final = 0o0001
|
||||
|
||||
S_ENFMT: Final = 0o2000
|
||||
S_IREAD: Final = 0o0400
|
||||
S_IWRITE: Final = 0o0200
|
||||
S_IEXEC: Final = 0o0100
|
||||
|
||||
UF_APPEND: Final = 0x00000004
|
||||
UF_COMPRESSED: Final = 0x00000020 # OS X 10.6+ only
|
||||
UF_HIDDEN: Final = 0x00008000 # OX X 10.5+ only
|
||||
UF_IMMUTABLE: Final = 0x00000002
|
||||
UF_NODUMP: Final = 0x00000001
|
||||
UF_NOUNLINK: Final = 0x00000010
|
||||
UF_OPAQUE: Final = 0x00000008
|
||||
|
||||
def S_IMODE(mode: int, /) -> int: ...
|
||||
def S_IFMT(mode: int, /) -> int: ...
|
||||
def S_ISBLK(mode: int, /) -> bool: ...
|
||||
def S_ISCHR(mode: int, /) -> bool: ...
|
||||
def S_ISDIR(mode: int, /) -> bool: ...
|
||||
def S_ISDOOR(mode: int, /) -> bool: ...
|
||||
def S_ISFIFO(mode: int, /) -> bool: ...
|
||||
def S_ISLNK(mode: int, /) -> bool: ...
|
||||
def S_ISPORT(mode: int, /) -> bool: ...
|
||||
def S_ISREG(mode: int, /) -> bool: ...
|
||||
def S_ISSOCK(mode: int, /) -> bool: ...
|
||||
def S_ISWHT(mode: int, /) -> bool: ...
|
||||
def filemode(mode: int, /) -> str: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
IO_REPARSE_TAG_SYMLINK: Final = 0xA000000C
|
||||
IO_REPARSE_TAG_MOUNT_POINT: Final = 0xA0000003
|
||||
IO_REPARSE_TAG_APPEXECLINK: Final = 0x8000001B
|
||||
|
||||
if sys.platform == "win32":
|
||||
FILE_ATTRIBUTE_ARCHIVE: Final = 32
|
||||
FILE_ATTRIBUTE_COMPRESSED: Final = 2048
|
||||
FILE_ATTRIBUTE_DEVICE: Final = 64
|
||||
FILE_ATTRIBUTE_DIRECTORY: Final = 16
|
||||
FILE_ATTRIBUTE_ENCRYPTED: Final = 16384
|
||||
FILE_ATTRIBUTE_HIDDEN: Final = 2
|
||||
FILE_ATTRIBUTE_INTEGRITY_STREAM: Final = 32768
|
||||
FILE_ATTRIBUTE_NORMAL: Final = 128
|
||||
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED: Final = 8192
|
||||
FILE_ATTRIBUTE_NO_SCRUB_DATA: Final = 131072
|
||||
FILE_ATTRIBUTE_OFFLINE: Final = 4096
|
||||
FILE_ATTRIBUTE_READONLY: Final = 1
|
||||
FILE_ATTRIBUTE_REPARSE_POINT: Final = 1024
|
||||
FILE_ATTRIBUTE_SPARSE_FILE: Final = 512
|
||||
FILE_ATTRIBUTE_SYSTEM: Final = 4
|
||||
FILE_ATTRIBUTE_TEMPORARY: Final = 256
|
||||
FILE_ATTRIBUTE_VIRTUAL: Final = 65536
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
# Varies by platform.
|
||||
SF_SETTABLE: Final[int]
|
||||
# https://github.com/python/cpython/issues/114081#issuecomment-2119017790
|
||||
# SF_RESTRICTED: Literal[0x00080000]
|
||||
SF_FIRMLINK: Final = 0x00800000
|
||||
SF_DATALESS: Final = 0x40000000
|
||||
|
||||
if sys.platform == "darwin":
|
||||
SF_SUPPORTED: Final = 0x9F0000
|
||||
SF_SYNTHETIC: Final = 0xC0000000
|
||||
|
||||
UF_TRACKED: Final = 0x00000040
|
||||
UF_DATAVAULT: Final = 0x00000080
|
||||
UF_SETTABLE: Final = 0x0000FFFF
|
||||
22
crates/red_knot_vendored/vendor/typeshed/stdlib/_struct.pyi
vendored
Normal file
22
crates/red_knot_vendored/vendor/typeshed/stdlib/_struct.pyi
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
from _typeshed import ReadableBuffer, WriteableBuffer
|
||||
from collections.abc import Iterator
|
||||
from typing import Any
|
||||
|
||||
def pack(fmt: str | bytes, /, *v: Any) -> bytes: ...
|
||||
def pack_into(fmt: str | bytes, buffer: WriteableBuffer, offset: int, /, *v: Any) -> None: ...
|
||||
def unpack(format: str | bytes, buffer: ReadableBuffer, /) -> tuple[Any, ...]: ...
|
||||
def unpack_from(format: str | bytes, /, buffer: ReadableBuffer, offset: int = 0) -> tuple[Any, ...]: ...
|
||||
def iter_unpack(format: str | bytes, buffer: ReadableBuffer, /) -> Iterator[tuple[Any, ...]]: ...
|
||||
def calcsize(format: str | bytes, /) -> int: ...
|
||||
|
||||
class Struct:
|
||||
@property
|
||||
def format(self) -> str: ...
|
||||
@property
|
||||
def size(self) -> int: ...
|
||||
def __init__(self, format: str | bytes) -> None: ...
|
||||
def pack(self, *v: Any) -> bytes: ...
|
||||
def pack_into(self, buffer: WriteableBuffer, offset: int, *v: Any) -> None: ...
|
||||
def unpack(self, buffer: ReadableBuffer, /) -> tuple[Any, ...]: ...
|
||||
def unpack_from(self, buffer: ReadableBuffer, offset: int = 0) -> tuple[Any, ...]: ...
|
||||
def iter_unpack(self, buffer: ReadableBuffer, /) -> Iterator[tuple[Any, ...]]: ...
|
||||
111
crates/red_knot_vendored/vendor/typeshed/stdlib/_thread.pyi
vendored
Normal file
111
crates/red_knot_vendored/vendor/typeshed/stdlib/_thread.pyi
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
import signal
|
||||
import sys
|
||||
from _typeshed import structseq
|
||||
from collections.abc import Callable
|
||||
from threading import Thread
|
||||
from types import TracebackType
|
||||
from typing import Any, Final, NoReturn, final, overload
|
||||
from typing_extensions import TypeVarTuple, Unpack
|
||||
|
||||
_Ts = TypeVarTuple("_Ts")
|
||||
|
||||
error = RuntimeError
|
||||
|
||||
def _count() -> int: ...
|
||||
@final
|
||||
class RLock:
|
||||
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
|
||||
def release(self) -> None: ...
|
||||
__enter__ = acquire
|
||||
def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
@final
|
||||
class _ThreadHandle:
|
||||
ident: int
|
||||
|
||||
def join(self, timeout: float | None = None, /) -> None: ...
|
||||
def is_done(self) -> bool: ...
|
||||
def _set_done(self) -> None: ...
|
||||
|
||||
def start_joinable_thread(
|
||||
function: Callable[[], object], handle: _ThreadHandle | None = None, daemon: bool = True
|
||||
) -> _ThreadHandle: ...
|
||||
@final
|
||||
class lock:
|
||||
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
|
||||
def release(self) -> None: ...
|
||||
def locked(self) -> bool: ...
|
||||
def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ...
|
||||
def release_lock(self) -> None: ...
|
||||
def locked_lock(self) -> bool: ...
|
||||
def __enter__(self) -> bool: ...
|
||||
def __exit__(
|
||||
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
LockType = lock
|
||||
else:
|
||||
@final
|
||||
class LockType:
|
||||
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
|
||||
def release(self) -> None: ...
|
||||
def locked(self) -> bool: ...
|
||||
def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ...
|
||||
def release_lock(self) -> None: ...
|
||||
def locked_lock(self) -> bool: ...
|
||||
def __enter__(self) -> bool: ...
|
||||
def __exit__(
|
||||
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
@overload
|
||||
def start_new_thread(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], /) -> int: ...
|
||||
@overload
|
||||
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ...
|
||||
|
||||
# Obsolete synonym for start_new_thread()
|
||||
@overload
|
||||
def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], /) -> int: ...
|
||||
@overload
|
||||
def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
def interrupt_main(signum: signal.Signals = ..., /) -> None: ...
|
||||
|
||||
else:
|
||||
def interrupt_main() -> None: ...
|
||||
|
||||
def exit() -> NoReturn: ...
|
||||
def exit_thread() -> NoReturn: ... # Obsolete synonym for exit()
|
||||
def allocate_lock() -> LockType: ...
|
||||
def allocate() -> LockType: ... # Obsolete synonym for allocate_lock()
|
||||
def get_ident() -> int: ...
|
||||
def stack_size(size: int = 0, /) -> int: ...
|
||||
|
||||
TIMEOUT_MAX: float
|
||||
|
||||
def get_native_id() -> int: ... # only available on some platforms
|
||||
@final
|
||||
class _ExceptHookArgs(structseq[Any], tuple[type[BaseException], BaseException | None, TracebackType | None, Thread | None]):
|
||||
if sys.version_info >= (3, 10):
|
||||
__match_args__: Final = ("exc_type", "exc_value", "exc_traceback", "thread")
|
||||
|
||||
@property
|
||||
def exc_type(self) -> type[BaseException]: ...
|
||||
@property
|
||||
def exc_value(self) -> BaseException | None: ...
|
||||
@property
|
||||
def exc_traceback(self) -> TracebackType | None: ...
|
||||
@property
|
||||
def thread(self) -> Thread | None: ...
|
||||
|
||||
_excepthook: Callable[[_ExceptHookArgs], Any]
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
def daemon_threads_allowed() -> bool: ...
|
||||
|
||||
class _local:
|
||||
def __getattribute__(self, name: str, /) -> Any: ...
|
||||
def __setattr__(self, name: str, value: Any, /) -> None: ...
|
||||
def __delattr__(self, name: str, /) -> None: ...
|
||||
22
crates/red_knot_vendored/vendor/typeshed/stdlib/_threading_local.pyi
vendored
Normal file
22
crates/red_knot_vendored/vendor/typeshed/stdlib/_threading_local.pyi
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
from threading import RLock
|
||||
from typing import Any
|
||||
from typing_extensions import Self, TypeAlias
|
||||
from weakref import ReferenceType
|
||||
|
||||
__all__ = ["local"]
|
||||
_LocalDict: TypeAlias = dict[Any, Any]
|
||||
|
||||
class _localimpl:
|
||||
key: str
|
||||
dicts: dict[int, tuple[ReferenceType[Any], _LocalDict]]
|
||||
# Keep localargs in sync with the *args, **kwargs annotation on local.__new__
|
||||
localargs: tuple[list[Any], dict[str, Any]]
|
||||
locallock: RLock
|
||||
def get_dict(self) -> _LocalDict: ...
|
||||
def create_dict(self) -> _LocalDict: ...
|
||||
|
||||
class local:
|
||||
def __new__(cls, /, *args: Any, **kw: Any) -> Self: ...
|
||||
def __getattribute__(self, name: str) -> Any: ...
|
||||
def __setattr__(self, name: str, value: Any) -> None: ...
|
||||
def __delattr__(self, name: str) -> None: ...
|
||||
143
crates/red_knot_vendored/vendor/typeshed/stdlib/_tkinter.pyi
vendored
Normal file
143
crates/red_knot_vendored/vendor/typeshed/stdlib/_tkinter.pyi
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
import sys
|
||||
from collections.abc import Callable
|
||||
from typing import Any, ClassVar, Final, final
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
# _tkinter is meant to be only used internally by tkinter, but some tkinter
|
||||
# functions e.g. return _tkinter.Tcl_Obj objects. Tcl_Obj represents a Tcl
|
||||
# object that hasn't been converted to a string.
|
||||
#
|
||||
# There are not many ways to get Tcl_Objs from tkinter, and I'm not sure if the
|
||||
# only existing ways are supposed to return Tcl_Objs as opposed to returning
|
||||
# strings. Here's one of these things that return Tcl_Objs:
|
||||
#
|
||||
# >>> import tkinter
|
||||
# >>> text = tkinter.Text()
|
||||
# >>> text.tag_add('foo', '1.0', 'end')
|
||||
# >>> text.tag_ranges('foo')
|
||||
# (<textindex object: '1.0'>, <textindex object: '2.0'>)
|
||||
@final
|
||||
class Tcl_Obj:
|
||||
@property
|
||||
def string(self) -> str: ...
|
||||
@property
|
||||
def typename(self) -> str: ...
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
def __eq__(self, value, /): ...
|
||||
def __ge__(self, value, /): ...
|
||||
def __gt__(self, value, /): ...
|
||||
def __le__(self, value, /): ...
|
||||
def __lt__(self, value, /): ...
|
||||
def __ne__(self, value, /): ...
|
||||
|
||||
class TclError(Exception): ...
|
||||
|
||||
_TkinterTraceFunc: TypeAlias = Callable[[tuple[str, ...]], object]
|
||||
|
||||
# This class allows running Tcl code. Tkinter uses it internally a lot, and
|
||||
# it's often handy to drop a piece of Tcl code into a tkinter program. Example:
|
||||
#
|
||||
# >>> import tkinter, _tkinter
|
||||
# >>> tkapp = tkinter.Tk().tk
|
||||
# >>> isinstance(tkapp, _tkinter.TkappType)
|
||||
# True
|
||||
# >>> tkapp.call('set', 'foo', (1,2,3))
|
||||
# (1, 2, 3)
|
||||
# >>> tkapp.eval('return $foo')
|
||||
# '1 2 3'
|
||||
# >>>
|
||||
#
|
||||
# call args can be pretty much anything. Also, call(some_tuple) is same as call(*some_tuple).
|
||||
#
|
||||
# eval always returns str because _tkinter_tkapp_eval_impl in _tkinter.c calls
|
||||
# Tkapp_UnicodeResult, and it returns a string when it succeeds.
|
||||
@final
|
||||
class TkappType:
|
||||
# Please keep in sync with tkinter.Tk
|
||||
def adderrorinfo(self, msg, /): ...
|
||||
def call(self, command: Any, /, *args: Any) -> Any: ...
|
||||
def createcommand(self, name, func, /): ...
|
||||
if sys.platform != "win32":
|
||||
def createfilehandler(self, file, mask, func, /): ...
|
||||
def deletefilehandler(self, file, /): ...
|
||||
|
||||
def createtimerhandler(self, milliseconds, func, /): ...
|
||||
def deletecommand(self, name, /): ...
|
||||
def dooneevent(self, flags: int = 0, /): ...
|
||||
def eval(self, script: str, /) -> str: ...
|
||||
def evalfile(self, fileName, /): ...
|
||||
def exprboolean(self, s, /): ...
|
||||
def exprdouble(self, s, /): ...
|
||||
def exprlong(self, s, /): ...
|
||||
def exprstring(self, s, /): ...
|
||||
def getboolean(self, arg, /): ...
|
||||
def getdouble(self, arg, /): ...
|
||||
def getint(self, arg, /): ...
|
||||
def getvar(self, *args, **kwargs): ...
|
||||
def globalgetvar(self, *args, **kwargs): ...
|
||||
def globalsetvar(self, *args, **kwargs): ...
|
||||
def globalunsetvar(self, *args, **kwargs): ...
|
||||
def interpaddr(self): ...
|
||||
def loadtk(self) -> None: ...
|
||||
def mainloop(self, threshold: int = 0, /): ...
|
||||
def quit(self): ...
|
||||
def record(self, script, /): ...
|
||||
def setvar(self, *ags, **kwargs): ...
|
||||
if sys.version_info < (3, 11):
|
||||
def split(self, arg, /): ...
|
||||
|
||||
def splitlist(self, arg, /): ...
|
||||
def unsetvar(self, *args, **kwargs): ...
|
||||
def wantobjects(self, *args, **kwargs): ...
|
||||
def willdispatch(self): ...
|
||||
if sys.version_info >= (3, 12):
|
||||
def gettrace(self, /) -> _TkinterTraceFunc | None: ...
|
||||
def settrace(self, func: _TkinterTraceFunc | None, /) -> None: ...
|
||||
|
||||
# These should be kept in sync with tkinter.tix constants, except ALL_EVENTS which doesn't match TCL_ALL_EVENTS
|
||||
ALL_EVENTS: Final = -3
|
||||
FILE_EVENTS: Final = 8
|
||||
IDLE_EVENTS: Final = 32
|
||||
TIMER_EVENTS: Final = 16
|
||||
WINDOW_EVENTS: Final = 4
|
||||
|
||||
DONT_WAIT: Final = 2
|
||||
EXCEPTION: Final = 8
|
||||
READABLE: Final = 2
|
||||
WRITABLE: Final = 4
|
||||
|
||||
TCL_VERSION: Final[str]
|
||||
TK_VERSION: Final[str]
|
||||
|
||||
@final
|
||||
class TkttType:
|
||||
def deletetimerhandler(self): ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
def create(
|
||||
screenName: str | None = None,
|
||||
baseName: str = "",
|
||||
className: str = "Tk",
|
||||
interactive: bool = False,
|
||||
wantobjects: int = 0,
|
||||
wantTk: bool = True,
|
||||
sync: bool = False,
|
||||
use: str | None = None,
|
||||
/,
|
||||
): ...
|
||||
|
||||
else:
|
||||
def create(
|
||||
screenName: str | None = None,
|
||||
baseName: str = "",
|
||||
className: str = "Tk",
|
||||
interactive: bool = False,
|
||||
wantobjects: bool = False,
|
||||
wantTk: bool = True,
|
||||
sync: bool = False,
|
||||
use: str | None = None,
|
||||
/,
|
||||
): ...
|
||||
|
||||
def getbusywaitinterval(): ...
|
||||
def setbusywaitinterval(new_val, /): ...
|
||||
13
crates/red_knot_vendored/vendor/typeshed/stdlib/_tracemalloc.pyi
vendored
Normal file
13
crates/red_knot_vendored/vendor/typeshed/stdlib/_tracemalloc.pyi
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
from collections.abc import Sequence
|
||||
from tracemalloc import _FrameTuple, _TraceTuple
|
||||
|
||||
def _get_object_traceback(obj: object, /) -> Sequence[_FrameTuple] | None: ...
|
||||
def _get_traces() -> Sequence[_TraceTuple]: ...
|
||||
def clear_traces() -> None: ...
|
||||
def get_traceback_limit() -> int: ...
|
||||
def get_traced_memory() -> tuple[int, int]: ...
|
||||
def get_tracemalloc_memory() -> int: ...
|
||||
def is_tracing() -> bool: ...
|
||||
def reset_peak() -> None: ...
|
||||
def start(nframe: int = 1, /) -> None: ...
|
||||
def stop() -> None: ...
|
||||
@@ -1,7 +1,366 @@
|
||||
import sys
|
||||
# Utility types for typeshed
|
||||
#
|
||||
# See the README.md file in this directory for more information.
|
||||
|
||||
# issue only repros if we check `sys.version_info` here; no other test will do
|
||||
import sys
|
||||
from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as AbstractSet, Sized
|
||||
from dataclasses import Field
|
||||
from os import PathLike
|
||||
from types import FrameType, TracebackType
|
||||
from typing import (
|
||||
Any,
|
||||
AnyStr,
|
||||
ClassVar,
|
||||
Final,
|
||||
Generic,
|
||||
Literal,
|
||||
Protocol,
|
||||
SupportsFloat,
|
||||
SupportsIndex,
|
||||
SupportsInt,
|
||||
TypeVar,
|
||||
final,
|
||||
overload,
|
||||
)
|
||||
from typing_extensions import Buffer, LiteralString, Self as _Self, TypeAlias
|
||||
|
||||
_KT = TypeVar("_KT")
|
||||
_KT_co = TypeVar("_KT_co", covariant=True)
|
||||
_KT_contra = TypeVar("_KT_contra", contravariant=True)
|
||||
_VT = TypeVar("_VT")
|
||||
_VT_co = TypeVar("_VT_co", covariant=True)
|
||||
_T = TypeVar("_T")
|
||||
_T_co = TypeVar("_T_co", covariant=True)
|
||||
_T_contra = TypeVar("_T_contra", contravariant=True)
|
||||
|
||||
# Alternative to `typing_extensions.Self`, exclusively for use with `__new__`
|
||||
# in metaclasses:
|
||||
# def __new__(cls: type[Self], ...) -> Self: ...
|
||||
# In other cases, use `typing_extensions.Self`.
|
||||
Self = TypeVar("Self") # noqa: Y001
|
||||
|
||||
# covariant version of typing.AnyStr, useful for protocols
|
||||
AnyStr_co = TypeVar("AnyStr_co", str, bytes, covariant=True) # noqa: Y001
|
||||
|
||||
# For partially known annotations. Usually, fields where type annotations
|
||||
# haven't been added are left unannotated, but in some situations this
|
||||
# isn't possible or a type is already partially known. In cases like these,
|
||||
# use Incomplete instead of Any as a marker. For example, use
|
||||
# "Incomplete | None" instead of "Any | None".
|
||||
Incomplete: TypeAlias = Any # stable
|
||||
|
||||
# To describe a function parameter that is unused and will work with anything.
|
||||
Unused: TypeAlias = object # stable
|
||||
|
||||
# Marker for return types that include None, but where forcing the user to
|
||||
# check for None can be detrimental. Sometimes called "the Any trick". See
|
||||
# CONTRIBUTING.md for more information.
|
||||
MaybeNone: TypeAlias = Any # stable
|
||||
|
||||
# Used to mark arguments that default to a sentinel value. This prevents
|
||||
# stubtest from complaining about the default value not matching.
|
||||
#
|
||||
# def foo(x: int | None = sentinel) -> None: ...
|
||||
#
|
||||
# In cases where the sentinel object is exported and can be used by user code,
|
||||
# a construct like this is better:
|
||||
#
|
||||
# _SentinelType = NewType("_SentinelType", object)
|
||||
# sentinel: _SentinelType
|
||||
# def foo(x: int | None | _SentinelType = ...) -> None: ...
|
||||
sentinel: Any
|
||||
|
||||
# stable
|
||||
class IdentityFunction(Protocol):
|
||||
def __call__(self, x: _T, /) -> _T: ...
|
||||
|
||||
# stable
|
||||
class SupportsNext(Protocol[_T_co]):
|
||||
def __next__(self) -> _T_co: ...
|
||||
|
||||
# stable
|
||||
class SupportsAnext(Protocol[_T_co]):
|
||||
def __anext__(self) -> Awaitable[_T_co]: ...
|
||||
|
||||
# Comparison protocols
|
||||
|
||||
class SupportsDunderLT(Protocol[_T_contra]):
|
||||
def __lt__(self, other: _T_contra, /) -> bool: ...
|
||||
|
||||
class SupportsDunderGT(Protocol[_T_contra]):
|
||||
def __gt__(self, other: _T_contra, /) -> bool: ...
|
||||
|
||||
class SupportsDunderLE(Protocol[_T_contra]):
|
||||
def __le__(self, other: _T_contra, /) -> bool: ...
|
||||
|
||||
class SupportsDunderGE(Protocol[_T_contra]):
|
||||
def __ge__(self, other: _T_contra, /) -> bool: ...
|
||||
|
||||
class SupportsAllComparisons(
|
||||
SupportsDunderLT[Any], SupportsDunderGT[Any], SupportsDunderLE[Any], SupportsDunderGE[Any], Protocol
|
||||
): ...
|
||||
|
||||
SupportsRichComparison: TypeAlias = SupportsDunderLT[Any] | SupportsDunderGT[Any]
|
||||
SupportsRichComparisonT = TypeVar("SupportsRichComparisonT", bound=SupportsRichComparison) # noqa: Y001
|
||||
|
||||
# Dunder protocols
|
||||
|
||||
class SupportsAdd(Protocol[_T_contra, _T_co]):
|
||||
def __add__(self, x: _T_contra, /) -> _T_co: ...
|
||||
|
||||
class SupportsRAdd(Protocol[_T_contra, _T_co]):
|
||||
def __radd__(self, x: _T_contra, /) -> _T_co: ...
|
||||
|
||||
class SupportsSub(Protocol[_T_contra, _T_co]):
|
||||
def __sub__(self, x: _T_contra, /) -> _T_co: ...
|
||||
|
||||
class SupportsRSub(Protocol[_T_contra, _T_co]):
|
||||
def __rsub__(self, x: _T_contra, /) -> _T_co: ...
|
||||
|
||||
class SupportsMul(Protocol[_T_contra, _T_co]):
|
||||
def __mul__(self, x: _T_contra, /) -> _T_co: ...
|
||||
|
||||
class SupportsRMul(Protocol[_T_contra, _T_co]):
|
||||
def __rmul__(self, x: _T_contra, /) -> _T_co: ...
|
||||
|
||||
class SupportsDivMod(Protocol[_T_contra, _T_co]):
|
||||
def __divmod__(self, other: _T_contra, /) -> _T_co: ...
|
||||
|
||||
class SupportsRDivMod(Protocol[_T_contra, _T_co]):
|
||||
def __rdivmod__(self, other: _T_contra, /) -> _T_co: ...
|
||||
|
||||
# This protocol is generic over the iterator type, while Iterable is
|
||||
# generic over the type that is iterated over.
|
||||
class SupportsIter(Protocol[_T_co]):
|
||||
def __iter__(self) -> _T_co: ...
|
||||
|
||||
# This protocol is generic over the iterator type, while AsyncIterable is
|
||||
# generic over the type that is iterated over.
|
||||
class SupportsAiter(Protocol[_T_co]):
|
||||
def __aiter__(self) -> _T_co: ...
|
||||
|
||||
class SupportsLenAndGetItem(Protocol[_T_co]):
|
||||
def __len__(self) -> int: ...
|
||||
def __getitem__(self, k: int, /) -> _T_co: ...
|
||||
|
||||
class SupportsTrunc(Protocol):
|
||||
def __trunc__(self) -> int: ...
|
||||
|
||||
# Mapping-like protocols
|
||||
|
||||
# stable
|
||||
class SupportsItems(Protocol[_KT_co, _VT_co]):
|
||||
def items(self) -> AbstractSet[tuple[_KT_co, _VT_co]]: ...
|
||||
|
||||
# stable
|
||||
class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
|
||||
def keys(self) -> Iterable[_KT]: ...
|
||||
def __getitem__(self, key: _KT, /) -> _VT_co: ...
|
||||
|
||||
# stable
|
||||
class SupportsGetItem(Protocol[_KT_contra, _VT_co]):
|
||||
def __getitem__(self, key: _KT_contra, /) -> _VT_co: ...
|
||||
|
||||
# stable
|
||||
class SupportsContainsAndGetItem(Protocol[_KT_contra, _VT_co]):
|
||||
def __contains__(self, x: Any, /) -> bool: ...
|
||||
def __getitem__(self, key: _KT_contra, /) -> _VT_co: ...
|
||||
|
||||
# stable
|
||||
class SupportsItemAccess(Protocol[_KT_contra, _VT]):
|
||||
def __contains__(self, x: Any, /) -> bool: ...
|
||||
def __getitem__(self, key: _KT_contra, /) -> _VT: ...
|
||||
def __setitem__(self, key: _KT_contra, value: _VT, /) -> None: ...
|
||||
def __delitem__(self, key: _KT_contra, /) -> None: ...
|
||||
|
||||
StrPath: TypeAlias = str | PathLike[str] # stable
|
||||
BytesPath: TypeAlias = bytes | PathLike[bytes] # stable
|
||||
GenericPath: TypeAlias = AnyStr | PathLike[AnyStr]
|
||||
StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes] # stable
|
||||
|
||||
OpenTextModeUpdating: TypeAlias = Literal[
|
||||
"r+",
|
||||
"+r",
|
||||
"rt+",
|
||||
"r+t",
|
||||
"+rt",
|
||||
"tr+",
|
||||
"t+r",
|
||||
"+tr",
|
||||
"w+",
|
||||
"+w",
|
||||
"wt+",
|
||||
"w+t",
|
||||
"+wt",
|
||||
"tw+",
|
||||
"t+w",
|
||||
"+tw",
|
||||
"a+",
|
||||
"+a",
|
||||
"at+",
|
||||
"a+t",
|
||||
"+at",
|
||||
"ta+",
|
||||
"t+a",
|
||||
"+ta",
|
||||
"x+",
|
||||
"+x",
|
||||
"xt+",
|
||||
"x+t",
|
||||
"+xt",
|
||||
"tx+",
|
||||
"t+x",
|
||||
"+tx",
|
||||
]
|
||||
OpenTextModeWriting: TypeAlias = Literal["w", "wt", "tw", "a", "at", "ta", "x", "xt", "tx"]
|
||||
OpenTextModeReading: TypeAlias = Literal["r", "rt", "tr", "U", "rU", "Ur", "rtU", "rUt", "Urt", "trU", "tUr", "Utr"]
|
||||
OpenTextMode: TypeAlias = OpenTextModeUpdating | OpenTextModeWriting | OpenTextModeReading
|
||||
OpenBinaryModeUpdating: TypeAlias = Literal[
|
||||
"rb+",
|
||||
"r+b",
|
||||
"+rb",
|
||||
"br+",
|
||||
"b+r",
|
||||
"+br",
|
||||
"wb+",
|
||||
"w+b",
|
||||
"+wb",
|
||||
"bw+",
|
||||
"b+w",
|
||||
"+bw",
|
||||
"ab+",
|
||||
"a+b",
|
||||
"+ab",
|
||||
"ba+",
|
||||
"b+a",
|
||||
"+ba",
|
||||
"xb+",
|
||||
"x+b",
|
||||
"+xb",
|
||||
"bx+",
|
||||
"b+x",
|
||||
"+bx",
|
||||
]
|
||||
OpenBinaryModeWriting: TypeAlias = Literal["wb", "bw", "ab", "ba", "xb", "bx"]
|
||||
OpenBinaryModeReading: TypeAlias = Literal["rb", "br", "rbU", "rUb", "Urb", "brU", "bUr", "Ubr"]
|
||||
OpenBinaryMode: TypeAlias = OpenBinaryModeUpdating | OpenBinaryModeReading | OpenBinaryModeWriting
|
||||
|
||||
# stable
|
||||
class HasFileno(Protocol):
|
||||
def fileno(self) -> int: ...
|
||||
|
||||
FileDescriptor: TypeAlias = int # stable
|
||||
FileDescriptorLike: TypeAlias = int | HasFileno # stable
|
||||
FileDescriptorOrPath: TypeAlias = int | StrOrBytesPath
|
||||
|
||||
# stable
|
||||
class SupportsRead(Protocol[_T_co]):
|
||||
def read(self, length: int = ..., /) -> _T_co: ...
|
||||
|
||||
# stable
|
||||
class SupportsReadline(Protocol[_T_co]):
|
||||
def readline(self, length: int = ..., /) -> _T_co: ...
|
||||
|
||||
# stable
|
||||
class SupportsNoArgReadline(Protocol[_T_co]):
|
||||
def readline(self) -> _T_co: ...
|
||||
|
||||
# stable
|
||||
class SupportsWrite(Protocol[_T_contra]):
|
||||
def write(self, s: _T_contra, /) -> object: ...
|
||||
|
||||
# stable
|
||||
class SupportsFlush(Protocol):
|
||||
def flush(self) -> object: ...
|
||||
|
||||
# Unfortunately PEP 688 does not allow us to distinguish read-only
|
||||
# from writable buffers. We use these aliases for readability for now.
|
||||
# Perhaps a future extension of the buffer protocol will allow us to
|
||||
# distinguish these cases in the type system.
|
||||
ReadOnlyBuffer: TypeAlias = Buffer # stable
|
||||
# Anything that implements the read-write buffer interface.
|
||||
WriteableBuffer: TypeAlias = Buffer
|
||||
# Same as WriteableBuffer, but also includes read-only buffer types (like bytes).
|
||||
ReadableBuffer: TypeAlias = Buffer # stable
|
||||
|
||||
class SliceableBuffer(Buffer, Protocol):
|
||||
def __getitem__(self, slice: slice, /) -> Sequence[int]: ...
|
||||
|
||||
class IndexableBuffer(Buffer, Protocol):
|
||||
def __getitem__(self, i: int, /) -> int: ...
|
||||
|
||||
class SupportsGetItemBuffer(SliceableBuffer, IndexableBuffer, Protocol):
|
||||
def __contains__(self, x: Any, /) -> bool: ...
|
||||
@overload
|
||||
def __getitem__(self, slice: slice, /) -> Sequence[int]: ...
|
||||
@overload
|
||||
def __getitem__(self, i: int, /) -> int: ...
|
||||
|
||||
class SizedBuffer(Sized, Buffer, Protocol): ...
|
||||
|
||||
# for compatibility with third-party stubs that may use this
|
||||
_BufferWithLen: TypeAlias = SizedBuffer # not stable # noqa: Y047
|
||||
|
||||
ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType]
|
||||
OptExcInfo: TypeAlias = ExcInfo | tuple[None, None, None]
|
||||
|
||||
# stable
|
||||
if sys.version_info >= (3, 10):
|
||||
class NoneType: ...
|
||||
from types import NoneType as NoneType
|
||||
else:
|
||||
class NoneType: ...
|
||||
# Used by type checkers for checks involving None (does not exist at runtime)
|
||||
@final
|
||||
class NoneType:
|
||||
def __bool__(self) -> Literal[False]: ...
|
||||
|
||||
# This is an internal CPython type that is like, but subtly different from, a NamedTuple
|
||||
# Subclasses of this type are found in multiple modules.
|
||||
# In typeshed, `structseq` is only ever used as a mixin in combination with a fixed-length `Tuple`
|
||||
# See discussion at #6546 & #6560
|
||||
# `structseq` classes are unsubclassable, so are all decorated with `@final`.
|
||||
class structseq(Generic[_T_co]):
|
||||
n_fields: Final[int]
|
||||
n_unnamed_fields: Final[int]
|
||||
n_sequence_fields: Final[int]
|
||||
# The first parameter will generally only take an iterable of a specific length.
|
||||
# E.g. `os.uname_result` takes any iterable of length exactly 5.
|
||||
#
|
||||
# The second parameter will accept a dict of any kind without raising an exception,
|
||||
# but only has any meaning if you supply it a dict where the keys are strings.
|
||||
# https://github.com/python/typeshed/pull/6560#discussion_r767149830
|
||||
def __new__(cls, sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> _Self: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
def __replace__(self, **kwargs: Any) -> _Self: ...
|
||||
|
||||
# Superset of typing.AnyStr that also includes LiteralString
|
||||
AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa: Y001
|
||||
|
||||
# Represents when str or LiteralStr is acceptable. Useful for string processing
|
||||
# APIs where literalness of return value depends on literalness of inputs
|
||||
StrOrLiteralStr = TypeVar("StrOrLiteralStr", LiteralString, str) # noqa: Y001
|
||||
|
||||
# Objects suitable to be passed to sys.setprofile, threading.setprofile, and similar
|
||||
ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object]
|
||||
|
||||
# Objects suitable to be passed to sys.settrace, threading.settrace, and similar
|
||||
TraceFunction: TypeAlias = Callable[[FrameType, str, Any], TraceFunction | None]
|
||||
|
||||
# experimental
|
||||
# Might not work as expected for pyright, see
|
||||
# https://github.com/python/typeshed/pull/9362
|
||||
# https://github.com/microsoft/pyright/issues/4339
|
||||
class DataclassInstance(Protocol):
|
||||
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
|
||||
|
||||
# Anything that can be passed to the int/float constructors
|
||||
ConvertibleToInt: TypeAlias = str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc
|
||||
ConvertibleToFloat: TypeAlias = str | ReadableBuffer | SupportsFloat | SupportsIndex
|
||||
|
||||
# A few classes updated from Foo(str, Enum) to Foo(StrEnum). This is a convenience so these
|
||||
# can be accurate on all python versions without getting too wordy
|
||||
if sys.version_info >= (3, 11):
|
||||
from enum import StrEnum as StrEnum
|
||||
else:
|
||||
from enum import Enum
|
||||
|
||||
class StrEnum(str, Enum): ...
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user