Compare commits
384 Commits
0.11.5
...
micha/sals
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90d16987b7 | ||
|
|
a9d3e2e253 | ||
|
|
4f890b2867 | ||
|
|
d566636ca5 | ||
|
|
51cef5a72b | ||
|
|
2cf5cba7ff | ||
|
|
ce0800fccf | ||
|
|
d03a7069ad | ||
|
|
f5096f2050 | ||
|
|
895b6161a6 | ||
|
|
74fe7982ba | ||
|
|
51386b3c7a | ||
|
|
51e2effd2d | ||
|
|
82d31a6014 | ||
|
|
78054824c0 | ||
|
|
c6f4929cdc | ||
|
|
2ec0d7e072 | ||
|
|
ad658f4d68 | ||
|
|
3dedd70a92 | ||
|
|
fab862c8cd | ||
|
|
0d9b6a0975 | ||
|
|
c5e299e796 | ||
|
|
c504001b32 | ||
|
|
04457f99b6 | ||
|
|
a33d0d4bf4 | ||
|
|
443f62e98d | ||
|
|
a2e9a7732a | ||
|
|
b2de749c32 | ||
|
|
9085f18353 | ||
|
|
8152ba7cb7 | ||
|
|
3d01d3be3e | ||
|
|
4510a236d3 | ||
|
|
76b6d53d8b | ||
|
|
f82b72882b | ||
|
|
d07eefc408 | ||
|
|
f7237e3b69 | ||
|
|
2f9992b6ef | ||
|
|
457ec4dddd | ||
|
|
aa0614509b | ||
|
|
9000eb3bfd | ||
|
|
7f50b503cf | ||
|
|
24d3fc27fb | ||
|
|
6f821ac846 | ||
|
|
d410d12bc5 | ||
|
|
89424cce5f | ||
|
|
fd76d70a31 | ||
|
|
a4c8e43c5f | ||
|
|
ada4c4cb1f | ||
|
|
bb6c7cad07 | ||
|
|
47e3aa40b3 | ||
|
|
9a6633da0b | ||
|
|
de78da5ee6 | ||
|
|
20d64b9c85 | ||
|
|
4850c187ea | ||
|
|
3f32446e16 | ||
|
|
784daae497 | ||
|
|
178c882740 | ||
|
|
101e1a5ddd | ||
|
|
965a4dd731 | ||
|
|
5e2c818417 | ||
|
|
90c12f4177 | ||
|
|
6e9fb9af38 | ||
|
|
a507c1b8b3 | ||
|
|
5a91badb8b | ||
|
|
1945bfdb84 | ||
|
|
a95c73d5d0 | ||
|
|
78b4c3ccf1 | ||
|
|
2485afe640 | ||
|
|
b8ed729f59 | ||
|
|
108c470348 | ||
|
|
87c64c9eab | ||
|
|
a10606dda2 | ||
|
|
d1c6dd9ac1 | ||
|
|
073b993ab0 | ||
|
|
6a36cd6f02 | ||
|
|
3b15af6d4f | ||
|
|
e95130ad80 | ||
|
|
68e32c103f | ||
|
|
fe4051b2e6 | ||
|
|
fa628018b2 | ||
|
|
8535af8516 | ||
|
|
b51c4f82ea | ||
|
|
e6a798b962 | ||
|
|
52b0470870 | ||
|
|
c4a08782cc | ||
|
|
91481a8be7 | ||
|
|
097af060c9 | ||
|
|
b7d0b3f9e5 | ||
|
|
084352f72c | ||
|
|
78d4356301 | ||
|
|
96697c98f3 | ||
|
|
f7cae4ffb5 | ||
|
|
675a5af89a | ||
|
|
ea3f4ac059 | ||
|
|
6d2c10cca2 | ||
|
|
3cf44e401a | ||
|
|
17050e2ec5 | ||
|
|
a6dc04f96e | ||
|
|
e515899141 | ||
|
|
0c80c56afc | ||
|
|
b7ce694162 | ||
|
|
163d526407 | ||
|
|
75effb8ed7 | ||
|
|
3353d07938 | ||
|
|
41f3f21629 | ||
|
|
76ec64d535 | ||
|
|
b7e69ecbfc | ||
|
|
9c57862262 | ||
|
|
67ef370733 | ||
|
|
e17e1e860b | ||
|
|
03d8679adf | ||
|
|
d33a503686 | ||
|
|
650cbdd296 | ||
|
|
d2a238dfad | ||
|
|
6e765b4527 | ||
|
|
c5e41c278c | ||
|
|
0eeb02c0c1 | ||
|
|
f31b1c695c | ||
|
|
5679bf00bc | ||
|
|
a7c358ab5c | ||
|
|
b6de01b9a5 | ||
|
|
18bac94226 | ||
|
|
7568eeb7a5 | ||
|
|
0e85cbdd91 | ||
|
|
7825975972 | ||
|
|
f584b66824 | ||
|
|
ad1a8da4d1 | ||
|
|
0861ecfa55 | ||
|
|
d1f359afbb | ||
|
|
b84b58760e | ||
|
|
d94be0e780 | ||
|
|
8a6787b39e | ||
|
|
4a621c2c12 | ||
|
|
2bb99df394 | ||
|
|
f11d9cb509 | ||
|
|
549ab74bd6 | ||
|
|
81fc7d7d3a | ||
|
|
8c68d30c3a | ||
|
|
93d6a3567b | ||
|
|
1d788981cd | ||
|
|
7d46579808 | ||
|
|
c9a6b1a9d0 | ||
|
|
9b9d16c3ba | ||
|
|
79f8473e51 | ||
|
|
ca4fdf452d | ||
|
|
3c460a7b9a | ||
|
|
31e6576971 | ||
|
|
c953e7d143 | ||
|
|
5096824793 | ||
|
|
ae7691b026 | ||
|
|
504fa20057 | ||
|
|
f0868ac0c9 | ||
|
|
01a31c08f5 | ||
|
|
405878a128 | ||
|
|
80103a179d | ||
|
|
9a8f3cf247 | ||
|
|
07718f4788 | ||
|
|
1e8881f9af | ||
|
|
152a0b6585 | ||
|
|
1ad5015e19 | ||
|
|
92f95ff494 | ||
|
|
ceb2bf1168 | ||
|
|
f521358033 | ||
|
|
74081032d9 | ||
|
|
dbc137c951 | ||
|
|
826b2c9ff3 | ||
|
|
a3e55cfd8f | ||
|
|
d2246278e6 | ||
|
|
6bd1863bf0 | ||
|
|
97dc58fc77 | ||
|
|
53a9448fb5 | ||
|
|
516291b693 | ||
|
|
b09f00a4ef | ||
|
|
03065c245c | ||
|
|
b45598389d | ||
|
|
4729ff2bc8 | ||
|
|
1bdb22c139 | ||
|
|
1c65e0ad25 | ||
|
|
4443f6653c | ||
|
|
b0d475f353 | ||
|
|
b578a828ef | ||
|
|
64ba39a385 | ||
|
|
a4e225ee8a | ||
|
|
45d0634b01 | ||
|
|
4bcf1778fa | ||
|
|
6044f04137 | ||
|
|
2e95475f57 | ||
|
|
cfa1505068 | ||
|
|
0251679f87 | ||
|
|
6ab32a7746 | ||
|
|
bc0a5aa409 | ||
|
|
aba21a5d47 | ||
|
|
b6281a8805 | ||
|
|
049280a3bc | ||
|
|
fa88989ef0 | ||
|
|
4c3f389598 | ||
|
|
6d3b1d13d6 | ||
|
|
3f84e75e20 | ||
|
|
afc18ff1a1 | ||
|
|
f1a539dac6 | ||
|
|
ef0343189c | ||
|
|
4eecc40110 | ||
|
|
cf59cee928 | ||
|
|
538393d1f3 | ||
|
|
92ecfc908b | ||
|
|
f7b48510b5 | ||
|
|
9937064761 | ||
|
|
8d2c79276d | ||
|
|
0f47810768 | ||
|
|
eb1d2518c1 | ||
|
|
a45a0a92bd | ||
|
|
43bd043755 | ||
|
|
9a54ee3a1c | ||
|
|
25c3be51d2 | ||
|
|
e71f3ed2c5 | ||
|
|
ac6219ec38 | ||
|
|
e93fa7062c | ||
|
|
21fd28d713 | ||
|
|
a01f25107a | ||
|
|
48a85c4ed4 | ||
|
|
1796ca97d5 | ||
|
|
e897f37911 | ||
|
|
00e73dc331 | ||
|
|
7b6222700b | ||
|
|
bfc1650198 | ||
|
|
d5410ef9fe | ||
|
|
9db63fc58c | ||
|
|
61e73481fe | ||
|
|
e170fe493d | ||
|
|
e91e2f49db | ||
|
|
b537552927 | ||
|
|
5a719f2d60 | ||
|
|
e7f38fe74b | ||
|
|
624f5c6c22 | ||
|
|
8abf93f5fb | ||
|
|
5407249467 | ||
|
|
0a1f9d090e | ||
|
|
f9c7908bb7 | ||
|
|
99fa850e53 | ||
|
|
a241321735 | ||
|
|
b1b8ca3bcd | ||
|
|
3fae176345 | ||
|
|
f36262d970 | ||
|
|
e45f23b0ec | ||
|
|
aa46047649 | ||
|
|
f9da115fdc | ||
|
|
3872d57463 | ||
|
|
27ada26ddb | ||
|
|
810478f68b | ||
|
|
17f799424a | ||
|
|
c12640fea8 | ||
|
|
3796b13ea2 | ||
|
|
ad5a659f29 | ||
|
|
27a377f077 | ||
|
|
b8b624d890 | ||
|
|
6dc2d29966 | ||
|
|
890ba725d9 | ||
|
|
298f43f34e | ||
|
|
3b300559ab | ||
|
|
14f71ceb83 | ||
|
|
4775719abf | ||
|
|
6bdffc3cbf | ||
|
|
775815ef22 | ||
|
|
0299a52fb1 | ||
|
|
83d5ad8983 | ||
|
|
ae6fde152c | ||
|
|
d2b20f7367 | ||
|
|
38a3b056e3 | ||
|
|
37a0836bd2 | ||
|
|
f83295fe51 | ||
|
|
c4581788b2 | ||
|
|
2894aaa943 | ||
|
|
ed4866a00b | ||
|
|
9b5fe51b32 | ||
|
|
53ffe7143f | ||
|
|
21561000b1 | ||
|
|
9c0772d8f0 | ||
|
|
a4531bf865 | ||
|
|
be54b840e9 | ||
|
|
45b5dedee2 | ||
|
|
9ff4772a2c | ||
|
|
c077b109ce | ||
|
|
8a2dd01db4 | ||
|
|
f888e51a34 | ||
|
|
d11e959ad5 | ||
|
|
a56eef444a | ||
|
|
14ff67fd46 | ||
|
|
ada7d4da0d | ||
|
|
4cafb44ba7 | ||
|
|
1445836872 | ||
|
|
da6b68cb58 | ||
|
|
2a478ce1b2 | ||
|
|
8fe2dd5e03 | ||
|
|
454ad15aee | ||
|
|
fd3fc34a9e | ||
|
|
c550b4d565 | ||
|
|
f8061e8b99 | ||
|
|
27a315b740 | ||
|
|
08221454f6 | ||
|
|
5fec1039ed | ||
|
|
787bcd1c6a | ||
|
|
5853eb28dd | ||
|
|
84d064a14c | ||
|
|
e4e405d2a1 | ||
|
|
1918c61623 | ||
|
|
44ad201262 | ||
|
|
c7372d218d | ||
|
|
de8f4e62e2 | ||
|
|
edfa03a692 | ||
|
|
9965cee998 | ||
|
|
58807b2980 | ||
|
|
9c47b6dbb0 | ||
|
|
d2ebfd6ed7 | ||
|
|
c36f3f5304 | ||
|
|
fcd50a0496 | ||
|
|
3ada36b766 | ||
|
|
bd89838212 | ||
|
|
b32407b6f3 | ||
|
|
b4de245a5a | ||
|
|
914095d08f | ||
|
|
5350288d07 | ||
|
|
649610cc98 | ||
|
|
1a79722ee0 | ||
|
|
b67590bfde | ||
|
|
e6a2de3ac6 | ||
|
|
c7b5067ef8 | ||
|
|
5a115e750d | ||
|
|
a1f361949e | ||
|
|
13ea4e5d0e | ||
|
|
a2a7b1e268 | ||
|
|
1dedcb9e0d | ||
|
|
807a8a7a29 | ||
|
|
78dabc332d | ||
|
|
bfc17fecaa | ||
|
|
942cb9e3ad | ||
|
|
312a487ea7 | ||
|
|
cf8dc60292 | ||
|
|
ea5d5c4e29 | ||
|
|
c99d5522eb | ||
|
|
e57c83e369 | ||
|
|
1d49e71ddd | ||
|
|
f05b2d3673 | ||
|
|
79b921179c | ||
|
|
1f85e0d0a0 | ||
|
|
03adae80dc | ||
|
|
4894f52bae | ||
|
|
3b24fe5c07 | ||
|
|
b5d529e976 | ||
|
|
014bb526f4 | ||
|
|
e2a38e4c00 | ||
|
|
9bee9429de | ||
|
|
17e5b61c54 | ||
|
|
701aecb2a6 | ||
|
|
850360a0b4 | ||
|
|
dfd8eaeb32 | ||
|
|
3aa3ee8b89 | ||
|
|
f0c3abd198 | ||
|
|
e5026c0877 | ||
|
|
da32a83c9f | ||
|
|
4bfdf54d1a | ||
|
|
7d11ef1564 | ||
|
|
b79d43a852 | ||
|
|
a4d3c4bf8b | ||
|
|
f3cc287a40 | ||
|
|
bd5b8a9ec6 | ||
|
|
0caf09f5c3 | ||
|
|
47956db567 | ||
|
|
ffef71d106 | ||
|
|
7e571791c0 | ||
|
|
8e11c53310 | ||
|
|
1aad180aae | ||
|
|
1a3b73720c | ||
|
|
8b2727cf67 | ||
|
|
410aa4b8fd | ||
|
|
bd58135b0d | ||
|
|
81045758d3 | ||
|
|
0b2a5b5cd3 | ||
|
|
7d958a9ee5 | ||
|
|
7e2eb591bc | ||
|
|
ba408f4231 | ||
|
|
28b64064f5 | ||
|
|
75b15ea2d0 | ||
|
|
e7e86b8584 | ||
|
|
f84bc07d56 |
6
.gitattributes
vendored
6
.gitattributes
vendored
@@ -12,6 +12,12 @@ crates/ruff_python_parser/resources/invalid/re_lexing/line_continuation_windows_
|
||||
crates/ruff_python_parser/resources/invalid/re_lex_logical_token_windows_eol.py text eol=crlf
|
||||
crates/ruff_python_parser/resources/invalid/re_lex_logical_token_mac_eol.py text eol=cr
|
||||
|
||||
crates/ruff_linter/resources/test/fixtures/ruff/RUF046_CR.py text eol=cr
|
||||
crates/ruff_linter/resources/test/fixtures/ruff/RUF046_LF.py text eol=lf
|
||||
|
||||
crates/ruff_linter/resources/test/fixtures/pyupgrade/UP018_CR.py text eol=cr
|
||||
crates/ruff_linter/resources/test/fixtures/pyupgrade/UP018_LF.py text eol=lf
|
||||
|
||||
crates/ruff_python_parser/resources/inline linguist-generated=true
|
||||
|
||||
ruff.schema.json -diff linguist-generated=true text=auto eol=lf
|
||||
|
||||
10
.github/CODEOWNERS
vendored
10
.github/CODEOWNERS
vendored
@@ -14,11 +14,11 @@
|
||||
# flake8-pyi
|
||||
/crates/ruff_linter/src/rules/flake8_pyi/ @AlexWaygood
|
||||
|
||||
# Script for fuzzing the parser/red-knot etc.
|
||||
# Script for fuzzing the parser/ty etc.
|
||||
/python/py-fuzzer/ @AlexWaygood
|
||||
|
||||
# red-knot
|
||||
/crates/red_knot* @carljm @MichaReiser @AlexWaygood @sharkdp @dcreager
|
||||
# ty
|
||||
/crates/ty* @carljm @MichaReiser @AlexWaygood @sharkdp @dcreager
|
||||
/crates/ruff_db/ @carljm @MichaReiser @AlexWaygood @sharkdp @dcreager
|
||||
/scripts/knot_benchmark/ @carljm @MichaReiser @AlexWaygood @sharkdp @dcreager
|
||||
/crates/red_knot_python_semantic @carljm @AlexWaygood @sharkdp @dcreager
|
||||
/scripts/ty_benchmark/ @carljm @MichaReiser @AlexWaygood @sharkdp @dcreager
|
||||
/crates/ty_python_semantic @carljm @AlexWaygood @sharkdp @dcreager
|
||||
|
||||
3
.github/ISSUE_TEMPLATE/config.yml
vendored
3
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +1,8 @@
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: Report an issue with ty
|
||||
url: https://github.com/astral-sh/ty/issues/new/choose
|
||||
about: Please report issues for our type checker ty in the ty repository.
|
||||
- name: Documentation
|
||||
url: https://docs.astral.sh/ruff
|
||||
about: Please consult the documentation before creating an issue.
|
||||
|
||||
1
.github/actionlint.yaml
vendored
1
.github/actionlint.yaml
vendored
@@ -6,5 +6,6 @@ self-hosted-runner:
|
||||
labels:
|
||||
- depot-ubuntu-latest-8
|
||||
- depot-ubuntu-22.04-16
|
||||
- depot-ubuntu-22.04-32
|
||||
- github-windows-2025-x86_64-8
|
||||
- github-windows-2025-x86_64-16
|
||||
|
||||
34
.github/workflows/build-binaries.yml
vendored
34
.github/workflows/build-binaries.yml
vendored
@@ -43,13 +43,13 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build sdist"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
command: sdist
|
||||
args: --out dist
|
||||
@@ -72,14 +72,14 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
architecture: x64
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build wheels - x86_64"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
target: x86_64
|
||||
args: --release --locked --out dist
|
||||
@@ -114,14 +114,14 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
architecture: arm64
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build wheels - aarch64"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
target: aarch64
|
||||
args: --release --locked --out dist
|
||||
@@ -170,14 +170,14 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
architecture: ${{ matrix.platform.arch }}
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build wheels"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
target: ${{ matrix.platform.target }}
|
||||
args: --release --locked --out dist
|
||||
@@ -223,14 +223,14 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
architecture: x64
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build wheels"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
target: ${{ matrix.target }}
|
||||
manylinux: auto
|
||||
@@ -298,13 +298,13 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build wheels"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
target: ${{ matrix.platform.target }}
|
||||
manylinux: auto
|
||||
@@ -363,21 +363,21 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
architecture: x64
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build wheels"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
target: ${{ matrix.target }}
|
||||
manylinux: musllinux_1_2
|
||||
args: --release --locked --out dist
|
||||
- name: "Test wheel"
|
||||
if: matrix.target == 'x86_64-unknown-linux-musl'
|
||||
uses: addnab/docker-run-action@v3
|
||||
uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 # v3
|
||||
with:
|
||||
image: alpine:latest
|
||||
options: -v ${{ github.workspace }}:/io -w /io
|
||||
@@ -429,13 +429,13 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build wheels"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
target: ${{ matrix.platform.target }}
|
||||
manylinux: musllinux_1_2
|
||||
|
||||
8
.github/workflows/build-docker.yml
vendored
8
.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@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6
|
||||
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6
|
||||
with:
|
||||
context: .
|
||||
platforms: ${{ matrix.platform }}
|
||||
@@ -113,7 +113,7 @@ jobs:
|
||||
if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}
|
||||
steps:
|
||||
- name: Download digests
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
with:
|
||||
path: /tmp/digests
|
||||
pattern: digests-*
|
||||
@@ -231,7 +231,7 @@ jobs:
|
||||
${{ env.TAG_PATTERNS }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6
|
||||
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
@@ -256,7 +256,7 @@ jobs:
|
||||
if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}
|
||||
steps:
|
||||
- name: Download digests
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
with:
|
||||
path: /tmp/digests
|
||||
pattern: digests-*
|
||||
|
||||
133
.github/workflows/ci.yaml
vendored
133
.github/workflows/ci.yaml
vendored
@@ -36,8 +36,8 @@ jobs:
|
||||
code: ${{ steps.check_code.outputs.changed }}
|
||||
# Flag that is raised when any code that affects the fuzzer is changed
|
||||
fuzz: ${{ steps.check_fuzzer.outputs.changed }}
|
||||
# Flag that is set to "true" when code related to red-knot changes.
|
||||
red_knot: ${{ steps.check_red_knot.outputs.changed }}
|
||||
# Flag that is set to "true" when code related to ty changes.
|
||||
ty: ${{ steps.check_ty.outputs.changed }}
|
||||
|
||||
# Flag that is set to "true" when code related to the playground changes.
|
||||
playground: ${{ steps.check_playground.outputs.changed }}
|
||||
@@ -84,7 +84,7 @@ jobs:
|
||||
if git diff --quiet "${MERGE_BASE}...HEAD" -- ':Cargo.toml' \
|
||||
':Cargo.lock' \
|
||||
':crates/**' \
|
||||
':!crates/red_knot*/**' \
|
||||
':!crates/ty*/**' \
|
||||
':!crates/ruff_python_formatter/**' \
|
||||
':!crates/ruff_formatter/**' \
|
||||
':!crates/ruff_dev/**' \
|
||||
@@ -145,7 +145,7 @@ jobs:
|
||||
run: |
|
||||
if git diff --quiet "${MERGE_BASE}...HEAD" -- ':**' \
|
||||
':!**/*.md' \
|
||||
':crates/red_knot_python_semantic/resources/mdtest/**/*.md' \
|
||||
':crates/ty_python_semantic/resources/mdtest/**/*.md' \
|
||||
':!docs/**' \
|
||||
':!assets/**' \
|
||||
':.github/workflows/ci.yaml' \
|
||||
@@ -168,15 +168,15 @@ jobs:
|
||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Check if the red-knot code changed
|
||||
id: check_red_knot
|
||||
- name: Check if the ty code changed
|
||||
id: check_ty
|
||||
env:
|
||||
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
|
||||
run: |
|
||||
if git diff --quiet "${MERGE_BASE}...HEAD" -- \
|
||||
':Cargo.toml' \
|
||||
':Cargo.lock' \
|
||||
':crates/red_knot*/**' \
|
||||
':crates/ty*/**' \
|
||||
':crates/ruff_db/**' \
|
||||
':crates/ruff_annotate_snippets/**' \
|
||||
':crates/ruff_python_ast/**' \
|
||||
@@ -221,7 +221,7 @@ jobs:
|
||||
- name: "Clippy"
|
||||
run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
|
||||
- name: "Clippy (wasm)"
|
||||
run: cargo clippy -p ruff_wasm -p red_knot_wasm --target wasm32-unknown-unknown --all-features --locked -- -D warnings
|
||||
run: cargo clippy -p ruff_wasm -p ty_wasm --target wasm32-unknown-unknown --all-features --locked -- -D warnings
|
||||
|
||||
cargo-test-linux:
|
||||
name: "cargo test (linux)"
|
||||
@@ -237,23 +237,23 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@v1
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc # v2
|
||||
uses: taiki-e/install-action@86c23eed46c17b80677df6d8151545ce3e236c61 # v2
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Install cargo insta"
|
||||
uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc # v2
|
||||
uses: taiki-e/install-action@86c23eed46c17b80677df6d8151545ce3e236c61 # v2
|
||||
with:
|
||||
tool: cargo-insta
|
||||
- name: Red-knot mdtests (GitHub annotations)
|
||||
if: ${{ needs.determine_changes.outputs.red_knot == 'true' }}
|
||||
- name: ty mdtests (GitHub annotations)
|
||||
if: ${{ needs.determine_changes.outputs.ty == 'true' }}
|
||||
env:
|
||||
NO_COLOR: 1
|
||||
MDTEST_GITHUB_ANNOTATIONS_FORMAT: 1
|
||||
# Ignore errors if this step fails; we want to continue to later steps in the workflow anyway.
|
||||
# This step is just to get nice GitHub annotations on the PR diff in the files-changed tab.
|
||||
run: cargo test -p red_knot_python_semantic --test mdtest || true
|
||||
run: cargo test -p ty_python_semantic --test mdtest || true
|
||||
- name: "Run tests"
|
||||
shell: bash
|
||||
env:
|
||||
@@ -268,7 +268,7 @@ jobs:
|
||||
# sync, not just public items. Eventually we should do this for all
|
||||
# crates; for now add crates here as they are warning-clean to prevent
|
||||
# regression.
|
||||
- run: cargo doc --no-deps -p red_knot_python_semantic -p red_knot -p red_knot_test -p ruff_db --document-private-items
|
||||
- run: cargo doc --no-deps -p ty_python_semantic -p ty -p ty_test -p ruff_db --document-private-items
|
||||
env:
|
||||
# Setting RUSTDOCFLAGS because `cargo doc --check` isn't yet implemented (https://github.com/rust-lang/cargo/issues/10025).
|
||||
RUSTDOCFLAGS: "-D warnings"
|
||||
@@ -276,6 +276,10 @@ jobs:
|
||||
with:
|
||||
name: ruff
|
||||
path: target/debug/ruff
|
||||
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: ty
|
||||
path: target/debug/ty
|
||||
|
||||
cargo-test-linux-release:
|
||||
name: "cargo test (linux, release)"
|
||||
@@ -291,13 +295,13 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@v1
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc # v2
|
||||
uses: taiki-e/install-action@86c23eed46c17b80677df6d8151545ce3e236c61 # v2
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Install cargo insta"
|
||||
uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc # v2
|
||||
uses: taiki-e/install-action@86c23eed46c17b80677df6d8151545ce3e236c61 # v2
|
||||
with:
|
||||
tool: cargo-insta
|
||||
- name: "Run tests"
|
||||
@@ -320,7 +324,7 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc # v2
|
||||
uses: taiki-e/install-action@86c23eed46c17b80677df6d8151545ce3e236c61 # v2
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Run tests"
|
||||
@@ -346,7 +350,7 @@ jobs:
|
||||
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup target add wasm32-unknown-unknown
|
||||
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
|
||||
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: 20
|
||||
cache: "npm"
|
||||
@@ -358,9 +362,9 @@ jobs:
|
||||
run: |
|
||||
cd crates/ruff_wasm
|
||||
wasm-pack test --node
|
||||
- name: "Test red_knot_wasm"
|
||||
- name: "Test ty_wasm"
|
||||
run: |
|
||||
cd crates/red_knot_wasm
|
||||
cd crates/ty_wasm
|
||||
wasm-pack test --node
|
||||
|
||||
cargo-build-release:
|
||||
@@ -376,7 +380,7 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@v1
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- name: "Build"
|
||||
run: cargo build --release --locked
|
||||
|
||||
@@ -401,13 +405,13 @@ jobs:
|
||||
MSRV: ${{ steps.msrv.outputs.value }}
|
||||
run: rustup default "${MSRV}"
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@v1
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc # v2
|
||||
uses: taiki-e/install-action@86c23eed46c17b80677df6d8151545ce3e236c61 # v2
|
||||
with:
|
||||
tool: cargo-nextest
|
||||
- name: "Install cargo insta"
|
||||
uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc # v2
|
||||
uses: taiki-e/install-action@86c23eed46c17b80677df6d8151545ce3e236c61 # v2
|
||||
with:
|
||||
tool: cargo-insta
|
||||
- name: "Run tests"
|
||||
@@ -433,7 +437,7 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install cargo-binstall"
|
||||
uses: cargo-bins/cargo-binstall@main
|
||||
uses: cargo-bins/cargo-binstall@63aaa5c1932cebabc34eceda9d92a70215dcead6 # v1.12.3
|
||||
with:
|
||||
tool: cargo-fuzz@0.11.2
|
||||
- name: "Install cargo-fuzz"
|
||||
@@ -455,8 +459,8 @@ jobs:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
|
||||
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
|
||||
- uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
||||
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
name: Download Ruff binary to test
|
||||
id: download-cached-binary
|
||||
with:
|
||||
@@ -521,11 +525,11 @@ jobs:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
|
||||
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
|
||||
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
name: Download comparison Ruff binary
|
||||
id: ruff-target
|
||||
with:
|
||||
@@ -632,6 +636,53 @@ jobs:
|
||||
name: ecosystem-result
|
||||
path: ecosystem-result
|
||||
|
||||
fuzz-ty:
|
||||
name: "Fuzz for new ty panics"
|
||||
runs-on: depot-ubuntu-22.04-16
|
||||
needs:
|
||||
- cargo-test-linux
|
||||
- determine_changes
|
||||
# Only runs on pull requests, since that is the only we way we can find the base version for comparison.
|
||||
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-test') && github.event_name == 'pull_request' && needs.determine_changes.outputs.ty == 'true' }}
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
name: Download new ty binary
|
||||
id: ty-new
|
||||
with:
|
||||
name: ty
|
||||
path: target/debug
|
||||
- uses: dawidd6/action-download-artifact@20319c5641d495c8a52e688b7dc5fada6c3a9fbc # v8
|
||||
name: Download baseline ty binary
|
||||
with:
|
||||
name: ty
|
||||
branch: ${{ github.event.pull_request.base.ref }}
|
||||
workflow: "ci.yaml"
|
||||
check_artifacts: true
|
||||
- uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
||||
- name: Fuzz
|
||||
env:
|
||||
FORCE_COLOR: 1
|
||||
NEW_TY: ${{ steps.ty-new.outputs.download-path }}
|
||||
run: |
|
||||
# Make executable, since artifact download doesn't preserve this
|
||||
chmod +x "${PWD}/ty" "${NEW_TY}/ty"
|
||||
|
||||
(
|
||||
uvx \
|
||||
--python="${PYTHON_VERSION}" \
|
||||
--from=./python/py-fuzzer \
|
||||
fuzz \
|
||||
--test-executable="${NEW_TY}/ty" \
|
||||
--baseline-executable="${PWD}/ty" \
|
||||
--only-new-bugs \
|
||||
--bin=ty \
|
||||
0-500
|
||||
)
|
||||
|
||||
cargo-shear:
|
||||
name: "cargo shear"
|
||||
runs-on: ubuntu-latest
|
||||
@@ -641,7 +692,7 @@ jobs:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: cargo-bins/cargo-binstall@main
|
||||
- uses: cargo-bins/cargo-binstall@63aaa5c1932cebabc34eceda9d92a70215dcead6 # v1.12.3
|
||||
- run: cargo binstall --no-confirm cargo-shear
|
||||
- run: cargo shear
|
||||
|
||||
@@ -654,7 +705,7 @@ jobs:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
architecture: x64
|
||||
@@ -662,7 +713,7 @@ jobs:
|
||||
- name: "Prep README.md"
|
||||
run: python scripts/transform_readme.py --target pypi
|
||||
- name: "Build wheels"
|
||||
uses: PyO3/maturin-action@44479ae1b6b1a57f561e03add8832e62c185eb17 # v1.48.1
|
||||
uses: PyO3/maturin-action@aef21716ff3dcae8a1c301d23ec3e4446972a6e3 # v1.49.1
|
||||
with:
|
||||
args: --out dist
|
||||
- name: "Test wheel"
|
||||
@@ -681,7 +732,7 @@ jobs:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
|
||||
- uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
||||
- name: "Cache pre-commit"
|
||||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
|
||||
with:
|
||||
@@ -708,7 +759,7 @@ jobs:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: "3.13"
|
||||
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
@@ -720,7 +771,7 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
|
||||
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
||||
- name: "Install Insiders dependencies"
|
||||
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
|
||||
run: uv pip install -r docs/requirements-insiders.txt --system
|
||||
@@ -779,12 +830,12 @@ jobs:
|
||||
persist-credentials: false
|
||||
repository: "astral-sh/ruff-lsp"
|
||||
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
# installation fails on 3.13 and newer
|
||||
python-version: "3.12"
|
||||
|
||||
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
|
||||
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
name: Download development ruff binary
|
||||
id: ruff-target
|
||||
with:
|
||||
@@ -821,7 +872,7 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup target add wasm32-unknown-unknown
|
||||
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
|
||||
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: 22
|
||||
cache: "npm"
|
||||
@@ -857,7 +908,7 @@ jobs:
|
||||
run: rustup show
|
||||
|
||||
- name: "Install codspeed"
|
||||
uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc # v2
|
||||
uses: taiki-e/install-action@86c23eed46c17b80677df6d8151545ce3e236c61 # v2
|
||||
with:
|
||||
tool: cargo-codspeed
|
||||
|
||||
|
||||
4
.github/workflows/daily_fuzz.yaml
vendored
4
.github/workflows/daily_fuzz.yaml
vendored
@@ -34,11 +34,11 @@ jobs:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
|
||||
- uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@v1
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
- name: Build ruff
|
||||
# A debug build means the script runs slower once it gets started,
|
||||
|
||||
12
.github/workflows/daily_property_tests.yaml
vendored
12
.github/workflows/daily_property_tests.yaml
vendored
@@ -36,19 +36,19 @@ jobs:
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
- name: "Install mold"
|
||||
uses: rui314/setup-mold@v1
|
||||
uses: rui314/setup-mold@e16410e7f8d9e167b74ad5697a9089a35126eb50 # v1
|
||||
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
- name: Build Red Knot
|
||||
- name: Build ty
|
||||
# A release build takes longer (2 min vs 1 min), but the property tests run much faster in release
|
||||
# mode (1.5 min vs 14 min), so the overall time is shorter with a release build.
|
||||
run: cargo build --locked --release --package red_knot_python_semantic --tests
|
||||
run: cargo build --locked --release --package ty_python_semantic --tests
|
||||
- name: Run property tests
|
||||
shell: bash
|
||||
run: |
|
||||
export QUICKCHECK_TESTS=100000
|
||||
for _ in {1..5}; do
|
||||
cargo test --locked --release --package red_knot_python_semantic -- --ignored list::property_tests
|
||||
cargo test --locked --release --package red_knot_python_semantic -- --ignored types::property_tests::stable
|
||||
cargo test --locked --release --package ty_python_semantic -- --ignored list::property_tests
|
||||
cargo test --locked --release --package ty_python_semantic -- --ignored types::property_tests::stable
|
||||
done
|
||||
|
||||
create-issue-on-failure:
|
||||
@@ -68,5 +68,5 @@ jobs:
|
||||
repo: "ruff",
|
||||
title: `Daily property test run failed on ${new Date().toDateString()}`,
|
||||
body: "Run listed here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
|
||||
labels: ["bug", "red-knot", "testing"],
|
||||
labels: ["bug", "ty", "testing"],
|
||||
})
|
||||
|
||||
23
.github/workflows/mypy_primer.yaml
vendored
23
.github/workflows/mypy_primer.yaml
vendored
@@ -5,7 +5,7 @@ permissions: {}
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "crates/red_knot*/**"
|
||||
- "crates/ty*/**"
|
||||
- "crates/ruff_db"
|
||||
- "crates/ruff_python_ast"
|
||||
- "crates/ruff_python_parser"
|
||||
@@ -21,11 +21,12 @@ env:
|
||||
CARGO_NET_RETRY: 10
|
||||
CARGO_TERM_COLOR: always
|
||||
RUSTUP_MAX_RETRIES: 10
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
jobs:
|
||||
mypy_primer:
|
||||
name: Run mypy_primer
|
||||
runs-on: depot-ubuntu-22.04-16
|
||||
runs-on: depot-ubuntu-22.04-32
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
@@ -35,23 +36,22 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
|
||||
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
||||
|
||||
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
with:
|
||||
workspaces: "ruff"
|
||||
|
||||
- name: Install Rust toolchain
|
||||
run: rustup show
|
||||
|
||||
- name: Install mypy_primer
|
||||
run: |
|
||||
uv tool install "git+https://github.com/astral-sh/mypy_primer.git@add-red-knot-support-v4"
|
||||
|
||||
- name: Run mypy_primer
|
||||
shell: bash
|
||||
run: |
|
||||
cd ruff
|
||||
|
||||
PRIMER_SELECTOR="$(paste -s -d'|' crates/ty_python_semantic/resources/primer/good.txt)"
|
||||
|
||||
echo "new commit"
|
||||
git rev-list --format=%s --max-count=1 "$GITHUB_SHA"
|
||||
|
||||
@@ -62,13 +62,16 @@ jobs:
|
||||
|
||||
cd ..
|
||||
|
||||
echo "Project selector: $PRIMER_SELECTOR"
|
||||
# Allow the exit code to be 0 or 1, only fail for actual mypy_primer crashes/bugs
|
||||
uvx mypy_primer \
|
||||
uvx \
|
||||
--from="git+https://github.com/hauntsaninja/mypy_primer@4b15cf3b07db69db67bbfaebfffb2a8a28040933" \
|
||||
mypy_primer \
|
||||
--repo ruff \
|
||||
--type-checker knot \
|
||||
--type-checker ty \
|
||||
--old base_commit \
|
||||
--new "$GITHUB_SHA" \
|
||||
--project-selector '/(mypy_primer|black|pyp|git-revise|zipp|arrow|isort|itsdangerous|rich|packaging|pybind11|pyinstrument|typeshed-stats|scrapy|werkzeug|bidict|async-utils)$' \
|
||||
--project-selector "/($PRIMER_SELECTOR)\$" \
|
||||
--output concise \
|
||||
--debug > mypy_primer.diff || [ $? -eq 1 ]
|
||||
|
||||
|
||||
2
.github/workflows/publish-docs.yml
vendored
2
.github/workflows/publish-docs.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
||||
ref: ${{ inputs.ref }}
|
||||
persist-credentials: true
|
||||
|
||||
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
with:
|
||||
python-version: 3.12
|
||||
|
||||
|
||||
2
.github/workflows/publish-playground.yml
vendored
2
.github/workflows/publish-playground.yml
vendored
@@ -29,7 +29,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup target add wasm32-unknown-unknown
|
||||
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
|
||||
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: 22
|
||||
cache: "npm"
|
||||
|
||||
4
.github/workflows/publish-pypi.yml
vendored
4
.github/workflows/publish-pypi.yml
vendored
@@ -22,8 +22,8 @@ jobs:
|
||||
id-token: write
|
||||
steps:
|
||||
- name: "Install uv"
|
||||
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
|
||||
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
|
||||
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
||||
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
with:
|
||||
pattern: wheels-*
|
||||
path: wheels
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Publish the Red Knot playground.
|
||||
name: "[Knot Playground] Release"
|
||||
# Publish the ty playground.
|
||||
name: "[ty Playground] Release"
|
||||
|
||||
permissions: {}
|
||||
|
||||
@@ -7,12 +7,12 @@ on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "crates/red_knot*/**"
|
||||
- "crates/ty*/**"
|
||||
- "crates/ruff_db/**"
|
||||
- "crates/ruff_python_ast/**"
|
||||
- "crates/ruff_python_parser/**"
|
||||
- "playground/**"
|
||||
- ".github/workflows/publish-knot-playground.yml"
|
||||
- ".github/workflows/publish-ty-playground.yml"
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref_name }}
|
||||
@@ -35,7 +35,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: "Install Rust toolchain"
|
||||
run: rustup target add wasm32-unknown-unknown
|
||||
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
|
||||
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: 22
|
||||
- uses: jetli/wasm-bindgen-action@20b33e20595891ab1a0ed73145d8a21fc96e7c29 # v0.2.0
|
||||
@@ -45,8 +45,8 @@ jobs:
|
||||
- name: "Run TypeScript checks"
|
||||
run: npm run check
|
||||
working-directory: playground
|
||||
- name: "Build Knot playground"
|
||||
run: npm run build --workspace knot-playground
|
||||
- name: "Build ty playground"
|
||||
run: npm run build --workspace ty-playground
|
||||
working-directory: playground
|
||||
- name: "Deploy to Cloudflare Pages"
|
||||
if: ${{ env.CF_API_TOKEN_EXISTS == 'true' }}
|
||||
@@ -55,4 +55,4 @@ jobs:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
# `github.head_ref` is only set during pull requests and for manual runs or tags we use `main` to deploy to production
|
||||
command: pages deploy playground/knot/dist --project-name=knot-playground --branch ${{ github.head_ref || 'main' }} --commit-hash ${GITHUB_SHA}
|
||||
command: pages deploy playground/ty/dist --project-name=ty-playground --branch ${{ github.head_ref || 'main' }} --commit-hash ${GITHUB_SHA}
|
||||
2
.github/workflows/publish-wasm.yml
vendored
2
.github/workflows/publish-wasm.yml
vendored
@@ -45,7 +45,7 @@ jobs:
|
||||
jq '.name="@astral-sh/ruff-wasm-${{ matrix.target }}"' crates/ruff_wasm/pkg/package.json > /tmp/package.json
|
||||
mv /tmp/package.json crates/ruff_wasm/pkg
|
||||
- run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg
|
||||
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
|
||||
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: 20
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
|
||||
29
.github/workflows/release.yml
vendored
29
.github/workflows/release.yml
vendored
@@ -40,6 +40,7 @@ permissions:
|
||||
# If there's a prerelease-style suffix to the version, then the release(s)
|
||||
# will be marked as a prerelease.
|
||||
on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
@@ -60,7 +61,7 @@ jobs:
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||
- uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
@@ -68,9 +69,9 @@ jobs:
|
||||
# we specify bash to get pipefail; it guards against the `curl` command
|
||||
# failing. otherwise `sh` won't catch that `curl` returned non-0
|
||||
shell: bash
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/cargo-dist/releases/download/v0.28.4-prerelease.1/cargo-dist-installer.sh | sh"
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/cargo-dist/releases/download/v0.28.5-prerelease.1/cargo-dist-installer.sh | sh"
|
||||
- name: Cache dist
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
with:
|
||||
name: cargo-dist-cache
|
||||
path: ~/.cargo/bin/dist
|
||||
@@ -86,7 +87,7 @@ jobs:
|
||||
cat plan-dist-manifest.json
|
||||
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
|
||||
- name: "Upload dist-manifest.json"
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
with:
|
||||
name: artifacts-plan-dist-manifest
|
||||
path: plan-dist-manifest.json
|
||||
@@ -123,19 +124,19 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||
- uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
- name: Install cached dist
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
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@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
with:
|
||||
pattern: artifacts-*
|
||||
path: target/distrib/
|
||||
@@ -153,7 +154,7 @@ jobs:
|
||||
|
||||
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
|
||||
- name: "Upload artifacts"
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
with:
|
||||
name: artifacts-build-global
|
||||
path: |
|
||||
@@ -174,19 +175,19 @@ jobs:
|
||||
outputs:
|
||||
val: ${{ steps.host.outputs.manifest }}
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||
- uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
- name: Install cached dist
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
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@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
with:
|
||||
pattern: artifacts-*
|
||||
path: target/distrib/
|
||||
@@ -200,7 +201,7 @@ jobs:
|
||||
cat dist-manifest.json
|
||||
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
|
||||
- name: "Upload dist-manifest.json"
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
with:
|
||||
# Overwrite the previous copy
|
||||
name: artifacts-dist-manifest
|
||||
@@ -250,13 +251,13 @@ jobs:
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||
- uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
# Create a GitHub Release while uploading all files to it
|
||||
- name: "Download GitHub Artifacts"
|
||||
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
|
||||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
|
||||
with:
|
||||
pattern: artifacts-*
|
||||
path: artifacts
|
||||
|
||||
16
.github/workflows/sync_typeshed.yaml
vendored
16
.github/workflows/sync_typeshed.yaml
vendored
@@ -39,13 +39,13 @@ jobs:
|
||||
- name: Sync typeshed
|
||||
id: sync
|
||||
run: |
|
||||
rm -rf ruff/crates/red_knot_vendored/vendor/typeshed
|
||||
mkdir ruff/crates/red_knot_vendored/vendor/typeshed
|
||||
cp typeshed/README.md ruff/crates/red_knot_vendored/vendor/typeshed
|
||||
cp typeshed/LICENSE ruff/crates/red_knot_vendored/vendor/typeshed
|
||||
cp -r typeshed/stdlib ruff/crates/red_knot_vendored/vendor/typeshed/stdlib
|
||||
rm -rf ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/@tests
|
||||
git -C typeshed rev-parse HEAD > ruff/crates/red_knot_vendored/vendor/typeshed/source_commit.txt
|
||||
rm -rf ruff/crates/ty_vendored/vendor/typeshed
|
||||
mkdir ruff/crates/ty_vendored/vendor/typeshed
|
||||
cp typeshed/README.md ruff/crates/ty_vendored/vendor/typeshed
|
||||
cp typeshed/LICENSE ruff/crates/ty_vendored/vendor/typeshed
|
||||
cp -r typeshed/stdlib ruff/crates/ty_vendored/vendor/typeshed/stdlib
|
||||
rm -rf ruff/crates/ty_vendored/vendor/typeshed/stdlib/@tests
|
||||
git -C typeshed rev-parse HEAD > ruff/crates/ty_vendored/vendor/typeshed/source_commit.txt
|
||||
- name: Commit the changes
|
||||
id: commit
|
||||
if: ${{ steps.sync.outcome == 'success' }}
|
||||
@@ -79,5 +79,5 @@ jobs:
|
||||
repo: "ruff",
|
||||
title: `Automated typeshed sync failed on ${new Date().toDateString()}`,
|
||||
body: "Run listed here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
|
||||
labels: ["bug", "red-knot"],
|
||||
labels: ["bug", "ty"],
|
||||
})
|
||||
|
||||
@@ -3,8 +3,8 @@ fail_fast: false
|
||||
exclude: |
|
||||
(?x)^(
|
||||
.github/workflows/release.yml|
|
||||
crates/red_knot_vendored/vendor/.*|
|
||||
crates/red_knot_project/resources/.*|
|
||||
crates/ty_vendored/vendor/.*|
|
||||
crates/ty_project/resources/.*|
|
||||
crates/ruff_benchmark/resources/.*|
|
||||
crates/ruff_linter/resources/.*|
|
||||
crates/ruff_linter/src/rules/.*/snapshots/.*|
|
||||
@@ -65,7 +65,7 @@ repos:
|
||||
- black==25.1.0
|
||||
|
||||
- repo: https://github.com/crate-ci/typos
|
||||
rev: v1.31.1
|
||||
rev: v1.32.0
|
||||
hooks:
|
||||
- id: typos
|
||||
|
||||
@@ -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.4
|
||||
rev: v0.11.8
|
||||
hooks:
|
||||
- id: ruff-format
|
||||
- id: ruff
|
||||
@@ -97,12 +97,12 @@ repos:
|
||||
# zizmor detects security vulnerabilities in GitHub Actions workflows.
|
||||
# Additional configuration for the tool is found in `.github/zizmor.yml`
|
||||
- repo: https://github.com/woodruffw/zizmor-pre-commit
|
||||
rev: v1.5.2
|
||||
rev: v1.6.0
|
||||
hooks:
|
||||
- id: zizmor
|
||||
|
||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
||||
rev: 0.32.1
|
||||
rev: 0.33.0
|
||||
hooks:
|
||||
- id: check-github-workflows
|
||||
|
||||
|
||||
72
CHANGELOG.md
72
CHANGELOG.md
@@ -1,5 +1,77 @@
|
||||
# Changelog
|
||||
|
||||
## 0.11.8
|
||||
|
||||
### Preview features
|
||||
|
||||
- \[`airflow`\] Apply auto fixes to cases where the names have changed in Airflow 3 (`AIR302`, `AIR311`) ([#17553](https://github.com/astral-sh/ruff/pull/17553), [#17570](https://github.com/astral-sh/ruff/pull/17570), [#17571](https://github.com/astral-sh/ruff/pull/17571))
|
||||
- \[`airflow`\] Extend `AIR301` rule ([#17598](https://github.com/astral-sh/ruff/pull/17598))
|
||||
- \[`airflow`\] Update existing `AIR302` rules with better suggestions ([#17542](https://github.com/astral-sh/ruff/pull/17542))
|
||||
- \[`refurb`\] Mark fix as safe for `readlines-in-for` (`FURB129`) ([#17644](https://github.com/astral-sh/ruff/pull/17644))
|
||||
- [syntax-errors] `nonlocal` declaration at module level ([#17559](https://github.com/astral-sh/ruff/pull/17559))
|
||||
- [syntax-errors] Detect single starred expression assignment `x = *y` ([#17624](https://github.com/astral-sh/ruff/pull/17624))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- \[`flake8-pyi`\] Ensure `Literal[None,] | Literal[None,]` is not autofixed to `None | None` (`PYI061`) ([#17659](https://github.com/astral-sh/ruff/pull/17659))
|
||||
- \[`flake8-use-pathlib`\] Avoid suggesting `Path.iterdir()` for `os.listdir` with file descriptor (`PTH208`) ([#17715](https://github.com/astral-sh/ruff/pull/17715))
|
||||
- \[`flake8-use-pathlib`\] Fix `PTH104` false positive when `rename` is passed a file descriptor ([#17712](https://github.com/astral-sh/ruff/pull/17712))
|
||||
- \[`flake8-use-pathlib`\] Fix `PTH116` false positive when `stat` is passed a file descriptor ([#17709](https://github.com/astral-sh/ruff/pull/17709))
|
||||
- \[`flake8-use-pathlib`\] Fix `PTH123` false positive when `open` is passed a file descriptor from a function call ([#17705](https://github.com/astral-sh/ruff/pull/17705))
|
||||
- \[`pycodestyle`\] Fix duplicated diagnostic in `E712` ([#17651](https://github.com/astral-sh/ruff/pull/17651))
|
||||
- \[`pylint`\] Detect `global` declarations in module scope (`PLE0118`) ([#17411](https://github.com/astral-sh/ruff/pull/17411))
|
||||
- [syntax-errors] Make `async-comprehension-in-sync-comprehension` more specific ([#17460](https://github.com/astral-sh/ruff/pull/17460))
|
||||
|
||||
### Configuration
|
||||
|
||||
- Add option to disable `typing_extensions` imports ([#17611](https://github.com/astral-sh/ruff/pull/17611))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Fix example syntax for the `lint.pydocstyle.ignore-var-parameters` option ([#17740](https://github.com/astral-sh/ruff/pull/17740))
|
||||
- Add fix safety sections (`ASYNC116`, `FLY002`, `D200`, `RUF005`, `RUF017`, `RUF027`, `RUF028`, `RUF057`) ([#17497](https://github.com/astral-sh/ruff/pull/17497), [#17496](https://github.com/astral-sh/ruff/pull/17496), [#17502](https://github.com/astral-sh/ruff/pull/17502), [#17484](https://github.com/astral-sh/ruff/pull/17484), [#17480](https://github.com/astral-sh/ruff/pull/17480), [#17485](https://github.com/astral-sh/ruff/pull/17485), [#17722](https://github.com/astral-sh/ruff/pull/17722), [#17483](https://github.com/astral-sh/ruff/pull/17483))
|
||||
|
||||
### Other changes
|
||||
|
||||
- Add Python 3.14 to configuration options ([#17647](https://github.com/astral-sh/ruff/pull/17647))
|
||||
- Make syntax error for unparenthesized except tuples version specific to before 3.14 ([#17660](https://github.com/astral-sh/ruff/pull/17660))
|
||||
|
||||
## 0.11.7
|
||||
|
||||
### Preview features
|
||||
|
||||
- \[`airflow`\] Apply auto fixes to cases where the names have changed in Airflow 3 (`AIR301`) ([#17355](https://github.com/astral-sh/ruff/pull/17355))
|
||||
- \[`perflint`\] Implement fix for `manual-dict-comprehension` (`PERF403`) ([#16719](https://github.com/astral-sh/ruff/pull/16719))
|
||||
- [syntax-errors] Make duplicate parameter names a semantic error ([#17131](https://github.com/astral-sh/ruff/pull/17131))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- \[`airflow`\] Fix typos in provider package names (`AIR302`, `AIR312`) ([#17574](https://github.com/astral-sh/ruff/pull/17574))
|
||||
- \[`flake8-type-checking`\] Visit keyword arguments in checks involving `typing.cast`/`typing.NewType` arguments ([#17538](https://github.com/astral-sh/ruff/pull/17538))
|
||||
- \[`pyupgrade`\] Preserve parenthesis when fixing native literals containing newlines (`UP018`) ([#17220](https://github.com/astral-sh/ruff/pull/17220))
|
||||
- \[`refurb`\] Mark the `FURB161` fix unsafe except for integers and booleans ([#17240](https://github.com/astral-sh/ruff/pull/17240))
|
||||
|
||||
### Rule changes
|
||||
|
||||
- \[`perflint`\] Allow list function calls to be replaced with a comprehension (`PERF401`) ([#17519](https://github.com/astral-sh/ruff/pull/17519))
|
||||
- \[`pycodestyle`\] Auto-fix redundant boolean comparison (`E712`) ([#17090](https://github.com/astral-sh/ruff/pull/17090))
|
||||
- \[`pylint`\] make fix unsafe if delete comments (`PLR1730`) ([#17459](https://github.com/astral-sh/ruff/pull/17459))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add fix safety sections to docs for several rules ([#17410](https://github.com/astral-sh/ruff/pull/17410),[#17440](https://github.com/astral-sh/ruff/pull/17440),[#17441](https://github.com/astral-sh/ruff/pull/17441),[#17443](https://github.com/astral-sh/ruff/pull/17443),[#17444](https://github.com/astral-sh/ruff/pull/17444))
|
||||
|
||||
## 0.11.6
|
||||
|
||||
### Preview features
|
||||
|
||||
- Avoid adding whitespace to the end of a docstring after an escaped quote ([#17216](https://github.com/astral-sh/ruff/pull/17216))
|
||||
- \[`airflow`\] Extract `AIR311` from `AIR301` rules (`AIR301`, `AIR311`) ([#17310](https://github.com/astral-sh/ruff/pull/17310), [#17422](https://github.com/astral-sh/ruff/pull/17422))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Raise syntax error when `\` is at end of file ([#17409](https://github.com/astral-sh/ruff/pull/17409))
|
||||
|
||||
## 0.11.5
|
||||
|
||||
### Preview features
|
||||
|
||||
@@ -71,8 +71,7 @@ representative at an online or offline event.
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
<charlie.r.marsh@gmail.com>.
|
||||
reported to the community leaders responsible for enforcement at <hey@astral.sh>.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
|
||||
@@ -366,6 +366,15 @@ uvx --from ./python/ruff-ecosystem ruff-ecosystem format ruff "./target/debug/ru
|
||||
|
||||
See the [ruff-ecosystem package](https://github.com/astral-sh/ruff/tree/main/python/ruff-ecosystem) for more details.
|
||||
|
||||
## Upgrading Rust
|
||||
|
||||
1. Change the `channel` in `./rust-toolchain.toml` to the new Rust version (`<latest>`)
|
||||
1. Change the `rust-version` in the `./Cargo.toml` to `<latest> - 2` (e.g. 1.84 if the latest is 1.86)
|
||||
1. Run `cargo clippy --fix --allow-dirty --allow-staged` to fix new clippy warnings
|
||||
1. Create and merge the PR
|
||||
1. Bump the Rust version in Ruff's conda forge recipe. See [this PR](https://github.com/conda-forge/ruff-feedstock/pull/266) for an example.
|
||||
1. Enjoy the new Rust version!
|
||||
|
||||
## Benchmarking and Profiling
|
||||
|
||||
We have several ways of benchmarking and profiling Ruff:
|
||||
|
||||
660
Cargo.lock
generated
660
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
89
Cargo.toml
89
Cargo.toml
@@ -35,14 +35,14 @@ ruff_python_trivia = { path = "crates/ruff_python_trivia" }
|
||||
ruff_server = { path = "crates/ruff_server" }
|
||||
ruff_source_file = { path = "crates/ruff_source_file" }
|
||||
ruff_text_size = { path = "crates/ruff_text_size" }
|
||||
red_knot_vendored = { path = "crates/red_knot_vendored" }
|
||||
ruff_workspace = { path = "crates/ruff_workspace" }
|
||||
|
||||
red_knot_ide = { path = "crates/red_knot_ide" }
|
||||
red_knot_project = { path = "crates/red_knot_project", default-features = false }
|
||||
red_knot_python_semantic = { path = "crates/red_knot_python_semantic" }
|
||||
red_knot_server = { path = "crates/red_knot_server" }
|
||||
red_knot_test = { path = "crates/red_knot_test" }
|
||||
ty_ide = { path = "crates/ty_ide" }
|
||||
ty_project = { path = "crates/ty_project", default-features = false }
|
||||
ty_python_semantic = { path = "crates/ty_python_semantic" }
|
||||
ty_server = { path = "crates/ty_server" }
|
||||
ty_test = { path = "crates/ty_test" }
|
||||
ty_vendored = { path = "crates/ty_vendored" }
|
||||
|
||||
aho-corasick = { version = "1.1.3" }
|
||||
anstream = { version = "0.6.18" }
|
||||
@@ -55,7 +55,6 @@ bitflags = { version = "2.5.0" }
|
||||
bstr = { version = "1.9.1" }
|
||||
cachedir = { version = "0.3.1" }
|
||||
camino = { version = "1.1.7" }
|
||||
chrono = { version = "0.4.35", default-features = false, features = ["clock"] }
|
||||
clap = { version = "4.5.3", features = ["derive"] }
|
||||
clap_complete_command = { version = "0.6.0" }
|
||||
clearscreen = { version = "4.0.0" }
|
||||
@@ -95,6 +94,7 @@ insta-cmd = { version = "0.6.0" }
|
||||
is-macro = { version = "0.3.5" }
|
||||
is-wsl = { version = "0.4.0" }
|
||||
itertools = { version = "0.14.0" }
|
||||
jiff = { version = "0.2.0" }
|
||||
js-sys = { version = "0.3.69" }
|
||||
jod-thread = { version = "0.1.2" }
|
||||
libc = { version = "0.2.153" }
|
||||
@@ -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 = "87bf6b6c2d5f6479741271da73bd9d30c2580c26" }
|
||||
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "2c869364a9592d06fdf45c422e1e4a7265a8fe8a" }
|
||||
schemars = { version = "0.8.16" }
|
||||
seahash = { version = "4.1.0" }
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
@@ -185,6 +185,9 @@ zip = { version = "0.6.6", default-features = false }
|
||||
ignored = ["getrandom"]
|
||||
|
||||
|
||||
[patch."https://github.com/salsa-rs/salsa.git"]
|
||||
salsa = { path = "../salsa" }
|
||||
|
||||
[workspace.lints.rust]
|
||||
unsafe_code = "warn"
|
||||
unreachable_pub = "warn"
|
||||
@@ -268,73 +271,3 @@ debug = 1
|
||||
# The profile that 'cargo dist' will build with.
|
||||
[profile.dist]
|
||||
inherits = "release"
|
||||
|
||||
# Config for 'dist'
|
||||
[workspace.metadata.dist]
|
||||
# The preferred dist version to use in CI (Cargo.toml SemVer syntax)
|
||||
cargo-dist-version = "0.28.4-prerelease.1"
|
||||
# CI backends to support
|
||||
ci = "github"
|
||||
# The installers to generate for each app
|
||||
installers = ["shell", "powershell"]
|
||||
# The archive format to use for windows builds (defaults .zip)
|
||||
windows-archive = ".zip"
|
||||
# The archive format to use for non-windows builds (defaults .tar.xz)
|
||||
unix-archive = ".tar.gz"
|
||||
# Target platforms to build apps for (Rust target-triple syntax)
|
||||
targets = [
|
||||
"aarch64-apple-darwin",
|
||||
"aarch64-pc-windows-msvc",
|
||||
"aarch64-unknown-linux-gnu",
|
||||
"aarch64-unknown-linux-musl",
|
||||
"arm-unknown-linux-musleabihf",
|
||||
"armv7-unknown-linux-gnueabihf",
|
||||
"armv7-unknown-linux-musleabihf",
|
||||
"i686-pc-windows-msvc",
|
||||
"i686-unknown-linux-gnu",
|
||||
"i686-unknown-linux-musl",
|
||||
"powerpc64-unknown-linux-gnu",
|
||||
"powerpc64le-unknown-linux-gnu",
|
||||
"s390x-unknown-linux-gnu",
|
||||
"x86_64-apple-darwin",
|
||||
"x86_64-pc-windows-msvc",
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"x86_64-unknown-linux-musl",
|
||||
]
|
||||
# Whether to auto-include files like READMEs, LICENSEs, and CHANGELOGs (default true)
|
||||
auto-includes = false
|
||||
# Whether dist should create a Github Release or use an existing draft
|
||||
create-release = true
|
||||
# Which actions to run on pull requests
|
||||
pr-run-mode = "skip"
|
||||
# Whether CI should trigger releases with dispatches instead of tag pushes
|
||||
dispatch-releases = true
|
||||
# Which phase dist should use to create the GitHub release
|
||||
github-release = "announce"
|
||||
# Whether CI should include auto-generated code to build local artifacts
|
||||
build-local-artifacts = false
|
||||
# Local artifacts jobs to run in CI
|
||||
local-artifacts-jobs = ["./build-binaries", "./build-docker"]
|
||||
# Publish jobs to run in CI
|
||||
publish-jobs = ["./publish-pypi", "./publish-wasm"]
|
||||
# Post-announce jobs to run in CI
|
||||
post-announce-jobs = [
|
||||
"./notify-dependents",
|
||||
"./publish-docs",
|
||||
"./publish-playground",
|
||||
]
|
||||
# Custom permissions for GitHub Jobs
|
||||
github-custom-job-permissions = { "build-docker" = { packages = "write", contents = "read" }, "publish-wasm" = { contents = "read", id-token = "write", packages = "write" } }
|
||||
# Whether to install an updater program
|
||||
install-updater = false
|
||||
# Path that installers should place binaries in
|
||||
install-path = ["$XDG_BIN_HOME/", "$XDG_DATA_HOME/../bin", "~/.local/bin"]
|
||||
|
||||
[workspace.metadata.dist.github-custom-runners]
|
||||
global = "depot-ubuntu-latest-4"
|
||||
|
||||
[workspace.metadata.dist.github-action-commits]
|
||||
"actions/checkout" = "11bd71901bbe5b1630ceea73d27597364c9af683" # v4
|
||||
"actions/upload-artifact" = "ea165f8d65b6e75b540449e92b4886f43607fa02" # v4.6.2
|
||||
"actions/download-artifact" = "95815c38cf2ff2164869cbab79da8d1f422bc89e" # v4.2.1
|
||||
"actions/attest-build-provenance" = "c074443f1aee8d4aeeae555aebba3282517141b2" #v2.2.3
|
||||
|
||||
@@ -149,8 +149,8 @@ curl -LsSf https://astral.sh/ruff/install.sh | sh
|
||||
powershell -c "irm https://astral.sh/ruff/install.ps1 | iex"
|
||||
|
||||
# For a specific version.
|
||||
curl -LsSf https://astral.sh/ruff/0.11.5/install.sh | sh
|
||||
powershell -c "irm https://astral.sh/ruff/0.11.5/install.ps1 | iex"
|
||||
curl -LsSf https://astral.sh/ruff/0.11.8/install.sh | sh
|
||||
powershell -c "irm https://astral.sh/ruff/0.11.8/install.ps1 | iex"
|
||||
```
|
||||
|
||||
You can also install Ruff via [Homebrew](https://formulae.brew.sh/formula/ruff), [Conda](https://anaconda.org/conda-forge/ruff),
|
||||
@@ -183,7 +183,7 @@ Ruff can also be used as a [pre-commit](https://pre-commit.com/) hook via [`ruff
|
||||
```yaml
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: v0.11.5
|
||||
rev: v0.11.8
|
||||
hooks:
|
||||
# Run the linter.
|
||||
- id: ruff
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[files]
|
||||
# https://github.com/crate-ci/typos/issues/868
|
||||
extend-exclude = [
|
||||
"crates/red_knot_vendored/vendor/**/*",
|
||||
"crates/ty_vendored/vendor/**/*",
|
||||
"**/resources/**/*",
|
||||
"**/snapshots/**/*",
|
||||
]
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# Red Knot
|
||||
|
||||
Red Knot is an extremely fast type checker.
|
||||
Currently, it is a work-in-progress and not ready for user testing.
|
||||
|
||||
Red Knot is designed to prioritize good type inference, even in unannotated code,
|
||||
and aims to avoid false positives.
|
||||
|
||||
While Red Knot will produce similar results to mypy and pyright on many codebases,
|
||||
100% compatibility with these tools is a non-goal.
|
||||
On some codebases, Red Knot's design decisions lead to different outcomes
|
||||
than you would get from running one of these more established tools.
|
||||
|
||||
## Contributing
|
||||
|
||||
Core type checking tests are written as Markdown code blocks.
|
||||
They can be found in [`red_knot_python_semantic/resources/mdtest`][resources-mdtest].
|
||||
See [`red_knot_test/README.md`][mdtest-readme] for more information
|
||||
on the test framework itself.
|
||||
|
||||
The list of open issues can be found [here][open-issues].
|
||||
|
||||
[mdtest-readme]: ../red_knot_test/README.md
|
||||
[open-issues]: https://github.com/astral-sh/ruff/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20label%3Ared-knot
|
||||
[resources-mdtest]: ../red_knot_python_semantic/resources/mdtest
|
||||
@@ -1,83 +0,0 @@
|
||||
# Any
|
||||
|
||||
## Annotation
|
||||
|
||||
`typing.Any` is a way to name the Any type.
|
||||
|
||||
```py
|
||||
from typing import Any
|
||||
|
||||
x: Any = 1
|
||||
x = "foo"
|
||||
|
||||
def f():
|
||||
reveal_type(x) # revealed: Any
|
||||
```
|
||||
|
||||
## Aliased to a different name
|
||||
|
||||
If you alias `typing.Any` to another name, we still recognize that as a spelling of the Any type.
|
||||
|
||||
```py
|
||||
from typing import Any as RenamedAny
|
||||
|
||||
x: RenamedAny = 1
|
||||
x = "foo"
|
||||
|
||||
def f():
|
||||
reveal_type(x) # revealed: Any
|
||||
```
|
||||
|
||||
## Shadowed class
|
||||
|
||||
If you define your own class named `Any`, using that in a type expression refers to your class, and
|
||||
isn't a spelling of the Any type.
|
||||
|
||||
```py
|
||||
class Any: ...
|
||||
|
||||
x: Any
|
||||
|
||||
def f():
|
||||
reveal_type(x) # revealed: Any
|
||||
|
||||
# This verifies that we're not accidentally seeing typing.Any, since str is assignable
|
||||
# to that but not to our locally defined class.
|
||||
y: Any = "not an Any" # error: [invalid-assignment]
|
||||
```
|
||||
|
||||
## Subclass
|
||||
|
||||
The spec allows you to define subclasses of `Any`.
|
||||
|
||||
TODO: Handle assignments correctly. `Subclass` has an unknown superclass, which might be `int`. The
|
||||
assignment to `x` should not be allowed, even when the unknown superclass is `int`. The assignment
|
||||
to `y` should be allowed, since `Subclass` might have `int` as a superclass, and is therefore
|
||||
assignable to `int`.
|
||||
|
||||
```py
|
||||
from typing import Any
|
||||
|
||||
class Subclass(Any): ...
|
||||
|
||||
reveal_type(Subclass.__mro__) # revealed: tuple[Literal[Subclass], Any, Literal[object]]
|
||||
|
||||
x: Subclass = 1 # error: [invalid-assignment]
|
||||
# TODO: no diagnostic
|
||||
y: int = Subclass() # error: [invalid-assignment]
|
||||
|
||||
def _(s: Subclass):
|
||||
reveal_type(s) # revealed: Subclass
|
||||
```
|
||||
|
||||
## Invalid
|
||||
|
||||
`Any` cannot be parameterized:
|
||||
|
||||
```py
|
||||
from typing import Any
|
||||
|
||||
# error: [invalid-type-form] "Type `typing.Any` expected no type parameter"
|
||||
def f(x: Any[int]):
|
||||
reveal_type(x) # revealed: Unknown
|
||||
```
|
||||
@@ -1,124 +0,0 @@
|
||||
# Typing-module aliases to other stdlib classes
|
||||
|
||||
The `typing` module has various aliases to other stdlib classes. These are a legacy feature, but
|
||||
still need to be supported by a type checker.
|
||||
|
||||
## Correspondence
|
||||
|
||||
All of the following symbols can be mapped one-to-one with the actual type:
|
||||
|
||||
```py
|
||||
import typing
|
||||
|
||||
def f(
|
||||
list_bare: typing.List,
|
||||
list_parametrized: typing.List[int],
|
||||
dict_bare: typing.Dict,
|
||||
dict_parametrized: typing.Dict[int, str],
|
||||
set_bare: typing.Set,
|
||||
set_parametrized: typing.Set[int],
|
||||
frozen_set_bare: typing.FrozenSet,
|
||||
frozen_set_parametrized: typing.FrozenSet[str],
|
||||
chain_map_bare: typing.ChainMap,
|
||||
chain_map_parametrized: typing.ChainMap[int],
|
||||
counter_bare: typing.Counter,
|
||||
counter_parametrized: typing.Counter[int],
|
||||
default_dict_bare: typing.DefaultDict,
|
||||
default_dict_parametrized: typing.DefaultDict[str, int],
|
||||
deque_bare: typing.Deque,
|
||||
deque_parametrized: typing.Deque[str],
|
||||
ordered_dict_bare: typing.OrderedDict,
|
||||
ordered_dict_parametrized: typing.OrderedDict[int, str],
|
||||
):
|
||||
reveal_type(list_bare) # revealed: list
|
||||
reveal_type(list_parametrized) # revealed: list
|
||||
|
||||
reveal_type(dict_bare) # revealed: dict
|
||||
reveal_type(dict_parametrized) # revealed: dict
|
||||
|
||||
reveal_type(set_bare) # revealed: set
|
||||
reveal_type(set_parametrized) # revealed: set
|
||||
|
||||
reveal_type(frozen_set_bare) # revealed: frozenset
|
||||
reveal_type(frozen_set_parametrized) # revealed: frozenset
|
||||
|
||||
reveal_type(chain_map_bare) # revealed: ChainMap
|
||||
reveal_type(chain_map_parametrized) # revealed: ChainMap
|
||||
|
||||
reveal_type(counter_bare) # revealed: Counter
|
||||
reveal_type(counter_parametrized) # revealed: Counter
|
||||
|
||||
reveal_type(default_dict_bare) # revealed: defaultdict
|
||||
reveal_type(default_dict_parametrized) # revealed: defaultdict
|
||||
|
||||
reveal_type(deque_bare) # revealed: deque
|
||||
reveal_type(deque_parametrized) # revealed: deque
|
||||
|
||||
reveal_type(ordered_dict_bare) # revealed: OrderedDict
|
||||
reveal_type(ordered_dict_parametrized) # revealed: OrderedDict
|
||||
```
|
||||
|
||||
## Inheritance
|
||||
|
||||
The aliases can be inherited from. Some of these are still partially or wholly TODOs.
|
||||
|
||||
```py
|
||||
import typing
|
||||
|
||||
####################
|
||||
### Built-ins
|
||||
|
||||
class ListSubclass(typing.List): ...
|
||||
|
||||
# revealed: tuple[Literal[ListSubclass], Literal[list], Literal[MutableSequence], Literal[Sequence], Literal[Reversible], Literal[Collection], Literal[Iterable], Literal[Container], @Todo(protocol), Literal[object]]
|
||||
reveal_type(ListSubclass.__mro__)
|
||||
|
||||
class DictSubclass(typing.Dict): ...
|
||||
|
||||
# TODO: should have `Generic`, should not have `Unknown`
|
||||
# revealed: tuple[Literal[DictSubclass], Literal[dict], Unknown, Literal[object]]
|
||||
reveal_type(DictSubclass.__mro__)
|
||||
|
||||
class SetSubclass(typing.Set): ...
|
||||
|
||||
# revealed: tuple[Literal[SetSubclass], Literal[set], Literal[MutableSet], Literal[AbstractSet], Literal[Collection], Literal[Iterable], Literal[Container], @Todo(protocol), Literal[object]]
|
||||
reveal_type(SetSubclass.__mro__)
|
||||
|
||||
class FrozenSetSubclass(typing.FrozenSet): ...
|
||||
|
||||
# TODO: should have `Generic`, should not have `Unknown`
|
||||
# revealed: tuple[Literal[FrozenSetSubclass], Literal[frozenset], Unknown, Literal[object]]
|
||||
reveal_type(FrozenSetSubclass.__mro__)
|
||||
|
||||
####################
|
||||
### `collections`
|
||||
|
||||
class ChainMapSubclass(typing.ChainMap): ...
|
||||
|
||||
# TODO: Should be (ChainMapSubclass, ChainMap, MutableMapping, Mapping, Collection, Sized, Iterable, Container, Generic, object)
|
||||
# revealed: tuple[Literal[ChainMapSubclass], Literal[ChainMap], Unknown, Literal[object]]
|
||||
reveal_type(ChainMapSubclass.__mro__)
|
||||
|
||||
class CounterSubclass(typing.Counter): ...
|
||||
|
||||
# TODO: Should be (CounterSubclass, Counter, dict, MutableMapping, Mapping, Collection, Sized, Iterable, Container, Generic, object)
|
||||
# revealed: tuple[Literal[CounterSubclass], Literal[Counter], Unknown, Literal[object]]
|
||||
reveal_type(CounterSubclass.__mro__)
|
||||
|
||||
class DefaultDictSubclass(typing.DefaultDict): ...
|
||||
|
||||
# TODO: Should be (DefaultDictSubclass, defaultdict, dict, MutableMapping, Mapping, Collection, Sized, Iterable, Container, Generic, object)
|
||||
# revealed: tuple[Literal[DefaultDictSubclass], Literal[defaultdict], Unknown, Literal[object]]
|
||||
reveal_type(DefaultDictSubclass.__mro__)
|
||||
|
||||
class DequeSubclass(typing.Deque): ...
|
||||
|
||||
# revealed: tuple[Literal[DequeSubclass], Literal[deque], Literal[MutableSequence], Literal[Sequence], Literal[Reversible], Literal[Collection], Literal[Iterable], Literal[Container], @Todo(protocol), Literal[object]]
|
||||
reveal_type(DequeSubclass.__mro__)
|
||||
|
||||
class OrderedDictSubclass(typing.OrderedDict): ...
|
||||
|
||||
# TODO: Should be (OrderedDictSubclass, OrderedDict, dict, MutableMapping, Mapping, Collection, Sized, Iterable, Container, Generic, object)
|
||||
# revealed: tuple[Literal[OrderedDictSubclass], Literal[OrderedDict], Unknown, Literal[object]]
|
||||
reveal_type(OrderedDictSubclass.__mro__)
|
||||
```
|
||||
@@ -1,256 +0,0 @@
|
||||
# Generic classes
|
||||
|
||||
## PEP 695 syntax
|
||||
|
||||
TODO: Add a `red_knot_extension` function that asserts whether a function or class is generic.
|
||||
|
||||
This is a generic class defined using PEP 695 syntax:
|
||||
|
||||
```py
|
||||
class C[T]: ...
|
||||
```
|
||||
|
||||
A class that inherits from a generic class, and fills its type parameters with typevars, is generic:
|
||||
|
||||
```py
|
||||
class D[U](C[U]): ...
|
||||
```
|
||||
|
||||
A class that inherits from a generic class, but fills its type parameters with concrete types, is
|
||||
_not_ generic:
|
||||
|
||||
```py
|
||||
class E(C[int]): ...
|
||||
```
|
||||
|
||||
A class that inherits from a generic class, and doesn't fill its type parameters at all, implicitly
|
||||
uses the default value for the typevar. In this case, that default type is `Unknown`, so `F`
|
||||
inherits from `C[Unknown]` and is not itself generic.
|
||||
|
||||
```py
|
||||
class F(C): ...
|
||||
```
|
||||
|
||||
## Legacy syntax
|
||||
|
||||
This is a generic class defined using the legacy syntax:
|
||||
|
||||
```py
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
# TODO: no error
|
||||
# error: [invalid-base]
|
||||
class C(Generic[T]): ...
|
||||
```
|
||||
|
||||
A class that inherits from a generic class, and fills its type parameters with typevars, is generic.
|
||||
|
||||
```py
|
||||
class D(C[T]): ...
|
||||
```
|
||||
|
||||
(Examples `E` and `F` from above do not have analogues in the legacy syntax.)
|
||||
|
||||
## Specializing generic classes explicitly
|
||||
|
||||
The type parameter can be specified explicitly:
|
||||
|
||||
```py
|
||||
class C[T]:
|
||||
x: T
|
||||
|
||||
reveal_type(C[int]()) # revealed: C[int]
|
||||
```
|
||||
|
||||
The specialization must match the generic types:
|
||||
|
||||
```py
|
||||
# error: [too-many-positional-arguments] "Too many positional arguments to class `C`: expected 1, got 2"
|
||||
reveal_type(C[int, int]()) # revealed: Unknown
|
||||
```
|
||||
|
||||
If the type variable has an upper bound, the specialized type must satisfy that bound:
|
||||
|
||||
```py
|
||||
class Bounded[T: int]: ...
|
||||
class BoundedByUnion[T: int | str]: ...
|
||||
class IntSubclass(int): ...
|
||||
|
||||
reveal_type(Bounded[int]()) # revealed: Bounded[int]
|
||||
reveal_type(Bounded[IntSubclass]()) # revealed: Bounded[IntSubclass]
|
||||
|
||||
# error: [invalid-argument-type] "Object of type `str` cannot be assigned to parameter 1 (`T`) of class `Bounded`; expected type `int`"
|
||||
reveal_type(Bounded[str]()) # revealed: Unknown
|
||||
|
||||
# error: [invalid-argument-type] "Object of type `int | str` cannot be assigned to parameter 1 (`T`) of class `Bounded`; expected type `int`"
|
||||
reveal_type(Bounded[int | str]()) # revealed: Unknown
|
||||
|
||||
reveal_type(BoundedByUnion[int]()) # revealed: BoundedByUnion[int]
|
||||
reveal_type(BoundedByUnion[IntSubclass]()) # revealed: BoundedByUnion[IntSubclass]
|
||||
reveal_type(BoundedByUnion[str]()) # revealed: BoundedByUnion[str]
|
||||
reveal_type(BoundedByUnion[int | str]()) # revealed: BoundedByUnion[int | str]
|
||||
```
|
||||
|
||||
If the type variable is constrained, the specialized type must satisfy those constraints:
|
||||
|
||||
```py
|
||||
class Constrained[T: (int, str)]: ...
|
||||
|
||||
reveal_type(Constrained[int]()) # revealed: Constrained[int]
|
||||
|
||||
# TODO: error: [invalid-argument-type]
|
||||
# TODO: revealed: Constrained[Unknown]
|
||||
reveal_type(Constrained[IntSubclass]()) # revealed: Constrained[IntSubclass]
|
||||
|
||||
reveal_type(Constrained[str]()) # revealed: Constrained[str]
|
||||
|
||||
# TODO: error: [invalid-argument-type]
|
||||
# TODO: revealed: Unknown
|
||||
reveal_type(Constrained[int | str]()) # revealed: Constrained[int | str]
|
||||
|
||||
# error: [invalid-argument-type] "Object of type `object` cannot be assigned to parameter 1 (`T`) of class `Constrained`; expected type `int | str`"
|
||||
reveal_type(Constrained[object]()) # revealed: Unknown
|
||||
```
|
||||
|
||||
## Inferring generic class parameters
|
||||
|
||||
We can infer the type parameter from a type context:
|
||||
|
||||
```py
|
||||
class C[T]:
|
||||
x: T
|
||||
|
||||
c: C[int] = C()
|
||||
# TODO: revealed: C[int]
|
||||
reveal_type(c) # revealed: C[Unknown]
|
||||
```
|
||||
|
||||
The typevars of a fully specialized generic class should no longer be visible:
|
||||
|
||||
```py
|
||||
# TODO: revealed: int
|
||||
reveal_type(c.x) # revealed: Unknown
|
||||
```
|
||||
|
||||
If the type parameter is not specified explicitly, and there are no constraints that let us infer a
|
||||
specific type, we infer the typevar's default type:
|
||||
|
||||
```py
|
||||
class D[T = int]: ...
|
||||
|
||||
reveal_type(D()) # revealed: D[int]
|
||||
```
|
||||
|
||||
If a typevar does not provide a default, we use `Unknown`:
|
||||
|
||||
```py
|
||||
reveal_type(C()) # revealed: C[Unknown]
|
||||
```
|
||||
|
||||
If the type of a constructor parameter is a class typevar, we can use that to infer the type
|
||||
parameter:
|
||||
|
||||
```py
|
||||
class E[T]:
|
||||
def __init__(self, x: T) -> None: ...
|
||||
|
||||
# TODO: revealed: E[int] or E[Literal[1]]
|
||||
reveal_type(E(1)) # revealed: E[Unknown]
|
||||
```
|
||||
|
||||
The types inferred from a type context and from a constructor parameter must be consistent with each
|
||||
other:
|
||||
|
||||
```py
|
||||
# TODO: error: [invalid-argument-type]
|
||||
wrong_innards: E[int] = E("five")
|
||||
```
|
||||
|
||||
## Generic subclass
|
||||
|
||||
When a generic subclass fills its superclass's type parameter with one of its own, the actual types
|
||||
propagate through:
|
||||
|
||||
```py
|
||||
class Base[T]:
|
||||
x: T | None = None
|
||||
|
||||
class Sub[U](Base[U]): ...
|
||||
|
||||
reveal_type(Base[int].x) # revealed: int | None
|
||||
reveal_type(Sub[int].x) # revealed: int | None
|
||||
```
|
||||
|
||||
## Generic methods
|
||||
|
||||
Generic classes can contain methods that are themselves generic. The generic methods can refer to
|
||||
the typevars of the enclosing generic class, and introduce new (distinct) typevars that are only in
|
||||
scope for the method.
|
||||
|
||||
```py
|
||||
class C[T]:
|
||||
def method[U](self, u: U) -> U:
|
||||
return u
|
||||
# error: [unresolved-reference]
|
||||
def cannot_use_outside_of_method(self, u: U): ...
|
||||
|
||||
# TODO: error
|
||||
def cannot_shadow_class_typevar[T](self, t: T): ...
|
||||
|
||||
c: C[int] = C[int]()
|
||||
# TODO: no error
|
||||
# TODO: revealed: str or Literal["string"]
|
||||
# error: [invalid-argument-type]
|
||||
reveal_type(c.method("string")) # revealed: U
|
||||
```
|
||||
|
||||
## Cyclic class definition
|
||||
|
||||
A class can use itself as the type parameter of one of its superclasses. (This is also known as the
|
||||
[curiously recurring template pattern][crtp] or [F-bounded quantification][f-bound].)
|
||||
|
||||
Here, `Sub` is not a generic class, since it fills its superclass's type parameter (with itself).
|
||||
|
||||
`stub.pyi`:
|
||||
|
||||
```pyi
|
||||
class Base[T]: ...
|
||||
class Sub(Base[Sub]): ...
|
||||
|
||||
reveal_type(Sub) # revealed: Literal[Sub]
|
||||
```
|
||||
|
||||
A similar case can work in a non-stub file, if forward references are stringified:
|
||||
|
||||
`string_annotation.py`:
|
||||
|
||||
```py
|
||||
class Base[T]: ...
|
||||
class Sub(Base["Sub"]): ...
|
||||
|
||||
reveal_type(Sub) # revealed: Literal[Sub]
|
||||
```
|
||||
|
||||
In a non-stub file, without stringified forward references, this raises a `NameError`:
|
||||
|
||||
`bare_annotation.py`:
|
||||
|
||||
```py
|
||||
class Base[T]: ...
|
||||
|
||||
# error: [unresolved-reference]
|
||||
class Sub(Base[Sub]): ...
|
||||
```
|
||||
|
||||
## Another cyclic case
|
||||
|
||||
```pyi
|
||||
# TODO no error (generics)
|
||||
# error: [invalid-base]
|
||||
class Derived[T](list[Derived[T]]): ...
|
||||
```
|
||||
|
||||
[crtp]: https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
|
||||
[f-bound]: https://en.wikipedia.org/wiki/Bounded_quantification#F-bounded_quantification
|
||||
@@ -1,72 +0,0 @@
|
||||
# Legacy type variables
|
||||
|
||||
The tests in this file focus on how type variables are defined using the legacy notation. Most
|
||||
_uses_ of type variables are tested in other files in this directory; we do not duplicate every test
|
||||
for both type variable syntaxes.
|
||||
|
||||
Unless otherwise specified, all quotations come from the [Generics] section of the typing spec.
|
||||
|
||||
## Type variables
|
||||
|
||||
### Defining legacy type variables
|
||||
|
||||
> Generics can be parameterized by using a factory available in `typing` called `TypeVar`.
|
||||
|
||||
This was the only way to create type variables prior to PEP 695/Python 3.12. It is still available
|
||||
in newer Python releases.
|
||||
|
||||
```py
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
```
|
||||
|
||||
### Directly assigned to a variable
|
||||
|
||||
> A `TypeVar()` expression must always directly be assigned to a variable (it should not be used as
|
||||
> part of a larger expression).
|
||||
|
||||
```py
|
||||
from typing import TypeVar
|
||||
|
||||
# TODO: error
|
||||
TestList = list[TypeVar("W")]
|
||||
```
|
||||
|
||||
### `TypeVar` parameter must match variable name
|
||||
|
||||
> The argument to `TypeVar()` must be a string equal to the variable name to which it is assigned.
|
||||
|
||||
```py
|
||||
from typing import TypeVar
|
||||
|
||||
# TODO: error
|
||||
T = TypeVar("Q")
|
||||
```
|
||||
|
||||
### No redefinition
|
||||
|
||||
> Type variables must not be redefined.
|
||||
|
||||
```py
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
# TODO: error
|
||||
T = TypeVar("T")
|
||||
```
|
||||
|
||||
### Cannot have only one constraint
|
||||
|
||||
> `TypeVar` supports constraining parametric types to a fixed set of possible types...There should
|
||||
> be at least two constraints, if any; specifying a single constraint is disallowed.
|
||||
|
||||
```py
|
||||
from typing import TypeVar
|
||||
|
||||
# TODO: error: [invalid-type-variable-constraints]
|
||||
T = TypeVar("T", int)
|
||||
```
|
||||
|
||||
[generics]: https://typing.python.org/en/latest/spec/generics.html
|
||||
@@ -1,7 +0,0 @@
|
||||
# Dictionaries
|
||||
|
||||
## Empty dictionary
|
||||
|
||||
```py
|
||||
reveal_type({}) # revealed: dict
|
||||
```
|
||||
@@ -1,408 +0,0 @@
|
||||
# Method Resolution Order tests
|
||||
|
||||
Tests that assert that we can infer the correct type for a class's `__mro__` attribute.
|
||||
|
||||
This attribute is rarely accessed directly at runtime. However, it's extremely important for *us* to
|
||||
know the precise possible values of a class's Method Resolution Order, or we won't be able to infer
|
||||
the correct type of attributes accessed from instances.
|
||||
|
||||
For documentation on method resolution orders, see:
|
||||
|
||||
- <https://docs.python.org/3/glossary.html#term-method-resolution-order>
|
||||
- <https://docs.python.org/3/howto/mro.html#python-2-3-mro>
|
||||
|
||||
## No bases
|
||||
|
||||
```py
|
||||
class C: ...
|
||||
|
||||
reveal_type(C.__mro__) # revealed: tuple[Literal[C], Literal[object]]
|
||||
```
|
||||
|
||||
## The special case: `object` itself
|
||||
|
||||
```py
|
||||
reveal_type(object.__mro__) # revealed: tuple[Literal[object]]
|
||||
```
|
||||
|
||||
## Explicit inheritance from `object`
|
||||
|
||||
```py
|
||||
class C(object): ...
|
||||
|
||||
reveal_type(C.__mro__) # revealed: tuple[Literal[C], Literal[object]]
|
||||
```
|
||||
|
||||
## Explicit inheritance from non-`object` single base
|
||||
|
||||
```py
|
||||
class A: ...
|
||||
class B(A): ...
|
||||
|
||||
reveal_type(B.__mro__) # revealed: tuple[Literal[B], Literal[A], Literal[object]]
|
||||
```
|
||||
|
||||
## Linearization of multiple bases
|
||||
|
||||
```py
|
||||
class A: ...
|
||||
class B: ...
|
||||
class C(A, B): ...
|
||||
|
||||
reveal_type(C.__mro__) # revealed: tuple[Literal[C], Literal[A], Literal[B], Literal[object]]
|
||||
```
|
||||
|
||||
## Complex diamond inheritance (1)
|
||||
|
||||
This is "ex_2" from <https://docs.python.org/3/howto/mro.html#the-end>
|
||||
|
||||
```py
|
||||
class O: ...
|
||||
class X(O): ...
|
||||
class Y(O): ...
|
||||
class A(X, Y): ...
|
||||
class B(Y, X): ...
|
||||
|
||||
reveal_type(A.__mro__) # revealed: tuple[Literal[A], Literal[X], Literal[Y], Literal[O], Literal[object]]
|
||||
reveal_type(B.__mro__) # revealed: tuple[Literal[B], Literal[Y], Literal[X], Literal[O], Literal[object]]
|
||||
```
|
||||
|
||||
## Complex diamond inheritance (2)
|
||||
|
||||
This is "ex_5" from <https://docs.python.org/3/howto/mro.html#the-end>
|
||||
|
||||
```py
|
||||
class O: ...
|
||||
class F(O): ...
|
||||
class E(O): ...
|
||||
class D(O): ...
|
||||
class C(D, F): ...
|
||||
class B(D, E): ...
|
||||
class A(B, C): ...
|
||||
|
||||
# revealed: tuple[Literal[C], Literal[D], Literal[F], Literal[O], Literal[object]]
|
||||
reveal_type(C.__mro__)
|
||||
# revealed: tuple[Literal[B], Literal[D], Literal[E], Literal[O], Literal[object]]
|
||||
reveal_type(B.__mro__)
|
||||
# revealed: tuple[Literal[A], Literal[B], Literal[C], Literal[D], Literal[E], Literal[F], Literal[O], Literal[object]]
|
||||
reveal_type(A.__mro__)
|
||||
```
|
||||
|
||||
## Complex diamond inheritance (3)
|
||||
|
||||
This is "ex_6" from <https://docs.python.org/3/howto/mro.html#the-end>
|
||||
|
||||
```py
|
||||
class O: ...
|
||||
class F(O): ...
|
||||
class E(O): ...
|
||||
class D(O): ...
|
||||
class C(D, F): ...
|
||||
class B(E, D): ...
|
||||
class A(B, C): ...
|
||||
|
||||
# revealed: tuple[Literal[C], Literal[D], Literal[F], Literal[O], Literal[object]]
|
||||
reveal_type(C.__mro__)
|
||||
# revealed: tuple[Literal[B], Literal[E], Literal[D], Literal[O], Literal[object]]
|
||||
reveal_type(B.__mro__)
|
||||
# revealed: tuple[Literal[A], Literal[B], Literal[E], Literal[C], Literal[D], Literal[F], Literal[O], Literal[object]]
|
||||
reveal_type(A.__mro__)
|
||||
```
|
||||
|
||||
## Complex diamond inheritance (4)
|
||||
|
||||
This is "ex_9" from <https://docs.python.org/3/howto/mro.html#the-end>
|
||||
|
||||
```py
|
||||
class O: ...
|
||||
class A(O): ...
|
||||
class B(O): ...
|
||||
class C(O): ...
|
||||
class D(O): ...
|
||||
class E(O): ...
|
||||
class K1(A, B, C): ...
|
||||
class K2(D, B, E): ...
|
||||
class K3(D, A): ...
|
||||
class Z(K1, K2, K3): ...
|
||||
|
||||
# revealed: tuple[Literal[K1], Literal[A], Literal[B], Literal[C], Literal[O], Literal[object]]
|
||||
reveal_type(K1.__mro__)
|
||||
# revealed: tuple[Literal[K2], Literal[D], Literal[B], Literal[E], Literal[O], Literal[object]]
|
||||
reveal_type(K2.__mro__)
|
||||
# revealed: tuple[Literal[K3], Literal[D], Literal[A], Literal[O], Literal[object]]
|
||||
reveal_type(K3.__mro__)
|
||||
# revealed: tuple[Literal[Z], Literal[K1], Literal[K2], Literal[K3], Literal[D], Literal[A], Literal[B], Literal[C], Literal[E], Literal[O], Literal[object]]
|
||||
reveal_type(Z.__mro__)
|
||||
```
|
||||
|
||||
## Inheritance from `Unknown`
|
||||
|
||||
```py
|
||||
from does_not_exist import DoesNotExist # error: [unresolved-import]
|
||||
|
||||
class A(DoesNotExist): ...
|
||||
class B: ...
|
||||
class C: ...
|
||||
class D(A, B, C): ...
|
||||
class E(B, C): ...
|
||||
class F(E, A): ...
|
||||
|
||||
reveal_type(A.__mro__) # revealed: tuple[Literal[A], Unknown, Literal[object]]
|
||||
reveal_type(D.__mro__) # revealed: tuple[Literal[D], Literal[A], Unknown, Literal[B], Literal[C], Literal[object]]
|
||||
reveal_type(E.__mro__) # revealed: tuple[Literal[E], Literal[B], Literal[C], Literal[object]]
|
||||
reveal_type(F.__mro__) # revealed: tuple[Literal[F], Literal[E], Literal[B], Literal[C], Literal[A], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## `__bases__` lists that cause errors at runtime
|
||||
|
||||
If the class's `__bases__` cause an exception to be raised at runtime and therefore the class
|
||||
creation to fail, we infer the class's `__mro__` as being `[<class>, Unknown, object]`:
|
||||
|
||||
```py
|
||||
# error: [inconsistent-mro] "Cannot create a consistent method resolution order (MRO) for class `Foo` with bases list `[<class 'object'>, <class 'int'>]`"
|
||||
class Foo(object, int): ...
|
||||
|
||||
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
|
||||
|
||||
class Bar(Foo): ...
|
||||
|
||||
reveal_type(Bar.__mro__) # revealed: tuple[Literal[Bar], Literal[Foo], Unknown, Literal[object]]
|
||||
|
||||
# This is the `TypeError` at the bottom of "ex_2"
|
||||
# in the examples at <https://docs.python.org/3/howto/mro.html#the-end>
|
||||
class O: ...
|
||||
class X(O): ...
|
||||
class Y(O): ...
|
||||
class A(X, Y): ...
|
||||
class B(Y, X): ...
|
||||
|
||||
reveal_type(A.__mro__) # revealed: tuple[Literal[A], Literal[X], Literal[Y], Literal[O], Literal[object]]
|
||||
reveal_type(B.__mro__) # revealed: tuple[Literal[B], Literal[Y], Literal[X], Literal[O], Literal[object]]
|
||||
|
||||
# error: [inconsistent-mro] "Cannot create a consistent method resolution order (MRO) for class `Z` with bases list `[<class 'A'>, <class 'B'>]`"
|
||||
class Z(A, B): ...
|
||||
|
||||
reveal_type(Z.__mro__) # revealed: tuple[Literal[Z], Unknown, Literal[object]]
|
||||
|
||||
class AA(Z): ...
|
||||
|
||||
reveal_type(AA.__mro__) # revealed: tuple[Literal[AA], Literal[Z], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## `__bases__` includes a `Union`
|
||||
|
||||
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
|
||||
def returns_bool() -> bool:
|
||||
return True
|
||||
|
||||
class A: ...
|
||||
class B: ...
|
||||
|
||||
if returns_bool():
|
||||
x = A
|
||||
else:
|
||||
x = B
|
||||
|
||||
reveal_type(x) # revealed: Literal[A, B]
|
||||
|
||||
# error: 11 [invalid-base] "Invalid class base with type `Literal[A, B]` (all bases must be a class, `Any`, `Unknown` or `Todo`)"
|
||||
class Foo(x): ...
|
||||
|
||||
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## `__bases__` includes multiple `Union`s
|
||||
|
||||
```py
|
||||
def returns_bool() -> bool:
|
||||
return True
|
||||
|
||||
class A: ...
|
||||
class B: ...
|
||||
class C: ...
|
||||
class D: ...
|
||||
|
||||
if returns_bool():
|
||||
x = A
|
||||
else:
|
||||
x = B
|
||||
|
||||
if returns_bool():
|
||||
y = C
|
||||
else:
|
||||
y = D
|
||||
|
||||
reveal_type(x) # revealed: Literal[A, B]
|
||||
reveal_type(y) # revealed: Literal[C, D]
|
||||
|
||||
# error: 11 [invalid-base] "Invalid class base with type `Literal[A, B]` (all bases must be a class, `Any`, `Unknown` or `Todo`)"
|
||||
# error: 14 [invalid-base] "Invalid class base with type `Literal[C, D]` (all bases must be a class, `Any`, `Unknown` or `Todo`)"
|
||||
class Foo(x, y): ...
|
||||
|
||||
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## `__bases__` lists that cause errors... now with `Union`s
|
||||
|
||||
```py
|
||||
def returns_bool() -> bool:
|
||||
return True
|
||||
|
||||
class O: ...
|
||||
class X(O): ...
|
||||
class Y(O): ...
|
||||
|
||||
if returns_bool():
|
||||
foo = Y
|
||||
else:
|
||||
foo = object
|
||||
|
||||
# error: 21 [invalid-base] "Invalid class base with type `Literal[Y, object]` (all bases must be a class, `Any`, `Unknown` or `Todo`)"
|
||||
class PossibleError(foo, X): ...
|
||||
|
||||
reveal_type(PossibleError.__mro__) # revealed: tuple[Literal[PossibleError], Unknown, Literal[object]]
|
||||
|
||||
class A(X, Y): ...
|
||||
|
||||
reveal_type(A.__mro__) # revealed: tuple[Literal[A], Literal[X], Literal[Y], Literal[O], Literal[object]]
|
||||
|
||||
if returns_bool():
|
||||
class B(X, Y): ...
|
||||
|
||||
else:
|
||||
class B(Y, X): ...
|
||||
|
||||
# revealed: tuple[Literal[B], Literal[X], Literal[Y], Literal[O], Literal[object]] | tuple[Literal[B], Literal[Y], Literal[X], Literal[O], Literal[object]]
|
||||
reveal_type(B.__mro__)
|
||||
|
||||
# error: 12 [invalid-base] "Invalid class base with type `Literal[B, B]` (all bases must be a class, `Any`, `Unknown` or `Todo`)"
|
||||
class Z(A, B): ...
|
||||
|
||||
reveal_type(Z.__mro__) # revealed: tuple[Literal[Z], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## `__bases__` lists with duplicate bases
|
||||
|
||||
```py
|
||||
class Foo(str, str): ... # error: 16 [duplicate-base] "Duplicate base class `str`"
|
||||
|
||||
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
|
||||
|
||||
class Spam: ...
|
||||
class Eggs: ...
|
||||
class Ham(
|
||||
Spam,
|
||||
Eggs,
|
||||
Spam, # error: [duplicate-base] "Duplicate base class `Spam`"
|
||||
Eggs, # error: [duplicate-base] "Duplicate base class `Eggs`"
|
||||
): ...
|
||||
|
||||
reveal_type(Ham.__mro__) # revealed: tuple[Literal[Ham], Unknown, Literal[object]]
|
||||
|
||||
class Mushrooms: ...
|
||||
class Omelette(Spam, Eggs, Mushrooms, Mushrooms): ... # error: [duplicate-base]
|
||||
|
||||
reveal_type(Omelette.__mro__) # revealed: tuple[Literal[Omelette], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## `__bases__` lists with duplicate `Unknown` bases
|
||||
|
||||
```py
|
||||
# error: [unresolved-import]
|
||||
# error: [unresolved-import]
|
||||
from does_not_exist import unknown_object_1, unknown_object_2
|
||||
|
||||
reveal_type(unknown_object_1) # revealed: Unknown
|
||||
reveal_type(unknown_object_2) # revealed: Unknown
|
||||
|
||||
# We *should* emit an error here to warn the user that we have no idea
|
||||
# what the MRO of this class should really be.
|
||||
# However, we don't complain about "duplicate base classes" here,
|
||||
# even though two classes are both inferred as being `Unknown`.
|
||||
#
|
||||
# (TODO: should we revisit this? Does it violate the gradual guarantee?
|
||||
# Should we just silently infer `[Foo, Unknown, object]` as the MRO here
|
||||
# without emitting any error at all? Not sure...)
|
||||
#
|
||||
# error: [inconsistent-mro] "Cannot create a consistent method resolution order (MRO) for class `Foo` with bases list `[Unknown, Unknown]`"
|
||||
class Foo(unknown_object_1, unknown_object_2): ...
|
||||
|
||||
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## Unrelated objects inferred as `Any`/`Unknown` do not have special `__mro__` attributes
|
||||
|
||||
```py
|
||||
from does_not_exist import unknown_object # error: [unresolved-import]
|
||||
|
||||
reveal_type(unknown_object) # revealed: Unknown
|
||||
reveal_type(unknown_object.__mro__) # revealed: Unknown
|
||||
```
|
||||
|
||||
## Classes that inherit from themselves
|
||||
|
||||
These are invalid, but we need to be able to handle them gracefully without panicking.
|
||||
|
||||
```pyi
|
||||
class Foo(Foo): ... # error: [cyclic-class-definition]
|
||||
|
||||
reveal_type(Foo) # revealed: Literal[Foo]
|
||||
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
|
||||
|
||||
class Bar: ...
|
||||
class Baz: ...
|
||||
class Boz(Bar, Baz, Boz): ... # error: [cyclic-class-definition]
|
||||
|
||||
reveal_type(Boz) # revealed: Literal[Boz]
|
||||
reveal_type(Boz.__mro__) # revealed: tuple[Literal[Boz], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## Classes with indirect cycles in their MROs
|
||||
|
||||
These are similarly unlikely, but we still shouldn't crash:
|
||||
|
||||
```pyi
|
||||
class Foo(Bar): ... # error: [cyclic-class-definition]
|
||||
class Bar(Baz): ... # error: [cyclic-class-definition]
|
||||
class Baz(Foo): ... # error: [cyclic-class-definition]
|
||||
|
||||
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
|
||||
reveal_type(Bar.__mro__) # revealed: tuple[Literal[Bar], Unknown, Literal[object]]
|
||||
reveal_type(Baz.__mro__) # revealed: tuple[Literal[Baz], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## Classes with cycles in their MROs, and multiple inheritance
|
||||
|
||||
```pyi
|
||||
class Spam: ...
|
||||
class Foo(Bar): ... # error: [cyclic-class-definition]
|
||||
class Bar(Baz): ... # error: [cyclic-class-definition]
|
||||
class Baz(Foo, Spam): ... # error: [cyclic-class-definition]
|
||||
|
||||
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
|
||||
reveal_type(Bar.__mro__) # revealed: tuple[Literal[Bar], Unknown, Literal[object]]
|
||||
reveal_type(Baz.__mro__) # revealed: tuple[Literal[Baz], Unknown, Literal[object]]
|
||||
```
|
||||
|
||||
## Classes with cycles in their MRO, and a sub-graph
|
||||
|
||||
```pyi
|
||||
class FooCycle(BarCycle): ... # error: [cyclic-class-definition]
|
||||
class Foo: ...
|
||||
class BarCycle(FooCycle): ... # error: [cyclic-class-definition]
|
||||
class Bar(Foo): ...
|
||||
|
||||
# Avoid emitting the errors for these. The classes have cyclic superclasses,
|
||||
# but are not themselves cyclic...
|
||||
class Baz(Bar, BarCycle): ...
|
||||
class Spam(Baz): ...
|
||||
|
||||
reveal_type(FooCycle.__mro__) # revealed: tuple[Literal[FooCycle], Unknown, Literal[object]]
|
||||
reveal_type(BarCycle.__mro__) # revealed: tuple[Literal[BarCycle], Unknown, Literal[object]]
|
||||
reveal_type(Baz.__mro__) # revealed: tuple[Literal[Baz], Unknown, Literal[object]]
|
||||
reveal_type(Spam.__mro__) # revealed: tuple[Literal[Spam], Unknown, Literal[object]]
|
||||
```
|
||||
@@ -1,47 +0,0 @@
|
||||
# Narrowing for nested conditionals
|
||||
|
||||
## Multiple negative contributions
|
||||
|
||||
```py
|
||||
def _(x: int):
|
||||
if x != 1:
|
||||
if x != 2:
|
||||
if x != 3:
|
||||
reveal_type(x) # revealed: int & ~Literal[1] & ~Literal[2] & ~Literal[3]
|
||||
```
|
||||
|
||||
## Multiple negative contributions with simplification
|
||||
|
||||
```py
|
||||
def _(flag1: bool, flag2: bool):
|
||||
x = 1 if flag1 else 2 if flag2 else 3
|
||||
|
||||
if x != 1:
|
||||
reveal_type(x) # revealed: Literal[2, 3]
|
||||
if x != 2:
|
||||
reveal_type(x) # revealed: Literal[3]
|
||||
```
|
||||
|
||||
## elif-else blocks
|
||||
|
||||
```py
|
||||
def _(flag1: bool, flag2: bool):
|
||||
x = 1 if flag1 else 2 if flag2 else 3
|
||||
|
||||
if x != 1:
|
||||
reveal_type(x) # revealed: Literal[2, 3]
|
||||
if x == 2:
|
||||
# TODO should be `Literal[2]`
|
||||
reveal_type(x) # revealed: Literal[2, 3]
|
||||
elif x == 3:
|
||||
reveal_type(x) # revealed: Literal[3]
|
||||
else:
|
||||
reveal_type(x) # revealed: Never
|
||||
|
||||
elif x != 2:
|
||||
# TODO should be Literal[1]
|
||||
reveal_type(x) # revealed: Literal[1, 3]
|
||||
else:
|
||||
# TODO should be Never
|
||||
reveal_type(x) # revealed: Literal[1, 2, 3]
|
||||
```
|
||||
@@ -1,91 +0,0 @@
|
||||
# Narrowing for `!=` conditionals
|
||||
|
||||
## `x != None`
|
||||
|
||||
```py
|
||||
def _(flag: bool):
|
||||
x = None if flag else 1
|
||||
|
||||
if x != None:
|
||||
reveal_type(x) # revealed: Literal[1]
|
||||
else:
|
||||
# TODO should be None
|
||||
reveal_type(x) # revealed: None | Literal[1]
|
||||
```
|
||||
|
||||
## `!=` for other singleton types
|
||||
|
||||
```py
|
||||
def _(flag: bool):
|
||||
x = True if flag else False
|
||||
|
||||
if x != False:
|
||||
reveal_type(x) # revealed: Literal[True]
|
||||
else:
|
||||
# TODO should be Literal[False]
|
||||
reveal_type(x) # revealed: bool
|
||||
```
|
||||
|
||||
## `x != y` where `y` is of literal type
|
||||
|
||||
```py
|
||||
def _(flag: bool):
|
||||
x = 1 if flag else 2
|
||||
|
||||
if x != 1:
|
||||
reveal_type(x) # revealed: Literal[2]
|
||||
```
|
||||
|
||||
## `x != y` where `y` is a single-valued type
|
||||
|
||||
```py
|
||||
def _(flag: bool):
|
||||
class A: ...
|
||||
class B: ...
|
||||
C = A if flag else B
|
||||
|
||||
if C != A:
|
||||
reveal_type(C) # revealed: Literal[B]
|
||||
else:
|
||||
# TODO should be Literal[A]
|
||||
reveal_type(C) # revealed: Literal[A, B]
|
||||
```
|
||||
|
||||
## `x != y` where `y` has multiple single-valued options
|
||||
|
||||
```py
|
||||
def _(flag1: bool, flag2: bool):
|
||||
x = 1 if flag1 else 2
|
||||
y = 2 if flag2 else 3
|
||||
|
||||
if x != y:
|
||||
reveal_type(x) # revealed: Literal[1, 2]
|
||||
else:
|
||||
# TODO should be Literal[2]
|
||||
reveal_type(x) # revealed: Literal[1, 2]
|
||||
```
|
||||
|
||||
## `!=` for non-single-valued types
|
||||
|
||||
Only single-valued types should narrow the type:
|
||||
|
||||
```py
|
||||
def _(flag: bool, a: int, y: int):
|
||||
x = a if flag else None
|
||||
|
||||
if x != y:
|
||||
reveal_type(x) # revealed: int | None
|
||||
```
|
||||
|
||||
## Mix of single-valued and non-single-valued types
|
||||
|
||||
```py
|
||||
def _(flag1: bool, flag2: bool, a: int):
|
||||
x = 1 if flag1 else 2
|
||||
y = 2 if flag2 else a
|
||||
|
||||
if x != y:
|
||||
reveal_type(x) # revealed: Literal[1, 2]
|
||||
else:
|
||||
reveal_type(x) # revealed: Literal[1, 2]
|
||||
```
|
||||
@@ -1,25 +0,0 @@
|
||||
# Protocols
|
||||
|
||||
We do not support protocols yet, but to avoid false positives, we *partially* support some known
|
||||
protocols.
|
||||
|
||||
## `typing.SupportsIndex`
|
||||
|
||||
```py
|
||||
from typing import SupportsIndex, Literal
|
||||
|
||||
def _(some_int: int, some_literal_int: Literal[1], some_indexable: SupportsIndex):
|
||||
a: SupportsIndex = some_int
|
||||
b: SupportsIndex = some_literal_int
|
||||
c: SupportsIndex = some_indexable
|
||||
```
|
||||
|
||||
## Invalid
|
||||
|
||||
```py
|
||||
from typing import Protocol
|
||||
|
||||
# error: [invalid-type-form] "`typing.Protocol` is not allowed in type expressions"
|
||||
def f(x: Protocol) -> None:
|
||||
reveal_type(x) # revealed: Unknown
|
||||
```
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: basic.md - Structures - Unresolvable module import
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/import/basic.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | import zqzqzqzqzqzqzq # error: [unresolved-import] "Cannot resolve import `zqzqzqzqzqzqzq`"
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:unresolved-import
|
||||
--> /src/mdtest_snippet.py:1:8
|
||||
|
|
||||
1 | import zqzqzqzqzqzqzq # error: [unresolved-import] "Cannot resolve import `zqzqzqzqzqzqzq`"
|
||||
| ^^^^^^^^^^^^^^ Cannot resolve import `zqzqzqzqzqzqzq`
|
||||
|
|
||||
|
||||
```
|
||||
@@ -1,32 +0,0 @@
|
||||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: for.md - For loops - Invalid iterable
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/loops/for.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | nonsense = 123
|
||||
2 | for x in nonsense: # error: [not-iterable]
|
||||
3 | pass
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:not-iterable
|
||||
--> /src/mdtest_snippet.py:2:10
|
||||
|
|
||||
1 | nonsense = 123
|
||||
2 | for x in nonsense: # error: [not-iterable]
|
||||
| ^^^^^^^^ Object of type `Literal[123]` is not iterable because it doesn't have an `__iter__` method or a `__getitem__` method
|
||||
3 | pass
|
||||
|
|
||||
|
||||
```
|
||||
@@ -1,40 +0,0 @@
|
||||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: invalid_argument_type.md - Invalid argument type diagnostics - Basic
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/invalid_argument_type.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | def foo(x: int) -> int:
|
||||
2 | return x * x
|
||||
3 |
|
||||
4 | foo("hello") # error: [invalid-argument-type]
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:invalid-argument-type
|
||||
--> /src/mdtest_snippet.py:4:5
|
||||
|
|
||||
2 | return x * x
|
||||
3 |
|
||||
4 | foo("hello") # error: [invalid-argument-type]
|
||||
| ^^^^^^^ Object of type `Literal["hello"]` cannot be assigned to parameter 1 (`x`) of function `foo`; expected type `int`
|
||||
|
|
||||
info
|
||||
--> /src/mdtest_snippet.py:1:9
|
||||
|
|
||||
1 | def foo(x: int) -> int:
|
||||
| ------ parameter declared in function definition here
|
||||
2 | return x * x
|
||||
|
|
||||
|
||||
```
|
||||
@@ -1,81 +0,0 @@
|
||||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: invalid_argument_type.md - Invalid argument type diagnostics - Many parameters with multiple invalid arguments
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/invalid_argument_type.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | def foo(x: int, y: int, z: int) -> int:
|
||||
2 | return x * y * z
|
||||
3 |
|
||||
4 | # error: [invalid-argument-type]
|
||||
5 | # error: [invalid-argument-type]
|
||||
6 | # error: [invalid-argument-type]
|
||||
7 | foo("a", "b", "c")
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:invalid-argument-type
|
||||
--> /src/mdtest_snippet.py:7:5
|
||||
|
|
||||
5 | # error: [invalid-argument-type]
|
||||
6 | # error: [invalid-argument-type]
|
||||
7 | foo("a", "b", "c")
|
||||
| ^^^ Object of type `Literal["a"]` cannot be assigned to parameter 1 (`x`) of function `foo`; expected type `int`
|
||||
|
|
||||
info
|
||||
--> /src/mdtest_snippet.py:1:9
|
||||
|
|
||||
1 | def foo(x: int, y: int, z: int) -> int:
|
||||
| ------ parameter declared in function definition here
|
||||
2 | return x * y * z
|
||||
|
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
error: lint:invalid-argument-type
|
||||
--> /src/mdtest_snippet.py:7:10
|
||||
|
|
||||
5 | # error: [invalid-argument-type]
|
||||
6 | # error: [invalid-argument-type]
|
||||
7 | foo("a", "b", "c")
|
||||
| ^^^ Object of type `Literal["b"]` cannot be assigned to parameter 2 (`y`) of function `foo`; expected type `int`
|
||||
|
|
||||
info
|
||||
--> /src/mdtest_snippet.py:1:17
|
||||
|
|
||||
1 | def foo(x: int, y: int, z: int) -> int:
|
||||
| ------ parameter declared in function definition here
|
||||
2 | return x * y * z
|
||||
|
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
error: lint:invalid-argument-type
|
||||
--> /src/mdtest_snippet.py:7:15
|
||||
|
|
||||
5 | # error: [invalid-argument-type]
|
||||
6 | # error: [invalid-argument-type]
|
||||
7 | foo("a", "b", "c")
|
||||
| ^^^ Object of type `Literal["c"]` cannot be assigned to parameter 3 (`z`) of function `foo`; expected type `int`
|
||||
|
|
||||
info
|
||||
--> /src/mdtest_snippet.py:1:25
|
||||
|
|
||||
1 | def foo(x: int, y: int, z: int) -> int:
|
||||
| ------ parameter declared in function definition here
|
||||
2 | return x * y * z
|
||||
|
|
||||
|
||||
```
|
||||
@@ -1,95 +0,0 @@
|
||||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: return_type.md - Function return type - Invalid return type
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/function/return_type.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | # error: [invalid-return-type]
|
||||
2 | def f() -> int:
|
||||
3 | 1
|
||||
4 |
|
||||
5 | def f() -> str:
|
||||
6 | # error: [invalid-return-type]
|
||||
7 | return 1
|
||||
8 |
|
||||
9 | def f() -> int:
|
||||
10 | # error: [invalid-return-type]
|
||||
11 | return
|
||||
12 |
|
||||
13 | from typing import TypeVar
|
||||
14 |
|
||||
15 | T = TypeVar("T")
|
||||
16 |
|
||||
17 | # TODO: `invalid-return-type` error should be emitted
|
||||
18 | def m(x: T) -> T: ...
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:invalid-return-type
|
||||
--> /src/mdtest_snippet.py:2:12
|
||||
|
|
||||
1 | # error: [invalid-return-type]
|
||||
2 | def f() -> int:
|
||||
| ^^^ Function can implicitly return `None`, which is not assignable to return type `int`
|
||||
3 | 1
|
||||
|
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
error: lint:invalid-return-type
|
||||
--> /src/mdtest_snippet.py:7:12
|
||||
|
|
||||
5 | def f() -> str:
|
||||
6 | # error: [invalid-return-type]
|
||||
7 | return 1
|
||||
| ^ Object of type `Literal[1]` is not assignable to return type `str`
|
||||
8 |
|
||||
9 | def f() -> int:
|
||||
|
|
||||
info
|
||||
--> /src/mdtest_snippet.py:5:12
|
||||
|
|
||||
3 | 1
|
||||
4 |
|
||||
5 | def f() -> str:
|
||||
| --- Return type is declared here as `str`
|
||||
6 | # error: [invalid-return-type]
|
||||
7 | return 1
|
||||
|
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
error: lint:invalid-return-type
|
||||
--> /src/mdtest_snippet.py:11:5
|
||||
|
|
||||
9 | def f() -> int:
|
||||
10 | # error: [invalid-return-type]
|
||||
11 | return
|
||||
| ^^^^^^ Object of type `None` is not assignable to return type `int`
|
||||
12 |
|
||||
13 | from typing import TypeVar
|
||||
|
|
||||
info
|
||||
--> /src/mdtest_snippet.py:9:12
|
||||
|
|
||||
7 | return 1
|
||||
8 |
|
||||
9 | def f() -> int:
|
||||
| --- Return type is declared here as `int`
|
||||
10 | # error: [invalid-return-type]
|
||||
11 | return
|
||||
|
|
||||
|
||||
```
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: unpacking.md - Unpacking - Right hand side not iterable
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unpacking.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | a, b = 1 # error: [not-iterable]
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:not-iterable
|
||||
--> /src/mdtest_snippet.py:1:8
|
||||
|
|
||||
1 | a, b = 1 # error: [not-iterable]
|
||||
| ^ Object of type `Literal[1]` is not iterable because it doesn't have an `__iter__` method or a `__getitem__` method
|
||||
|
|
||||
|
||||
```
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: unpacking.md - Unpacking - Too few values to unpack
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unpacking.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | a, b = (1,) # error: [invalid-assignment]
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:invalid-assignment
|
||||
--> /src/mdtest_snippet.py:1:1
|
||||
|
|
||||
1 | a, b = (1,) # error: [invalid-assignment]
|
||||
| ^^^^ Not enough values to unpack (expected 2, got 1)
|
||||
|
|
||||
|
||||
```
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
source: crates/red_knot_test/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
---
|
||||
mdtest name: unpacking.md - Unpacking - Too many values to unpack
|
||||
mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unpacking.md
|
||||
---
|
||||
|
||||
# Python source files
|
||||
|
||||
## mdtest_snippet.py
|
||||
|
||||
```
|
||||
1 | a, b = (1, 2, 3) # error: [invalid-assignment]
|
||||
```
|
||||
|
||||
# Diagnostics
|
||||
|
||||
```
|
||||
error: lint:invalid-assignment
|
||||
--> /src/mdtest_snippet.py:1:1
|
||||
|
|
||||
1 | a, b = (1, 2, 3) # error: [invalid-assignment]
|
||||
| ^^^^ Too many values to unpack (expected 2, got 3)
|
||||
|
|
||||
|
||||
```
|
||||
@@ -1,191 +0,0 @@
|
||||
# Suppressing errors with `knot: ignore`
|
||||
|
||||
Type check errors can be suppressed by a `knot: ignore` comment on the same line as the violation.
|
||||
|
||||
## Simple `knot: ignore`
|
||||
|
||||
```py
|
||||
a = 4 + test # knot: ignore
|
||||
```
|
||||
|
||||
## Suppressing a specific code
|
||||
|
||||
```py
|
||||
a = 4 + test # knot: ignore[unresolved-reference]
|
||||
```
|
||||
|
||||
## Unused suppression
|
||||
|
||||
```py
|
||||
test = 10
|
||||
# error: [unused-ignore-comment] "Unused `knot: ignore` directive: 'possibly-unresolved-reference'"
|
||||
a = test + 3 # knot: ignore[possibly-unresolved-reference]
|
||||
```
|
||||
|
||||
## Unused suppression if the error codes don't match
|
||||
|
||||
```py
|
||||
# error: [unresolved-reference]
|
||||
# error: [unused-ignore-comment] "Unused `knot: ignore` directive: 'possibly-unresolved-reference'"
|
||||
a = test + 3 # knot: ignore[possibly-unresolved-reference]
|
||||
```
|
||||
|
||||
## Suppressed unused comment
|
||||
|
||||
```py
|
||||
# error: [unused-ignore-comment]
|
||||
a = 10 / 2 # knot: ignore[division-by-zero]
|
||||
a = 10 / 2 # knot: ignore[division-by-zero, unused-ignore-comment]
|
||||
a = 10 / 2 # knot: ignore[unused-ignore-comment, division-by-zero]
|
||||
a = 10 / 2 # knot: ignore[unused-ignore-comment] # type: ignore
|
||||
a = 10 / 2 # type: ignore # knot: ignore[unused-ignore-comment]
|
||||
```
|
||||
|
||||
## Unused ignore comment
|
||||
|
||||
```py
|
||||
# error: [unused-ignore-comment] "Unused `knot: ignore` directive: 'unused-ignore-comment'"
|
||||
a = 10 / 0 # knot: ignore[division-by-zero, unused-ignore-comment]
|
||||
```
|
||||
|
||||
## Multiple unused comments
|
||||
|
||||
Today, Red Knot emits a diagnostic for every unused code. We might want to group the codes by
|
||||
comment at some point in the future.
|
||||
|
||||
```py
|
||||
# error: [unused-ignore-comment] "Unused `knot: ignore` directive: 'division-by-zero'"
|
||||
# error: [unused-ignore-comment] "Unused `knot: ignore` directive: 'unresolved-reference'"
|
||||
a = 10 / 2 # knot: ignore[division-by-zero, unresolved-reference]
|
||||
|
||||
# error: [unused-ignore-comment] "Unused `knot: ignore` directive: 'invalid-assignment'"
|
||||
# error: [unused-ignore-comment] "Unused `knot: ignore` directive: 'unresolved-reference'"
|
||||
a = 10 / 0 # knot: ignore[invalid-assignment, division-by-zero, unresolved-reference]
|
||||
```
|
||||
|
||||
## Multiple suppressions
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
def test(a: f"f-string type annotation", b: b"byte-string-type-annotation"): ... # knot: ignore[fstring-type-annotation, byte-string-type-annotation]
|
||||
```
|
||||
|
||||
## Can't suppress syntax errors
|
||||
|
||||
<!-- blacken-docs:off -->
|
||||
|
||||
```py
|
||||
# error: [invalid-syntax]
|
||||
# error: [unused-ignore-comment]
|
||||
def test($): # knot: ignore
|
||||
pass
|
||||
```
|
||||
|
||||
<!-- blacken-docs:on -->
|
||||
|
||||
## Can't suppress `revealed-type` diagnostics
|
||||
|
||||
```py
|
||||
a = 10
|
||||
# revealed: Literal[10]
|
||||
# error: [unknown-rule] "Unknown rule `revealed-type`"
|
||||
reveal_type(a) # knot: ignore[revealed-type]
|
||||
```
|
||||
|
||||
## Extra whitespace in type ignore comments is allowed
|
||||
|
||||
```py
|
||||
a = 10 / 0 # knot : ignore
|
||||
a = 10 / 0 # knot: ignore [ division-by-zero ]
|
||||
```
|
||||
|
||||
## Whitespace is optional
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
a = 10 / 0 #knot:ignore[division-by-zero]
|
||||
```
|
||||
|
||||
## Trailing codes comma
|
||||
|
||||
Trailing commas in the codes section are allowed:
|
||||
|
||||
```py
|
||||
a = 10 / 0 # knot: ignore[division-by-zero,]
|
||||
```
|
||||
|
||||
## Invalid characters in codes
|
||||
|
||||
```py
|
||||
# error: [division-by-zero]
|
||||
# error: [invalid-ignore-comment] "Invalid `knot: ignore` comment: expected a alphanumeric character or `-` or `_` as code"
|
||||
a = 10 / 0 # knot: ignore[*-*]
|
||||
```
|
||||
|
||||
## Trailing whitespace
|
||||
|
||||
<!-- blacken-docs:off -->
|
||||
|
||||
```py
|
||||
a = 10 / 0 # knot: ignore[division-by-zero]
|
||||
# ^^^^^^ trailing whitespace
|
||||
```
|
||||
|
||||
<!-- blacken-docs:on -->
|
||||
|
||||
## Missing comma
|
||||
|
||||
A missing comma results in an invalid suppression comment. We may want to recover from this in the
|
||||
future.
|
||||
|
||||
```py
|
||||
# error: [unresolved-reference]
|
||||
# error: [invalid-ignore-comment] "Invalid `knot: ignore` comment: expected a comma separating the rule codes"
|
||||
a = x / 0 # knot: ignore[division-by-zero unresolved-reference]
|
||||
```
|
||||
|
||||
## Missing closing bracket
|
||||
|
||||
```py
|
||||
# error: [unresolved-reference] "Name `x` used when not defined"
|
||||
# error: [invalid-ignore-comment] "Invalid `knot: ignore` comment: expected a comma separating the rule codes"
|
||||
a = x / 2 # knot: ignore[unresolved-reference
|
||||
```
|
||||
|
||||
## Empty codes
|
||||
|
||||
An empty codes array suppresses no-diagnostics and is always useless
|
||||
|
||||
```py
|
||||
# error: [division-by-zero]
|
||||
# error: [unused-ignore-comment] "Unused `knot: ignore` without a code"
|
||||
a = 4 / 0 # knot: ignore[]
|
||||
```
|
||||
|
||||
## File-level suppression comments
|
||||
|
||||
File level suppression comments are currently intentionally unsupported because we've yet to decide
|
||||
if they should use a different syntax that also supports enabling rules or changing the rule's
|
||||
severity: `knot: possibly-undefined-reference=error`
|
||||
|
||||
```py
|
||||
# error: [unused-ignore-comment]
|
||||
# knot: ignore[division-by-zero]
|
||||
|
||||
a = 4 / 0 # error: [division-by-zero]
|
||||
```
|
||||
|
||||
## Unknown rule
|
||||
|
||||
```py
|
||||
# error: [unknown-rule] "Unknown rule `is-equal-14`"
|
||||
a = 10 + 4 # knot: ignore[is-equal-14]
|
||||
```
|
||||
|
||||
## Code with `lint:` prefix
|
||||
|
||||
```py
|
||||
# error:[unknown-rule] "Unknown rule `lint:division-by-zero`. Did you mean `division-by-zero`?"
|
||||
# error: [division-by-zero]
|
||||
a = 10 / 0 # knot: ignore[lint:division-by-zero]
|
||||
```
|
||||
@@ -1,37 +0,0 @@
|
||||
use crate::{
|
||||
semantic_index::{ast_ids::ScopedExpressionId, expression::Expression},
|
||||
unpack::Unpack,
|
||||
};
|
||||
|
||||
use ruff_python_ast::name::Name;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
/// Describes an (annotated) attribute assignment that we discovered in a method
|
||||
/// body, typically of the form `self.x: int`, `self.x: int = …` or `self.x = …`.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, salsa::Update)]
|
||||
pub(crate) enum AttributeAssignment<'db> {
|
||||
/// An attribute assignment with an explicit type annotation, either
|
||||
/// `self.x: <annotation>` or `self.x: <annotation> = …`.
|
||||
Annotated { annotation: Expression<'db> },
|
||||
|
||||
/// An attribute assignment without a type annotation, e.g. `self.x = <value>`.
|
||||
Unannotated { value: Expression<'db> },
|
||||
|
||||
/// An attribute assignment where the right-hand side is an iterable, for example
|
||||
/// `for self.x in <iterable>`.
|
||||
Iterable { iterable: Expression<'db> },
|
||||
|
||||
/// An attribute assignment where the expression to be assigned is a context manager, for example
|
||||
/// `with <context_manager> as self.x`.
|
||||
ContextManager { context_manager: Expression<'db> },
|
||||
|
||||
/// An attribute assignment where the left-hand side is an unpacking expression,
|
||||
/// e.g. `self.x, self.y = <value>`.
|
||||
Unpack {
|
||||
attribute_expression_id: ScopedExpressionId,
|
||||
unpack: Unpack<'db>,
|
||||
},
|
||||
}
|
||||
|
||||
pub(crate) type AttributeAssignments<'db> = FxHashMap<Name, Vec<AttributeAssignment<'db>>>;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,223 +0,0 @@
|
||||
use std::fmt;
|
||||
|
||||
use drop_bomb::DebugDropBomb;
|
||||
use ruff_db::{
|
||||
diagnostic::{
|
||||
Annotation, Diagnostic, DiagnosticId, OldSecondaryDiagnosticMessage, Severity, Span,
|
||||
},
|
||||
files::File,
|
||||
};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use super::{binding_type, Type, TypeCheckDiagnostics};
|
||||
|
||||
use crate::semantic_index::symbol::ScopeId;
|
||||
use crate::{
|
||||
lint::{LintId, LintMetadata},
|
||||
suppression::suppressions,
|
||||
Db,
|
||||
};
|
||||
use crate::{semantic_index::semantic_index, types::FunctionDecorators};
|
||||
|
||||
/// Context for inferring the types of a single file.
|
||||
///
|
||||
/// One context exists for at least for every inferred region but it's
|
||||
/// possible that inferring a sub-region, like an unpack assignment, creates
|
||||
/// a sub-context.
|
||||
///
|
||||
/// Tracks the reported diagnostics of the inferred region.
|
||||
///
|
||||
/// ## Consuming
|
||||
/// It's important that the context is explicitly consumed before dropping by calling
|
||||
/// [`InferContext::finish`] and the returned diagnostics must be stored
|
||||
/// on the current [`TypeInference`](super::infer::TypeInference) result.
|
||||
pub(crate) struct InferContext<'db> {
|
||||
db: &'db dyn Db,
|
||||
scope: ScopeId<'db>,
|
||||
file: File,
|
||||
diagnostics: std::cell::RefCell<TypeCheckDiagnostics>,
|
||||
no_type_check: InNoTypeCheck,
|
||||
bomb: DebugDropBomb,
|
||||
}
|
||||
|
||||
impl<'db> InferContext<'db> {
|
||||
pub(crate) fn new(db: &'db dyn Db, scope: ScopeId<'db>) -> Self {
|
||||
Self {
|
||||
db,
|
||||
scope,
|
||||
file: scope.file(db),
|
||||
diagnostics: std::cell::RefCell::new(TypeCheckDiagnostics::default()),
|
||||
no_type_check: InNoTypeCheck::default(),
|
||||
bomb: DebugDropBomb::new("`InferContext` needs to be explicitly consumed by calling `::finish` to prevent accidental loss of diagnostics."),
|
||||
}
|
||||
}
|
||||
|
||||
/// The file for which the types are inferred.
|
||||
pub(crate) fn file(&self) -> File {
|
||||
self.file
|
||||
}
|
||||
|
||||
pub(crate) fn db(&self) -> &'db dyn Db {
|
||||
self.db
|
||||
}
|
||||
|
||||
pub(crate) fn extend(&mut self, other: &TypeCheckDiagnostics) {
|
||||
self.diagnostics.get_mut().extend(other);
|
||||
}
|
||||
|
||||
/// Reports a lint located at `ranged`.
|
||||
pub(super) fn report_lint<T>(
|
||||
&self,
|
||||
lint: &'static LintMetadata,
|
||||
ranged: T,
|
||||
message: fmt::Arguments,
|
||||
) where
|
||||
T: Ranged,
|
||||
{
|
||||
self.report_lint_with_secondary_messages(lint, ranged, message, &[]);
|
||||
}
|
||||
|
||||
/// Reports a lint located at `ranged`.
|
||||
pub(super) fn report_lint_with_secondary_messages<T>(
|
||||
&self,
|
||||
lint: &'static LintMetadata,
|
||||
ranged: T,
|
||||
message: fmt::Arguments,
|
||||
secondary_messages: &[OldSecondaryDiagnosticMessage],
|
||||
) where
|
||||
T: Ranged,
|
||||
{
|
||||
fn lint_severity(
|
||||
context: &InferContext,
|
||||
lint: &'static LintMetadata,
|
||||
range: TextRange,
|
||||
) -> Option<Severity> {
|
||||
if !context.db.is_file_open(context.file) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Skip over diagnostics if the rule is disabled.
|
||||
let severity = context.db.rule_selection().severity(LintId::of(lint))?;
|
||||
|
||||
if context.is_in_no_type_check() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let suppressions = suppressions(context.db, context.file);
|
||||
|
||||
if let Some(suppression) = suppressions.find_suppression(range, LintId::of(lint)) {
|
||||
context.diagnostics.borrow_mut().mark_used(suppression.id());
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(severity)
|
||||
}
|
||||
|
||||
let Some(severity) = lint_severity(self, lint, ranged.range()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
self.report_diagnostic(
|
||||
ranged,
|
||||
DiagnosticId::Lint(lint.name()),
|
||||
severity,
|
||||
message,
|
||||
secondary_messages,
|
||||
);
|
||||
}
|
||||
|
||||
/// Adds a new diagnostic.
|
||||
///
|
||||
/// The diagnostic does not get added if the rule isn't enabled for this file.
|
||||
pub(super) fn report_diagnostic<T>(
|
||||
&self,
|
||||
ranged: T,
|
||||
id: DiagnosticId,
|
||||
severity: Severity,
|
||||
message: fmt::Arguments,
|
||||
secondary_messages: &[OldSecondaryDiagnosticMessage],
|
||||
) where
|
||||
T: Ranged,
|
||||
{
|
||||
if !self.db.is_file_open(self.file) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Don't emit the diagnostic if:
|
||||
// * The enclosing node contains any syntax errors
|
||||
// * The rule is disabled for this file. We probably want to introduce a new query that
|
||||
// returns a rule selector for a given file that respects the package's settings,
|
||||
// any global pragma comments in the file, and any per-file-ignores.
|
||||
|
||||
let mut diag = Diagnostic::new(id, severity, "");
|
||||
for secondary_msg in secondary_messages {
|
||||
diag.sub(secondary_msg.to_sub_diagnostic());
|
||||
}
|
||||
let span = Span::from(self.file).with_range(ranged.range());
|
||||
diag.annotate(Annotation::primary(span).message(message));
|
||||
self.diagnostics.borrow_mut().push(diag);
|
||||
}
|
||||
|
||||
pub(super) fn set_in_no_type_check(&mut self, no_type_check: InNoTypeCheck) {
|
||||
self.no_type_check = no_type_check;
|
||||
}
|
||||
|
||||
fn is_in_no_type_check(&self) -> bool {
|
||||
match self.no_type_check {
|
||||
InNoTypeCheck::Possibly => {
|
||||
// Accessing the semantic index here is fine because
|
||||
// the index belongs to the same file as for which we emit the diagnostic.
|
||||
let index = semantic_index(self.db, self.file);
|
||||
|
||||
let scope_id = self.scope.file_scope_id(self.db);
|
||||
|
||||
// Inspect all ancestor function scopes by walking bottom up and infer the function's type.
|
||||
let mut function_scope_tys = index
|
||||
.ancestor_scopes(scope_id)
|
||||
.filter_map(|(_, scope)| scope.node().as_function())
|
||||
.map(|node| binding_type(self.db, index.expect_single_definition(node)))
|
||||
.filter_map(Type::into_function_literal);
|
||||
|
||||
// Iterate over all functions and test if any is decorated with `@no_type_check`.
|
||||
function_scope_tys.any(|function_ty| {
|
||||
function_ty.has_known_decorator(self.db, FunctionDecorators::NO_TYPE_CHECK)
|
||||
})
|
||||
}
|
||||
InNoTypeCheck::Yes => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Are we currently inferring types in a stub file?
|
||||
pub(crate) fn in_stub(&self) -> bool {
|
||||
self.file.is_stub(self.db().upcast())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn finish(mut self) -> TypeCheckDiagnostics {
|
||||
self.bomb.defuse();
|
||||
let mut diagnostics = self.diagnostics.into_inner();
|
||||
diagnostics.shrink_to_fit();
|
||||
diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for InferContext<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("TyContext")
|
||||
.field("file", &self.file)
|
||||
.field("diagnostics", &self.diagnostics)
|
||||
.field("defused", &self.bomb)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub(crate) enum InNoTypeCheck {
|
||||
/// The inference might be in a `no_type_check` block but only if any
|
||||
/// ancestor function is decorated with `@no_type_check`.
|
||||
#[default]
|
||||
Possibly,
|
||||
|
||||
/// The inference is known to be in an `@no_type_check` decorated function.
|
||||
Yes,
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
use ruff_python_ast as ast;
|
||||
|
||||
use crate::semantic_index::SemanticIndex;
|
||||
use crate::types::signatures::{Parameter, Parameters, Signature};
|
||||
use crate::types::{
|
||||
declaration_type, KnownInstanceType, Type, TypeVarBoundOrConstraints, TypeVarInstance,
|
||||
UnionType,
|
||||
};
|
||||
use crate::Db;
|
||||
|
||||
/// A list of formal type variables for a generic function, class, or type alias.
|
||||
#[salsa::tracked(debug)]
|
||||
pub struct GenericContext<'db> {
|
||||
#[return_ref]
|
||||
pub(crate) variables: Box<[TypeVarInstance<'db>]>,
|
||||
}
|
||||
|
||||
impl<'db> GenericContext<'db> {
|
||||
pub(crate) fn from_type_params(
|
||||
db: &'db dyn Db,
|
||||
index: &'db SemanticIndex<'db>,
|
||||
type_params_node: &ast::TypeParams,
|
||||
) -> Self {
|
||||
let variables = type_params_node
|
||||
.iter()
|
||||
.filter_map(|type_param| Self::variable_from_type_param(db, index, type_param))
|
||||
.collect();
|
||||
Self::new(db, variables)
|
||||
}
|
||||
|
||||
fn variable_from_type_param(
|
||||
db: &'db dyn Db,
|
||||
index: &'db SemanticIndex<'db>,
|
||||
type_param_node: &ast::TypeParam,
|
||||
) -> Option<TypeVarInstance<'db>> {
|
||||
match type_param_node {
|
||||
ast::TypeParam::TypeVar(node) => {
|
||||
let definition = index.expect_single_definition(node);
|
||||
let Type::KnownInstance(KnownInstanceType::TypeVar(typevar)) =
|
||||
declaration_type(db, definition).inner_type()
|
||||
else {
|
||||
panic!("typevar should be inferred as a TypeVarInstance");
|
||||
};
|
||||
Some(typevar)
|
||||
}
|
||||
// TODO: Support these!
|
||||
ast::TypeParam::ParamSpec(_) => None,
|
||||
ast::TypeParam::TypeVarTuple(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn signature(self, db: &'db dyn Db) -> Signature<'db> {
|
||||
let parameters = Parameters::new(
|
||||
self.variables(db)
|
||||
.iter()
|
||||
.map(|typevar| Self::parameter_from_typevar(db, *typevar)),
|
||||
);
|
||||
Signature::new(parameters, None)
|
||||
}
|
||||
|
||||
fn parameter_from_typevar(db: &'db dyn Db, typevar: TypeVarInstance<'db>) -> Parameter<'db> {
|
||||
let mut parameter = Parameter::positional_only(Some(typevar.name(db).clone()));
|
||||
match typevar.bound_or_constraints(db) {
|
||||
Some(TypeVarBoundOrConstraints::UpperBound(bound)) => {
|
||||
// TODO: This should be a type form.
|
||||
parameter = parameter.with_annotated_type(bound);
|
||||
}
|
||||
Some(TypeVarBoundOrConstraints::Constraints(constraints)) => {
|
||||
// TODO: This should be a new type variant where only these exact types are
|
||||
// assignable, and not subclasses of them, nor a union of them.
|
||||
parameter = parameter
|
||||
.with_annotated_type(UnionType::from_elements(db, constraints.iter(db)));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
parameter
|
||||
}
|
||||
|
||||
pub(crate) fn default_specialization(self, db: &'db dyn Db) -> Specialization<'db> {
|
||||
let types = self
|
||||
.variables(db)
|
||||
.iter()
|
||||
.map(|typevar| typevar.default_ty(db).unwrap_or(Type::unknown()))
|
||||
.collect();
|
||||
self.specialize(db, types)
|
||||
}
|
||||
|
||||
pub(crate) fn unknown_specialization(self, db: &'db dyn Db) -> Specialization<'db> {
|
||||
let types = vec![Type::unknown(); self.variables(db).len()];
|
||||
self.specialize(db, types.into())
|
||||
}
|
||||
|
||||
pub(crate) fn specialize(
|
||||
self,
|
||||
db: &'db dyn Db,
|
||||
types: Box<[Type<'db>]>,
|
||||
) -> Specialization<'db> {
|
||||
Specialization::new(db, self, types)
|
||||
}
|
||||
}
|
||||
|
||||
/// An assignment of a specific type to each type variable in a generic scope.
|
||||
#[salsa::tracked(debug)]
|
||||
pub struct Specialization<'db> {
|
||||
pub(crate) generic_context: GenericContext<'db>,
|
||||
#[return_ref]
|
||||
pub(crate) types: Box<[Type<'db>]>,
|
||||
}
|
||||
|
||||
impl<'db> Specialization<'db> {
|
||||
/// Applies a specialization to this specialization. This is used, for instance, when a generic
|
||||
/// class inherits from a generic alias:
|
||||
///
|
||||
/// ```py
|
||||
/// class A[T]: ...
|
||||
/// class B[U](A[U]): ...
|
||||
/// ```
|
||||
///
|
||||
/// `B` is a generic class, whose MRO includes the generic alias `A[U]`, which specializes `A`
|
||||
/// with the specialization `{T: U}`. If `B` is specialized to `B[int]`, with specialization
|
||||
/// `{U: int}`, we can apply the second specialization to the first, resulting in `T: int`.
|
||||
/// That lets us produce the generic alias `A[int]`, which is the corresponding entry in the
|
||||
/// MRO of `B[int]`.
|
||||
pub(crate) fn apply_specialization(self, db: &'db dyn Db, other: Specialization<'db>) -> Self {
|
||||
let types = self
|
||||
.types(db)
|
||||
.into_iter()
|
||||
.map(|ty| ty.apply_specialization(db, other))
|
||||
.collect();
|
||||
Specialization::new(db, self.generic_context(db), types)
|
||||
}
|
||||
|
||||
pub(crate) fn normalized(self, db: &'db dyn Db) -> Self {
|
||||
let types = self.types(db).iter().map(|ty| ty.normalized(db)).collect();
|
||||
Self::new(db, self.generic_context(db), types)
|
||||
}
|
||||
|
||||
/// Returns the type that a typevar is specialized to, or None if the typevar isn't part of
|
||||
/// this specialization.
|
||||
pub(crate) fn get(self, db: &'db dyn Db, typevar: TypeVarInstance<'db>) -> Option<Type<'db>> {
|
||||
self.generic_context(db)
|
||||
.variables(db)
|
||||
.into_iter()
|
||||
.zip(self.types(db))
|
||||
.find(|(var, _)| **var == typevar)
|
||||
.map(|(_, ty)| *ty)
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
use crate::symbol::SymbolAndQualifiers;
|
||||
|
||||
use super::{ClassBase, Db, KnownClass, MemberLookupPolicy, Type};
|
||||
|
||||
/// A type that represents `type[C]`, i.e. the class object `C` and class objects that are subclasses of `C`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Update)]
|
||||
pub struct SubclassOfType<'db> {
|
||||
// Keep this field private, so that the only way of constructing the struct is through the `from` method.
|
||||
subclass_of: ClassBase<'db>,
|
||||
}
|
||||
|
||||
impl<'db> SubclassOfType<'db> {
|
||||
/// Construct a new [`Type`] instance representing a given class object (or a given dynamic type)
|
||||
/// and all possible subclasses of that class object/dynamic type.
|
||||
///
|
||||
/// 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::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.
|
||||
pub(crate) fn from(db: &'db dyn Db, subclass_of: impl Into<ClassBase<'db>>) -> Type<'db> {
|
||||
let subclass_of = subclass_of.into();
|
||||
match subclass_of {
|
||||
ClassBase::Dynamic(_) => Type::SubclassOf(Self { subclass_of }),
|
||||
ClassBase::Class(class) => {
|
||||
if class.is_final(db) {
|
||||
Type::from(class)
|
||||
} else if class.is_object(db) {
|
||||
KnownClass::Type.to_instance(db)
|
||||
} else {
|
||||
Type::SubclassOf(Self { subclass_of })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a [`Type`] instance representing the type `type[Unknown]`.
|
||||
pub(crate) const fn subclass_of_unknown() -> Type<'db> {
|
||||
Type::SubclassOf(SubclassOfType {
|
||||
subclass_of: ClassBase::unknown(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Return a [`Type`] instance representing the type `type[Any]`.
|
||||
pub(crate) const fn subclass_of_any() -> Type<'db> {
|
||||
Type::SubclassOf(SubclassOfType {
|
||||
subclass_of: ClassBase::any(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the inner [`ClassBase`] value wrapped by this `SubclassOfType`.
|
||||
pub(crate) const fn subclass_of(self) -> ClassBase<'db> {
|
||||
self.subclass_of
|
||||
}
|
||||
|
||||
pub(crate) const fn is_dynamic(self) -> bool {
|
||||
// Unpack `self` so that we're forced to update this method if any more fields are added in the future.
|
||||
let Self { subclass_of } = self;
|
||||
subclass_of.is_dynamic()
|
||||
}
|
||||
|
||||
pub(crate) const fn is_fully_static(self) -> bool {
|
||||
!self.is_dynamic()
|
||||
}
|
||||
|
||||
pub(crate) fn find_name_in_mro_with_policy(
|
||||
self,
|
||||
db: &'db dyn Db,
|
||||
name: &str,
|
||||
policy: MemberLookupPolicy,
|
||||
) -> Option<SymbolAndQualifiers<'db>> {
|
||||
Type::from(self.subclass_of).find_name_in_mro_with_policy(db, name, policy)
|
||||
}
|
||||
|
||||
/// Return `true` if `self` is a subtype of `other`.
|
||||
///
|
||||
/// This can only return `true` if `self.subclass_of` is a [`ClassBase::Class`] variant;
|
||||
/// only fully static types participate in subtyping.
|
||||
pub(crate) fn is_subtype_of(self, db: &'db dyn Db, other: SubclassOfType<'db>) -> bool {
|
||||
match (self.subclass_of, other.subclass_of) {
|
||||
// Non-fully-static types do not participate in subtyping
|
||||
(ClassBase::Dynamic(_), _) | (_, ClassBase::Dynamic(_)) => false,
|
||||
|
||||
// For example, `type[bool]` describes all possible runtime subclasses of the class `bool`,
|
||||
// and `type[int]` describes all possible runtime subclasses of the class `int`.
|
||||
// The first set is a subset of the second set, because `bool` is itself a subclass of `int`.
|
||||
(ClassBase::Class(self_class), ClassBase::Class(other_class)) => {
|
||||
// N.B. The subclass relation is fully static
|
||||
self_class.is_subclass_of(db, other_class)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn to_instance(self) -> Type<'db> {
|
||||
match self.subclass_of {
|
||||
ClassBase::Class(class) => Type::instance(class),
|
||||
ClassBase::Dynamic(dynamic_type) => Type::Dynamic(dynamic_type),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
The `knot_extensions.pyi` file in this directory will be symlinked into
|
||||
the `vendor/typeshed/stdlib` directory every time we sync our `typeshed`
|
||||
stubs (see `.github/workflows/sync_typeshed.yaml`).
|
||||
@@ -1 +0,0 @@
|
||||
bfd032156c59bbf851f62174014f24f4f89b96af
|
||||
@@ -1,117 +0,0 @@
|
||||
import sys
|
||||
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
|
||||
if sys.version_info >= (3, 9):
|
||||
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: ...
|
||||
else:
|
||||
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,
|
||||
) -> 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
|
||||
if sys.version_info >= (3, 9):
|
||||
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: ...
|
||||
else:
|
||||
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,
|
||||
) -> Self: ...
|
||||
|
||||
def copy(self) -> Self: ...
|
||||
def digest(self) -> bytes: ...
|
||||
def hexdigest(self) -> str: ...
|
||||
def update(self, data: ReadableBuffer, /) -> None: ...
|
||||
@@ -1,33 +0,0 @@
|
||||
from collections.abc import Callable
|
||||
from types import TracebackType
|
||||
from typing import Any, NoReturn, overload
|
||||
from typing_extensions import TypeVarTuple, Unpack
|
||||
|
||||
__all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "interrupt_main", "LockType", "RLock"]
|
||||
|
||||
_Ts = TypeVarTuple("_Ts")
|
||||
|
||||
TIMEOUT_MAX: int
|
||||
error = RuntimeError
|
||||
|
||||
@overload
|
||||
def start_new_thread(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]]) -> None: ...
|
||||
@overload
|
||||
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any]) -> None: ...
|
||||
def exit() -> NoReturn: ...
|
||||
def get_ident() -> int: ...
|
||||
def allocate_lock() -> LockType: ...
|
||||
def stack_size(size: int | None = None) -> int: ...
|
||||
|
||||
class LockType:
|
||||
locked_status: bool
|
||||
def acquire(self, waitflag: bool | None = None, timeout: int = -1) -> bool: ...
|
||||
def __enter__(self, waitflag: bool | None = None, timeout: int = -1) -> bool: ...
|
||||
def __exit__(self, typ: type[BaseException] | None, val: BaseException | None, tb: TracebackType | None) -> None: ...
|
||||
def release(self) -> bool: ...
|
||||
def locked(self) -> bool: ...
|
||||
|
||||
class RLock(LockType):
|
||||
def release(self) -> None: ... # type: ignore[override]
|
||||
|
||||
def interrupt_main() -> None: ...
|
||||
@@ -1,56 +0,0 @@
|
||||
from _threading_local import local as local
|
||||
from _typeshed import ProfileFunction, TraceFunction
|
||||
from threading import (
|
||||
TIMEOUT_MAX as TIMEOUT_MAX,
|
||||
Barrier as Barrier,
|
||||
BoundedSemaphore as BoundedSemaphore,
|
||||
BrokenBarrierError as BrokenBarrierError,
|
||||
Condition as Condition,
|
||||
Event as Event,
|
||||
ExceptHookArgs as ExceptHookArgs,
|
||||
Lock as Lock,
|
||||
RLock as RLock,
|
||||
Semaphore as Semaphore,
|
||||
Thread as Thread,
|
||||
ThreadError as ThreadError,
|
||||
Timer as Timer,
|
||||
_DummyThread as _DummyThread,
|
||||
_RLock as _RLock,
|
||||
excepthook as excepthook,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"get_ident",
|
||||
"active_count",
|
||||
"Condition",
|
||||
"current_thread",
|
||||
"enumerate",
|
||||
"main_thread",
|
||||
"TIMEOUT_MAX",
|
||||
"Event",
|
||||
"Lock",
|
||||
"RLock",
|
||||
"Semaphore",
|
||||
"BoundedSemaphore",
|
||||
"Thread",
|
||||
"Barrier",
|
||||
"BrokenBarrierError",
|
||||
"Timer",
|
||||
"ThreadError",
|
||||
"setprofile",
|
||||
"settrace",
|
||||
"local",
|
||||
"stack_size",
|
||||
"ExceptHookArgs",
|
||||
"excepthook",
|
||||
]
|
||||
|
||||
def active_count() -> int: ...
|
||||
def current_thread() -> Thread: ...
|
||||
def currentThread() -> Thread: ...
|
||||
def get_ident() -> int: ...
|
||||
def enumerate() -> list[Thread]: ...
|
||||
def main_thread() -> Thread: ...
|
||||
def settrace(func: TraceFunction) -> None: ...
|
||||
def setprofile(func: ProfileFunction | None) -> None: ...
|
||||
def stack_size(size: int | None = None) -> int: ...
|
||||
@@ -1,93 +0,0 @@
|
||||
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): ...
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
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: ...
|
||||
|
||||
else:
|
||||
def new(name: str, string: ReadableBuffer = b"") -> HASH: ...
|
||||
def openssl_md5(string: ReadableBuffer = b"") -> HASH: ...
|
||||
def openssl_sha1(string: ReadableBuffer = b"") -> HASH: ...
|
||||
def openssl_sha224(string: ReadableBuffer = b"") -> HASH: ...
|
||||
def openssl_sha256(string: ReadableBuffer = b"") -> HASH: ...
|
||||
def openssl_sha384(string: ReadableBuffer = b"") -> HASH: ...
|
||||
def openssl_sha512(string: ReadableBuffer = b"") -> HASH: ...
|
||||
|
||||
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: ...
|
||||
@@ -1,34 +0,0 @@
|
||||
# Utility types for typeshed
|
||||
|
||||
This package and its submodules contains various common types used by
|
||||
typeshed. It can also be used by packages outside typeshed, but beware
|
||||
the API stability guarantees below.
|
||||
|
||||
## Usage
|
||||
|
||||
The `_typeshed` package and its types do not exist at runtime, but can be
|
||||
used freely in stubs (`.pyi`) files. To import the types from this package in
|
||||
implementation (`.py`) files, use the following construct:
|
||||
|
||||
```python
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from _typeshed import ...
|
||||
```
|
||||
|
||||
Types can then be used in annotations by either quoting them or
|
||||
using:
|
||||
|
||||
```python
|
||||
from __future__ import annotations
|
||||
```
|
||||
|
||||
## API Stability
|
||||
|
||||
You can use this package and its submodules outside of typeshed, but we
|
||||
guarantee only limited API stability. Items marked as "stable" will not be
|
||||
removed or changed in an incompatible way for at least one year.
|
||||
Before making such a change, the "stable" moniker will be removed
|
||||
and we will mark the type in question as deprecated. No guarantees
|
||||
are made about unmarked types.
|
||||
@@ -1,366 +0,0 @@
|
||||
# Utility types for typeshed
|
||||
#
|
||||
# See the README.md file in this directory for more information.
|
||||
|
||||
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, 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):
|
||||
from types import NoneType as NoneType
|
||||
else:
|
||||
# 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: type[Self], sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> Self: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
def __replace__(self: 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): ...
|
||||
@@ -1,37 +0,0 @@
|
||||
# PEP 249 Database API 2.0 Types
|
||||
# https://www.python.org/dev/peps/pep-0249/
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import Any, Protocol
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
DBAPITypeCode: TypeAlias = Any | None
|
||||
# Strictly speaking, this should be a Sequence, but the type system does
|
||||
# not support fixed-length sequences.
|
||||
DBAPIColumnDescription: TypeAlias = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None]
|
||||
|
||||
class DBAPIConnection(Protocol):
|
||||
def close(self) -> object: ...
|
||||
def commit(self) -> object: ...
|
||||
# optional:
|
||||
# def rollback(self) -> Any: ...
|
||||
def cursor(self) -> DBAPICursor: ...
|
||||
|
||||
class DBAPICursor(Protocol):
|
||||
@property
|
||||
def description(self) -> Sequence[DBAPIColumnDescription] | None: ...
|
||||
@property
|
||||
def rowcount(self) -> int: ...
|
||||
# optional:
|
||||
# def callproc(self, procname: str, parameters: Sequence[Any] = ..., /) -> Sequence[Any]: ...
|
||||
def close(self) -> object: ...
|
||||
def execute(self, operation: str, parameters: Sequence[Any] | Mapping[str, Any] = ..., /) -> object: ...
|
||||
def executemany(self, operation: str, seq_of_parameters: Sequence[Sequence[Any]], /) -> object: ...
|
||||
def fetchone(self) -> Sequence[Any] | None: ...
|
||||
def fetchmany(self, size: int = ..., /) -> Sequence[Sequence[Any]]: ...
|
||||
def fetchall(self) -> Sequence[Sequence[Any]]: ...
|
||||
# optional:
|
||||
# def nextset(self) -> None | Literal[True]: ...
|
||||
arraysize: int
|
||||
def setinputsizes(self, sizes: Sequence[DBAPITypeCode | int | None], /) -> object: ...
|
||||
def setoutputsize(self, size: int, column: int = ..., /) -> object: ...
|
||||
@@ -1,18 +0,0 @@
|
||||
# Implicit protocols used in importlib.
|
||||
# We intentionally omit deprecated and optional methods.
|
||||
|
||||
from collections.abc import Sequence
|
||||
from importlib.machinery import ModuleSpec
|
||||
from types import ModuleType
|
||||
from typing import Protocol
|
||||
|
||||
__all__ = ["LoaderProtocol", "MetaPathFinderProtocol", "PathEntryFinderProtocol"]
|
||||
|
||||
class LoaderProtocol(Protocol):
|
||||
def load_module(self, fullname: str, /) -> ModuleType: ...
|
||||
|
||||
class MetaPathFinderProtocol(Protocol):
|
||||
def find_spec(self, fullname: str, path: Sequence[str] | None, target: ModuleType | None = ..., /) -> ModuleSpec | None: ...
|
||||
|
||||
class PathEntryFinderProtocol(Protocol):
|
||||
def find_spec(self, fullname: str, target: ModuleType | None = ..., /) -> ModuleSpec | None: ...
|
||||
@@ -1,44 +0,0 @@
|
||||
# Types to support PEP 3333 (WSGI)
|
||||
#
|
||||
# Obsolete since Python 3.11: Use wsgiref.types instead.
|
||||
#
|
||||
# See the README.md file in this directory for more information.
|
||||
|
||||
import sys
|
||||
from _typeshed import OptExcInfo
|
||||
from collections.abc import Callable, Iterable, Iterator
|
||||
from typing import Any, Protocol
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
class _Readable(Protocol):
|
||||
def read(self, size: int = ..., /) -> bytes: ...
|
||||
# Optional: def close(self) -> object: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from wsgiref.types import *
|
||||
else:
|
||||
# stable
|
||||
class StartResponse(Protocol):
|
||||
def __call__(
|
||||
self, status: str, headers: list[tuple[str, str]], exc_info: OptExcInfo | None = ..., /
|
||||
) -> Callable[[bytes], object]: ...
|
||||
|
||||
WSGIEnvironment: TypeAlias = dict[str, Any] # stable
|
||||
WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] # stable
|
||||
|
||||
# WSGI input streams per PEP 3333, stable
|
||||
class InputStream(Protocol):
|
||||
def read(self, size: int = ..., /) -> bytes: ...
|
||||
def readline(self, size: int = ..., /) -> bytes: ...
|
||||
def readlines(self, hint: int = ..., /) -> list[bytes]: ...
|
||||
def __iter__(self) -> Iterator[bytes]: ...
|
||||
|
||||
# WSGI error streams per PEP 3333, stable
|
||||
class ErrorStream(Protocol):
|
||||
def flush(self) -> object: ...
|
||||
def write(self, s: str, /) -> object: ...
|
||||
def writelines(self, seq: list[str], /) -> object: ...
|
||||
|
||||
# Optional file wrapper in wsgi.file_wrapper
|
||||
class FileWrapper(Protocol):
|
||||
def __call__(self, file: _Readable, block_size: int = ..., /) -> Iterable[bytes]: ...
|
||||
@@ -1,9 +0,0 @@
|
||||
# See the README.md file in this directory for more information.
|
||||
|
||||
from typing import Any, Protocol
|
||||
|
||||
# As defined https://docs.python.org/3/library/xml.dom.html#domimplementation-objects
|
||||
class DOMImplementation(Protocol):
|
||||
def hasFeature(self, feature: str, version: str | None, /) -> bool: ...
|
||||
def createDocument(self, namespaceUri: str, qualifiedName: str, doctype: Any | None, /) -> Any: ...
|
||||
def createDocumentType(self, qualifiedName: str, publicId: str, systemId: str, /) -> Any: ...
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,491 +0,0 @@
|
||||
import ssl
|
||||
import sys
|
||||
from _typeshed import FileDescriptorLike, ReadableBuffer, WriteableBuffer
|
||||
from asyncio import _AwaitableLike, _CoroutineLike
|
||||
from asyncio.events import AbstractEventLoop, AbstractServer, Handle, TimerHandle, _TaskFactory
|
||||
from asyncio.futures import Future
|
||||
from asyncio.protocols import BaseProtocol
|
||||
from asyncio.tasks import Task
|
||||
from asyncio.transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport
|
||||
from collections.abc import Callable, Iterable, Sequence
|
||||
from concurrent.futures import Executor, ThreadPoolExecutor
|
||||
from contextvars import Context
|
||||
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
|
||||
from typing import IO, Any, Literal, TypeVar, overload
|
||||
from typing_extensions import TypeAlias, TypeVarTuple, Unpack
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 9):
|
||||
__all__ = ("BaseEventLoop", "Server")
|
||||
else:
|
||||
__all__ = ("BaseEventLoop",)
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_Ts = TypeVarTuple("_Ts")
|
||||
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
|
||||
_Context: TypeAlias = dict[str, Any]
|
||||
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
|
||||
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
|
||||
_SSLContext: TypeAlias = bool | None | ssl.SSLContext
|
||||
|
||||
class Server(AbstractServer):
|
||||
if sys.version_info >= (3, 11):
|
||||
def __init__(
|
||||
self,
|
||||
loop: AbstractEventLoop,
|
||||
sockets: Iterable[socket],
|
||||
protocol_factory: _ProtocolFactory,
|
||||
ssl_context: _SSLContext,
|
||||
backlog: int,
|
||||
ssl_handshake_timeout: float | None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self,
|
||||
loop: AbstractEventLoop,
|
||||
sockets: Iterable[socket],
|
||||
protocol_factory: _ProtocolFactory,
|
||||
ssl_context: _SSLContext,
|
||||
backlog: int,
|
||||
ssl_handshake_timeout: float | None,
|
||||
) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
def close_clients(self) -> None: ...
|
||||
def abort_clients(self) -> None: ...
|
||||
|
||||
def get_loop(self) -> AbstractEventLoop: ...
|
||||
def is_serving(self) -> bool: ...
|
||||
async def start_serving(self) -> None: ...
|
||||
async def serve_forever(self) -> None: ...
|
||||
@property
|
||||
def sockets(self) -> tuple[socket, ...]: ...
|
||||
def close(self) -> None: ...
|
||||
async def wait_closed(self) -> None: ...
|
||||
|
||||
class BaseEventLoop(AbstractEventLoop):
|
||||
def run_forever(self) -> None: ...
|
||||
def run_until_complete(self, future: _AwaitableLike[_T]) -> _T: ...
|
||||
def stop(self) -> None: ...
|
||||
def is_running(self) -> bool: ...
|
||||
def is_closed(self) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
async def shutdown_asyncgens(self) -> None: ...
|
||||
# Methods scheduling callbacks. All these return Handles.
|
||||
def call_soon(
|
||||
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
|
||||
) -> Handle: ...
|
||||
def call_later(
|
||||
self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
|
||||
) -> TimerHandle: ...
|
||||
def call_at(
|
||||
self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
|
||||
) -> TimerHandle: ...
|
||||
def time(self) -> float: ...
|
||||
# Future methods
|
||||
def create_future(self) -> Future[Any]: ...
|
||||
# Tasks methods
|
||||
if sys.version_info >= (3, 11):
|
||||
def create_task(self, coro: _CoroutineLike[_T], *, name: object = None, context: Context | None = None) -> Task[_T]: ...
|
||||
else:
|
||||
def create_task(self, coro: _CoroutineLike[_T], *, name: object = None) -> Task[_T]: ...
|
||||
|
||||
def set_task_factory(self, factory: _TaskFactory | None) -> None: ...
|
||||
def get_task_factory(self) -> _TaskFactory | None: ...
|
||||
# Methods for interacting with threads
|
||||
def call_soon_threadsafe(
|
||||
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
|
||||
) -> Handle: ...
|
||||
def run_in_executor(self, executor: Executor | None, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
|
||||
def set_default_executor(self, executor: ThreadPoolExecutor) -> None: ... # type: ignore[override]
|
||||
# Network I/O methods returning Futures.
|
||||
async def getaddrinfo(
|
||||
self,
|
||||
host: bytes | str | None,
|
||||
port: bytes | str | int | None,
|
||||
*,
|
||||
family: int = 0,
|
||||
type: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...
|
||||
async def getnameinfo(self, sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int = 0) -> tuple[str, str]: ...
|
||||
if sys.version_info >= (3, 12):
|
||||
@overload
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: str = ...,
|
||||
port: int = ...,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: None = None,
|
||||
local_addr: tuple[str, int] | None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
all_errors: bool = False,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
@overload
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: socket,
|
||||
local_addr: None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
all_errors: bool = False,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
elif sys.version_info >= (3, 11):
|
||||
@overload
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: str = ...,
|
||||
port: int = ...,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: None = None,
|
||||
local_addr: tuple[str, int] | None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
@overload
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: socket,
|
||||
local_addr: None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
else:
|
||||
@overload
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: str = ...,
|
||||
port: int = ...,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: None = None,
|
||||
local_addr: tuple[str, int] | None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
@overload
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: socket,
|
||||
local_addr: None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
# 3.13 added `keep_alive`.
|
||||
@overload
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: str | Sequence[str] | None = None,
|
||||
port: int = ...,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
keep_alive: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
@overload
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: socket = ...,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
keep_alive: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
elif sys.version_info >= (3, 11):
|
||||
@overload
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: str | Sequence[str] | None = None,
|
||||
port: int = ...,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
@overload
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: socket = ...,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
else:
|
||||
@overload
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: str | Sequence[str] | None = None,
|
||||
port: int = ...,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
@overload
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: socket = ...,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
async def start_tls(
|
||||
self,
|
||||
transport: BaseTransport,
|
||||
protocol: BaseProtocol,
|
||||
sslcontext: ssl.SSLContext,
|
||||
*,
|
||||
server_side: bool = False,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
) -> Transport | None: ...
|
||||
async def connect_accepted_socket(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
sock: socket,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
else:
|
||||
async def start_tls(
|
||||
self,
|
||||
transport: BaseTransport,
|
||||
protocol: BaseProtocol,
|
||||
sslcontext: ssl.SSLContext,
|
||||
*,
|
||||
server_side: bool = False,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
) -> Transport | None: ...
|
||||
async def connect_accepted_socket(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
sock: socket,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
|
||||
async def sock_sendfile(
|
||||
self, sock: socket, file: IO[bytes], offset: int = 0, count: int | None = None, *, fallback: bool | None = True
|
||||
) -> int: ...
|
||||
async def sendfile(
|
||||
self, transport: WriteTransport, file: IO[bytes], offset: int = 0, count: int | None = None, *, fallback: bool = True
|
||||
) -> int: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
async def create_datagram_endpoint( # type: ignore[override]
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
local_addr: tuple[str, int] | str | None = None,
|
||||
remote_addr: tuple[str, int] | str | None = None,
|
||||
*,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
reuse_port: bool | None = None,
|
||||
allow_broadcast: bool | None = None,
|
||||
sock: socket | None = None,
|
||||
) -> tuple[DatagramTransport, _ProtocolT]: ...
|
||||
else:
|
||||
async def create_datagram_endpoint(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
local_addr: tuple[str, int] | str | None = None,
|
||||
remote_addr: tuple[str, int] | str | None = None,
|
||||
*,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
reuse_address: bool | None = ...,
|
||||
reuse_port: bool | None = None,
|
||||
allow_broadcast: bool | None = None,
|
||||
sock: socket | None = None,
|
||||
) -> tuple[DatagramTransport, _ProtocolT]: ...
|
||||
# Pipes and subprocesses.
|
||||
async def connect_read_pipe(
|
||||
self, protocol_factory: Callable[[], _ProtocolT], pipe: Any
|
||||
) -> tuple[ReadTransport, _ProtocolT]: ...
|
||||
async def connect_write_pipe(
|
||||
self, protocol_factory: Callable[[], _ProtocolT], pipe: Any
|
||||
) -> tuple[WriteTransport, _ProtocolT]: ...
|
||||
async def subprocess_shell(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
cmd: bytes | str,
|
||||
*,
|
||||
stdin: int | IO[Any] | None = -1,
|
||||
stdout: int | IO[Any] | None = -1,
|
||||
stderr: int | IO[Any] | None = -1,
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[True] = True,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = None,
|
||||
**kwargs: Any,
|
||||
) -> tuple[SubprocessTransport, _ProtocolT]: ...
|
||||
async def subprocess_exec(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
program: Any,
|
||||
*args: Any,
|
||||
stdin: int | IO[Any] | None = -1,
|
||||
stdout: int | IO[Any] | None = -1,
|
||||
stderr: int | IO[Any] | None = -1,
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[False] = False,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = None,
|
||||
**kwargs: Any,
|
||||
) -> tuple[SubprocessTransport, _ProtocolT]: ...
|
||||
def add_reader(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
|
||||
def remove_reader(self, fd: FileDescriptorLike) -> bool: ...
|
||||
def add_writer(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
|
||||
def remove_writer(self, fd: FileDescriptorLike) -> bool: ...
|
||||
# The sock_* methods (and probably some others) are not actually implemented on
|
||||
# BaseEventLoop, only on subclasses. We list them here for now for convenience.
|
||||
async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ...
|
||||
async def sock_recv_into(self, sock: socket, buf: WriteableBuffer) -> int: ...
|
||||
async def sock_sendall(self, sock: socket, data: ReadableBuffer) -> None: ...
|
||||
async def sock_connect(self, sock: socket, address: _Address) -> None: ...
|
||||
async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
async def sock_recvfrom(self, sock: socket, bufsize: int) -> tuple[bytes, _RetAddress]: ...
|
||||
async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = 0) -> tuple[int, _RetAddress]: ...
|
||||
async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> int: ...
|
||||
# Signal handling.
|
||||
def add_signal_handler(self, sig: int, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
|
||||
def remove_signal_handler(self, sig: int) -> bool: ...
|
||||
# Error handlers.
|
||||
def set_exception_handler(self, handler: _ExceptionHandler | None) -> None: ...
|
||||
def get_exception_handler(self) -> _ExceptionHandler | None: ...
|
||||
def default_exception_handler(self, context: _Context) -> None: ...
|
||||
def call_exception_handler(self, context: _Context) -> None: ...
|
||||
# Debug flag management.
|
||||
def get_debug(self) -> bool: ...
|
||||
def set_debug(self, enabled: bool) -> None: ...
|
||||
if sys.version_info >= (3, 12):
|
||||
async def shutdown_default_executor(self, timeout: float | None = None) -> None: ...
|
||||
elif sys.version_info >= (3, 9):
|
||||
async def shutdown_default_executor(self) -> None: ...
|
||||
|
||||
def __del__(self) -> None: ...
|
||||
@@ -1,19 +0,0 @@
|
||||
from collections.abc import Callable, Sequence
|
||||
from contextvars import Context
|
||||
from typing import Any, Final
|
||||
|
||||
from . import futures
|
||||
|
||||
__all__ = ()
|
||||
|
||||
# asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py
|
||||
# but it leads to circular import error in pytype tool.
|
||||
# That's why the import order is reversed.
|
||||
from .futures import isfuture as isfuture
|
||||
|
||||
_PENDING: Final = "PENDING" # undocumented
|
||||
_CANCELLED: Final = "CANCELLED" # undocumented
|
||||
_FINISHED: Final = "FINISHED" # undocumented
|
||||
|
||||
def _format_callbacks(cb: Sequence[tuple[Callable[[futures.Future[Any]], None], Context]]) -> str: ... # undocumented
|
||||
def _future_repr_info(future: futures.Future[Any]) -> list[str]: ... # undocumented
|
||||
@@ -1,63 +0,0 @@
|
||||
import subprocess
|
||||
from collections import deque
|
||||
from collections.abc import Callable, Sequence
|
||||
from typing import IO, Any
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from . import events, futures, protocols, transports
|
||||
|
||||
_File: TypeAlias = int | IO[Any] | None
|
||||
|
||||
class BaseSubprocessTransport(transports.SubprocessTransport):
|
||||
_closed: bool # undocumented
|
||||
_protocol: protocols.SubprocessProtocol # undocumented
|
||||
_loop: events.AbstractEventLoop # undocumented
|
||||
_proc: subprocess.Popen[Any] | None # undocumented
|
||||
_pid: int | None # undocumented
|
||||
_returncode: int | None # undocumented
|
||||
_exit_waiters: list[futures.Future[Any]] # undocumented
|
||||
_pending_calls: deque[tuple[Callable[..., Any], tuple[Any, ...]]] # undocumented
|
||||
_pipes: dict[int, _File] # undocumented
|
||||
_finished: bool # undocumented
|
||||
def __init__(
|
||||
self,
|
||||
loop: events.AbstractEventLoop,
|
||||
protocol: protocols.SubprocessProtocol,
|
||||
args: str | bytes | Sequence[str | bytes],
|
||||
shell: bool,
|
||||
stdin: _File,
|
||||
stdout: _File,
|
||||
stderr: _File,
|
||||
bufsize: int,
|
||||
waiter: futures.Future[Any] | None = None,
|
||||
extra: Any | None = None,
|
||||
**kwargs: Any,
|
||||
) -> None: ...
|
||||
def _start(
|
||||
self,
|
||||
args: str | bytes | Sequence[str | bytes],
|
||||
shell: bool,
|
||||
stdin: _File,
|
||||
stdout: _File,
|
||||
stderr: _File,
|
||||
bufsize: int,
|
||||
**kwargs: Any,
|
||||
) -> None: ... # undocumented
|
||||
def get_pid(self) -> int | None: ... # type: ignore[override]
|
||||
def get_pipe_transport(self, fd: int) -> _File: ... # type: ignore[override]
|
||||
def _check_proc(self) -> None: ... # undocumented
|
||||
def send_signal(self, signal: int) -> None: ...
|
||||
async def _connect_pipes(self, waiter: futures.Future[Any] | None) -> None: ... # undocumented
|
||||
def _call(self, cb: Callable[..., object], *data: Any) -> None: ... # undocumented
|
||||
def _pipe_connection_lost(self, fd: int, exc: BaseException | None) -> None: ... # undocumented
|
||||
def _pipe_data_received(self, fd: int, data: bytes) -> None: ... # undocumented
|
||||
def _process_exited(self, returncode: int) -> None: ... # undocumented
|
||||
async def _wait(self) -> int: ... # undocumented
|
||||
def _try_finish(self) -> None: ... # undocumented
|
||||
def _call_connection_lost(self, exc: BaseException | None) -> None: ... # undocumented
|
||||
def __del__(self) -> None: ...
|
||||
|
||||
class WriteSubprocessPipeProto(protocols.BaseProtocol): # undocumented
|
||||
def __init__(self, proc: BaseSubprocessTransport, fd: int) -> None: ...
|
||||
|
||||
class ReadSubprocessPipeProto(WriteSubprocessPipeProto, protocols.Protocol): ... # undocumented
|
||||
@@ -1,9 +0,0 @@
|
||||
from _typeshed import StrOrBytesPath
|
||||
from types import FrameType
|
||||
from typing import Any
|
||||
|
||||
from . import tasks
|
||||
|
||||
def _task_repr_info(task: tasks.Task[Any]) -> list[str]: ... # undocumented
|
||||
def _task_get_stack(task: tasks.Task[Any], limit: int | None) -> list[FrameType]: ... # undocumented
|
||||
def _task_print_stack(task: tasks.Task[Any], limit: int | None, file: StrOrBytesPath) -> None: ... # undocumented
|
||||
@@ -1,20 +0,0 @@
|
||||
import enum
|
||||
import sys
|
||||
from typing import Final
|
||||
|
||||
LOG_THRESHOLD_FOR_CONNLOST_WRITES: Final = 5
|
||||
ACCEPT_RETRY_DELAY: Final = 1
|
||||
DEBUG_STACK_DEPTH: Final = 10
|
||||
SSL_HANDSHAKE_TIMEOUT: float
|
||||
SENDFILE_FALLBACK_READBUFFER_SIZE: Final = 262144
|
||||
if sys.version_info >= (3, 11):
|
||||
SSL_SHUTDOWN_TIMEOUT: float
|
||||
FLOW_CONTROL_HIGH_WATER_SSL_READ: Final = 256
|
||||
FLOW_CONTROL_HIGH_WATER_SSL_WRITE: Final = 512
|
||||
if sys.version_info >= (3, 12):
|
||||
THREAD_JOIN_TIMEOUT: Final = 300
|
||||
|
||||
class _SendfileMode(enum.Enum):
|
||||
UNSUPPORTED = 1
|
||||
TRY_NATIVE = 2
|
||||
FALLBACK = 3
|
||||
@@ -1,27 +0,0 @@
|
||||
import sys
|
||||
from collections.abc import Awaitable, Callable, Coroutine
|
||||
from typing import Any, TypeVar, overload
|
||||
from typing_extensions import ParamSpec, TypeGuard, TypeIs
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 11):
|
||||
__all__ = ("iscoroutinefunction", "iscoroutine")
|
||||
else:
|
||||
__all__ = ("coroutine", "iscoroutinefunction", "iscoroutine")
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_FunctionT = TypeVar("_FunctionT", bound=Callable[..., Any])
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
if sys.version_info < (3, 11):
|
||||
def coroutine(func: _FunctionT) -> _FunctionT: ...
|
||||
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...
|
||||
def iscoroutine(obj: object) -> TypeIs[Coroutine[Any, Any, Any]]: ...
|
||||
@@ -1,655 +0,0 @@
|
||||
import ssl
|
||||
import sys
|
||||
from _asyncio import (
|
||||
_get_running_loop as _get_running_loop,
|
||||
_set_running_loop as _set_running_loop,
|
||||
get_event_loop as get_event_loop,
|
||||
get_running_loop as get_running_loop,
|
||||
)
|
||||
from _typeshed import FileDescriptorLike, ReadableBuffer, StrPath, Unused, WriteableBuffer
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections.abc import Callable, Sequence
|
||||
from concurrent.futures import Executor
|
||||
from contextvars import Context
|
||||
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
|
||||
from typing import IO, Any, Literal, Protocol, TypeVar, overload
|
||||
from typing_extensions import Self, TypeAlias, TypeVarTuple, Unpack, deprecated
|
||||
|
||||
from . import _AwaitableLike, _CoroutineLike
|
||||
from .base_events import Server
|
||||
from .futures import Future
|
||||
from .protocols import BaseProtocol
|
||||
from .tasks import Task
|
||||
from .transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport
|
||||
from .unix_events import AbstractChildWatcher
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 14):
|
||||
__all__ = (
|
||||
"AbstractEventLoopPolicy",
|
||||
"AbstractEventLoop",
|
||||
"AbstractServer",
|
||||
"Handle",
|
||||
"TimerHandle",
|
||||
"get_event_loop_policy",
|
||||
"set_event_loop_policy",
|
||||
"get_event_loop",
|
||||
"set_event_loop",
|
||||
"new_event_loop",
|
||||
"_set_running_loop",
|
||||
"get_running_loop",
|
||||
"_get_running_loop",
|
||||
)
|
||||
else:
|
||||
__all__ = (
|
||||
"AbstractEventLoopPolicy",
|
||||
"AbstractEventLoop",
|
||||
"AbstractServer",
|
||||
"Handle",
|
||||
"TimerHandle",
|
||||
"get_event_loop_policy",
|
||||
"set_event_loop_policy",
|
||||
"get_event_loop",
|
||||
"set_event_loop",
|
||||
"new_event_loop",
|
||||
"get_child_watcher",
|
||||
"set_child_watcher",
|
||||
"_set_running_loop",
|
||||
"get_running_loop",
|
||||
"_get_running_loop",
|
||||
)
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_Ts = TypeVarTuple("_Ts")
|
||||
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
|
||||
_Context: TypeAlias = dict[str, Any]
|
||||
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
|
||||
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
|
||||
_SSLContext: TypeAlias = bool | None | ssl.SSLContext
|
||||
|
||||
class _TaskFactory(Protocol):
|
||||
def __call__(self, loop: AbstractEventLoop, factory: _CoroutineLike[_T], /) -> Future[_T]: ...
|
||||
|
||||
class Handle:
|
||||
_cancelled: bool
|
||||
_args: Sequence[Any]
|
||||
def __init__(
|
||||
self, callback: Callable[..., object], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = None
|
||||
) -> None: ...
|
||||
def cancel(self) -> None: ...
|
||||
def _run(self) -> None: ...
|
||||
def cancelled(self) -> bool: ...
|
||||
if sys.version_info >= (3, 12):
|
||||
def get_context(self) -> Context: ...
|
||||
|
||||
class TimerHandle(Handle):
|
||||
def __init__(
|
||||
self,
|
||||
when: float,
|
||||
callback: Callable[..., object],
|
||||
args: Sequence[Any],
|
||||
loop: AbstractEventLoop,
|
||||
context: Context | None = None,
|
||||
) -> None: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def when(self) -> float: ...
|
||||
def __lt__(self, other: TimerHandle) -> bool: ...
|
||||
def __le__(self, other: TimerHandle) -> bool: ...
|
||||
def __gt__(self, other: TimerHandle) -> bool: ...
|
||||
def __ge__(self, other: TimerHandle) -> bool: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
|
||||
class AbstractServer:
|
||||
@abstractmethod
|
||||
def close(self) -> None: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
@abstractmethod
|
||||
def close_clients(self) -> None: ...
|
||||
@abstractmethod
|
||||
def abort_clients(self) -> None: ...
|
||||
|
||||
async def __aenter__(self) -> Self: ...
|
||||
async def __aexit__(self, *exc: Unused) -> None: ...
|
||||
@abstractmethod
|
||||
def get_loop(self) -> AbstractEventLoop: ...
|
||||
@abstractmethod
|
||||
def is_serving(self) -> bool: ...
|
||||
@abstractmethod
|
||||
async def start_serving(self) -> None: ...
|
||||
@abstractmethod
|
||||
async def serve_forever(self) -> None: ...
|
||||
@abstractmethod
|
||||
async def wait_closed(self) -> None: ...
|
||||
|
||||
class AbstractEventLoop:
|
||||
slow_callback_duration: float
|
||||
@abstractmethod
|
||||
def run_forever(self) -> None: ...
|
||||
@abstractmethod
|
||||
def run_until_complete(self, future: _AwaitableLike[_T]) -> _T: ...
|
||||
@abstractmethod
|
||||
def stop(self) -> None: ...
|
||||
@abstractmethod
|
||||
def is_running(self) -> bool: ...
|
||||
@abstractmethod
|
||||
def is_closed(self) -> bool: ...
|
||||
@abstractmethod
|
||||
def close(self) -> None: ...
|
||||
@abstractmethod
|
||||
async def shutdown_asyncgens(self) -> None: ...
|
||||
# Methods scheduling callbacks. All these return Handles.
|
||||
if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2
|
||||
@abstractmethod
|
||||
def call_soon(
|
||||
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
|
||||
) -> Handle: ...
|
||||
@abstractmethod
|
||||
def call_later(
|
||||
self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
|
||||
) -> TimerHandle: ...
|
||||
@abstractmethod
|
||||
def call_at(
|
||||
self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
|
||||
) -> TimerHandle: ...
|
||||
else:
|
||||
@abstractmethod
|
||||
def call_soon(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ...
|
||||
@abstractmethod
|
||||
def call_later(self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> TimerHandle: ...
|
||||
@abstractmethod
|
||||
def call_at(self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> TimerHandle: ...
|
||||
|
||||
@abstractmethod
|
||||
def time(self) -> float: ...
|
||||
# Future methods
|
||||
@abstractmethod
|
||||
def create_future(self) -> Future[Any]: ...
|
||||
# Tasks methods
|
||||
if sys.version_info >= (3, 11):
|
||||
@abstractmethod
|
||||
def create_task(
|
||||
self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None
|
||||
) -> Task[_T]: ...
|
||||
else:
|
||||
@abstractmethod
|
||||
def create_task(self, coro: _CoroutineLike[_T], *, name: str | None = None) -> Task[_T]: ...
|
||||
|
||||
@abstractmethod
|
||||
def set_task_factory(self, factory: _TaskFactory | None) -> None: ...
|
||||
@abstractmethod
|
||||
def get_task_factory(self) -> _TaskFactory | None: ...
|
||||
# Methods for interacting with threads
|
||||
if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2
|
||||
@abstractmethod
|
||||
def call_soon_threadsafe(
|
||||
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
|
||||
) -> Handle: ...
|
||||
else:
|
||||
@abstractmethod
|
||||
def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ...
|
||||
|
||||
@abstractmethod
|
||||
def run_in_executor(self, executor: Executor | None, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
|
||||
@abstractmethod
|
||||
def set_default_executor(self, executor: Executor) -> None: ...
|
||||
# Network I/O methods returning Futures.
|
||||
@abstractmethod
|
||||
async def getaddrinfo(
|
||||
self,
|
||||
host: bytes | str | None,
|
||||
port: bytes | str | int | None,
|
||||
*,
|
||||
family: int = 0,
|
||||
type: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...
|
||||
@abstractmethod
|
||||
async def getnameinfo(self, sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int = 0) -> tuple[str, str]: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: str = ...,
|
||||
port: int = ...,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: None = None,
|
||||
local_addr: tuple[str, int] | None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: socket,
|
||||
local_addr: None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
else:
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: str = ...,
|
||||
port: int = ...,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: None = None,
|
||||
local_addr: tuple[str, int] | None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
sock: socket,
|
||||
local_addr: None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
happy_eyeballs_delay: float | None = None,
|
||||
interleave: int | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
# 3.13 added `keep_alive`.
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: str | Sequence[str] | None = None,
|
||||
port: int = ...,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
keep_alive: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: socket = ...,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
keep_alive: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
elif sys.version_info >= (3, 11):
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: str | Sequence[str] | None = None,
|
||||
port: int = ...,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: socket = ...,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
else:
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: str | Sequence[str] | None = None,
|
||||
port: int = ...,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
async def create_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
host: None = None,
|
||||
port: None = None,
|
||||
*,
|
||||
family: int = ...,
|
||||
flags: int = ...,
|
||||
sock: socket = ...,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
@abstractmethod
|
||||
async def start_tls(
|
||||
self,
|
||||
transport: WriteTransport,
|
||||
protocol: BaseProtocol,
|
||||
sslcontext: ssl.SSLContext,
|
||||
*,
|
||||
server_side: bool = False,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
) -> Transport | None: ...
|
||||
async def create_unix_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
path: StrPath | None = None,
|
||||
*,
|
||||
sock: socket | None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
else:
|
||||
@abstractmethod
|
||||
async def start_tls(
|
||||
self,
|
||||
transport: BaseTransport,
|
||||
protocol: BaseProtocol,
|
||||
sslcontext: ssl.SSLContext,
|
||||
*,
|
||||
server_side: bool = False,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
) -> Transport | None: ...
|
||||
async def create_unix_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
path: StrPath | None = None,
|
||||
*,
|
||||
sock: socket | None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
) -> Server: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
async def connect_accepted_socket(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
sock: socket,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
elif sys.version_info >= (3, 10):
|
||||
async def connect_accepted_socket(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
sock: socket,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
async def create_unix_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
path: str | None = None,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
sock: socket | None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
else:
|
||||
async def create_unix_connection(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
path: str | None = None,
|
||||
*,
|
||||
ssl: _SSLContext = None,
|
||||
sock: socket | None = None,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
) -> tuple[Transport, _ProtocolT]: ...
|
||||
|
||||
@abstractmethod
|
||||
async def sock_sendfile(
|
||||
self, sock: socket, file: IO[bytes], offset: int = 0, count: int | None = None, *, fallback: bool | None = None
|
||||
) -> int: ...
|
||||
@abstractmethod
|
||||
async def sendfile(
|
||||
self, transport: WriteTransport, file: IO[bytes], offset: int = 0, count: int | None = None, *, fallback: bool = True
|
||||
) -> int: ...
|
||||
@abstractmethod
|
||||
async def create_datagram_endpoint(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
local_addr: tuple[str, int] | str | None = None,
|
||||
remote_addr: tuple[str, int] | str | None = None,
|
||||
*,
|
||||
family: int = 0,
|
||||
proto: int = 0,
|
||||
flags: int = 0,
|
||||
reuse_address: bool | None = None,
|
||||
reuse_port: bool | None = None,
|
||||
allow_broadcast: bool | None = None,
|
||||
sock: socket | None = None,
|
||||
) -> tuple[DatagramTransport, _ProtocolT]: ...
|
||||
# Pipes and subprocesses.
|
||||
@abstractmethod
|
||||
async def connect_read_pipe(
|
||||
self, protocol_factory: Callable[[], _ProtocolT], pipe: Any
|
||||
) -> tuple[ReadTransport, _ProtocolT]: ...
|
||||
@abstractmethod
|
||||
async def connect_write_pipe(
|
||||
self, protocol_factory: Callable[[], _ProtocolT], pipe: Any
|
||||
) -> tuple[WriteTransport, _ProtocolT]: ...
|
||||
@abstractmethod
|
||||
async def subprocess_shell(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
cmd: bytes | str,
|
||||
*,
|
||||
stdin: int | IO[Any] | None = -1,
|
||||
stdout: int | IO[Any] | None = -1,
|
||||
stderr: int | IO[Any] | None = -1,
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[True] = True,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = ...,
|
||||
**kwargs: Any,
|
||||
) -> tuple[SubprocessTransport, _ProtocolT]: ...
|
||||
@abstractmethod
|
||||
async def subprocess_exec(
|
||||
self,
|
||||
protocol_factory: Callable[[], _ProtocolT],
|
||||
program: Any,
|
||||
*args: Any,
|
||||
stdin: int | IO[Any] | None = -1,
|
||||
stdout: int | IO[Any] | None = -1,
|
||||
stderr: int | IO[Any] | None = -1,
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[False] = False,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
**kwargs: Any,
|
||||
) -> tuple[SubprocessTransport, _ProtocolT]: ...
|
||||
@abstractmethod
|
||||
def add_reader(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
|
||||
@abstractmethod
|
||||
def remove_reader(self, fd: FileDescriptorLike) -> bool: ...
|
||||
@abstractmethod
|
||||
def add_writer(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
|
||||
@abstractmethod
|
||||
def remove_writer(self, fd: FileDescriptorLike) -> bool: ...
|
||||
@abstractmethod
|
||||
async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ...
|
||||
@abstractmethod
|
||||
async def sock_recv_into(self, sock: socket, buf: WriteableBuffer) -> int: ...
|
||||
@abstractmethod
|
||||
async def sock_sendall(self, sock: socket, data: ReadableBuffer) -> None: ...
|
||||
@abstractmethod
|
||||
async def sock_connect(self, sock: socket, address: _Address) -> None: ...
|
||||
@abstractmethod
|
||||
async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
@abstractmethod
|
||||
async def sock_recvfrom(self, sock: socket, bufsize: int) -> tuple[bytes, _RetAddress]: ...
|
||||
@abstractmethod
|
||||
async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = 0) -> tuple[int, _RetAddress]: ...
|
||||
@abstractmethod
|
||||
async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> int: ...
|
||||
# Signal handling.
|
||||
@abstractmethod
|
||||
def add_signal_handler(self, sig: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ...
|
||||
@abstractmethod
|
||||
def remove_signal_handler(self, sig: int) -> bool: ...
|
||||
# Error handlers.
|
||||
@abstractmethod
|
||||
def set_exception_handler(self, handler: _ExceptionHandler | None) -> None: ...
|
||||
@abstractmethod
|
||||
def get_exception_handler(self) -> _ExceptionHandler | None: ...
|
||||
@abstractmethod
|
||||
def default_exception_handler(self, context: _Context) -> None: ...
|
||||
@abstractmethod
|
||||
def call_exception_handler(self, context: _Context) -> None: ...
|
||||
# Debug flag management.
|
||||
@abstractmethod
|
||||
def get_debug(self) -> bool: ...
|
||||
@abstractmethod
|
||||
def set_debug(self, enabled: bool) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
@abstractmethod
|
||||
async def shutdown_default_executor(self) -> None: ...
|
||||
|
||||
class AbstractEventLoopPolicy:
|
||||
@abstractmethod
|
||||
def get_event_loop(self) -> AbstractEventLoop: ...
|
||||
@abstractmethod
|
||||
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
@abstractmethod
|
||||
def new_event_loop(self) -> AbstractEventLoop: ...
|
||||
# Child processes handling (Unix only).
|
||||
if sys.version_info < (3, 14):
|
||||
if sys.version_info >= (3, 12):
|
||||
@abstractmethod
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
def get_child_watcher(self) -> AbstractChildWatcher: ...
|
||||
@abstractmethod
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
|
||||
else:
|
||||
@abstractmethod
|
||||
def get_child_watcher(self) -> AbstractChildWatcher: ...
|
||||
@abstractmethod
|
||||
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
|
||||
|
||||
class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy, metaclass=ABCMeta):
|
||||
def get_event_loop(self) -> AbstractEventLoop: ...
|
||||
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
def new_event_loop(self) -> AbstractEventLoop: ...
|
||||
|
||||
def get_event_loop_policy() -> AbstractEventLoopPolicy: ...
|
||||
def set_event_loop_policy(policy: AbstractEventLoopPolicy | None) -> None: ...
|
||||
def set_event_loop(loop: AbstractEventLoop | None) -> None: ...
|
||||
def new_event_loop() -> AbstractEventLoop: ...
|
||||
|
||||
if sys.version_info < (3, 14):
|
||||
if sys.version_info >= (3, 12):
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
def get_child_watcher() -> AbstractChildWatcher: ...
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
def set_child_watcher(watcher: AbstractChildWatcher) -> None: ...
|
||||
|
||||
else:
|
||||
def get_child_watcher() -> AbstractChildWatcher: ...
|
||||
def set_child_watcher(watcher: AbstractChildWatcher) -> None: ...
|
||||
@@ -1,44 +0,0 @@
|
||||
import sys
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 11):
|
||||
__all__ = (
|
||||
"BrokenBarrierError",
|
||||
"CancelledError",
|
||||
"InvalidStateError",
|
||||
"TimeoutError",
|
||||
"IncompleteReadError",
|
||||
"LimitOverrunError",
|
||||
"SendfileNotAvailableError",
|
||||
)
|
||||
else:
|
||||
__all__ = (
|
||||
"CancelledError",
|
||||
"InvalidStateError",
|
||||
"TimeoutError",
|
||||
"IncompleteReadError",
|
||||
"LimitOverrunError",
|
||||
"SendfileNotAvailableError",
|
||||
)
|
||||
|
||||
class CancelledError(BaseException): ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from builtins import TimeoutError as TimeoutError
|
||||
else:
|
||||
class TimeoutError(Exception): ...
|
||||
|
||||
class InvalidStateError(Exception): ...
|
||||
class SendfileNotAvailableError(RuntimeError): ...
|
||||
|
||||
class IncompleteReadError(EOFError):
|
||||
expected: int | None
|
||||
partial: bytes
|
||||
def __init__(self, partial: bytes, expected: int | None) -> None: ...
|
||||
|
||||
class LimitOverrunError(Exception):
|
||||
consumed: int
|
||||
def __init__(self, message: str, consumed: int) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
class BrokenBarrierError(RuntimeError): ...
|
||||
@@ -1,31 +0,0 @@
|
||||
import functools
|
||||
import sys
|
||||
import traceback
|
||||
from collections.abc import Iterable
|
||||
from types import FrameType, FunctionType
|
||||
from typing import Any, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
class _HasWrapper:
|
||||
__wrapper__: _HasWrapper | FunctionType
|
||||
|
||||
_FuncType: TypeAlias = FunctionType | _HasWrapper | functools.partial[Any] | functools.partialmethod[Any]
|
||||
|
||||
@overload
|
||||
def _get_function_source(func: _FuncType) -> tuple[str, int]: ...
|
||||
@overload
|
||||
def _get_function_source(func: object) -> tuple[str, int] | None: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
def _format_callback_source(func: object, args: Iterable[Any], *, debug: bool = False) -> str: ...
|
||||
def _format_args_and_kwargs(args: Iterable[Any], kwargs: dict[str, Any], *, debug: bool = False) -> str: ...
|
||||
def _format_callback(
|
||||
func: object, args: Iterable[Any], kwargs: dict[str, Any], *, debug: bool = False, suffix: str = ""
|
||||
) -> str: ...
|
||||
|
||||
else:
|
||||
def _format_callback_source(func: object, args: Iterable[Any]) -> str: ...
|
||||
def _format_args_and_kwargs(args: Iterable[Any], kwargs: dict[str, Any]) -> str: ...
|
||||
def _format_callback(func: object, args: Iterable[Any], kwargs: dict[str, Any], suffix: str = "") -> str: ...
|
||||
|
||||
def extract_stack(f: FrameType | None = None, limit: int | None = None) -> traceback.StackSummary: ...
|
||||
@@ -1,17 +0,0 @@
|
||||
from _asyncio import Future as Future
|
||||
from concurrent.futures._base import Future as _ConcurrentFuture
|
||||
from typing import Any, TypeVar
|
||||
from typing_extensions import TypeIs
|
||||
|
||||
from .events import AbstractEventLoop
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
__all__ = ("Future", "wrap_future", "isfuture")
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
# asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py
|
||||
# but it leads to circular import error in pytype tool.
|
||||
# That's why the import order is reversed.
|
||||
def isfuture(obj: object) -> TypeIs[Future[Any]]: ...
|
||||
def wrap_future(future: _ConcurrentFuture[_T] | Future[_T], *, loop: AbstractEventLoop | None = None) -> Future[_T]: ...
|
||||
@@ -1,122 +0,0 @@
|
||||
import enum
|
||||
import sys
|
||||
from _typeshed import Unused
|
||||
from collections import deque
|
||||
from collections.abc import Callable, Generator
|
||||
from types import TracebackType
|
||||
from typing import Any, Literal, TypeVar
|
||||
from typing_extensions import Self
|
||||
|
||||
from .events import AbstractEventLoop
|
||||
from .futures import Future
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from .mixins import _LoopBoundMixin
|
||||
else:
|
||||
_LoopBoundMixin = object
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 11):
|
||||
__all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore", "Barrier")
|
||||
else:
|
||||
__all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore")
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
class _ContextManagerMixin:
|
||||
async def __aenter__(self) -> None: ...
|
||||
async def __aexit__(
|
||||
self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
else:
|
||||
class _ContextManager:
|
||||
def __init__(self, lock: Lock | Semaphore) -> None: ...
|
||||
def __enter__(self) -> None: ...
|
||||
def __exit__(self, *args: Unused) -> None: ...
|
||||
|
||||
class _ContextManagerMixin:
|
||||
# Apparently this exists to *prohibit* use as a context manager.
|
||||
# def __enter__(self) -> NoReturn: ... see: https://github.com/python/typing/issues/1043
|
||||
# def __exit__(self, *args: Any) -> None: ...
|
||||
def __iter__(self) -> Generator[Any, None, _ContextManager]: ...
|
||||
def __await__(self) -> Generator[Any, None, _ContextManager]: ...
|
||||
async def __aenter__(self) -> None: ...
|
||||
async def __aexit__(
|
||||
self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
class Lock(_ContextManagerMixin, _LoopBoundMixin):
|
||||
_waiters: deque[Future[Any]] | None
|
||||
if sys.version_info >= (3, 10):
|
||||
def __init__(self) -> None: ...
|
||||
else:
|
||||
def __init__(self, *, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
|
||||
def locked(self) -> bool: ...
|
||||
async def acquire(self) -> Literal[True]: ...
|
||||
def release(self) -> None: ...
|
||||
|
||||
class Event(_LoopBoundMixin):
|
||||
_waiters: deque[Future[Any]]
|
||||
if sys.version_info >= (3, 10):
|
||||
def __init__(self) -> None: ...
|
||||
else:
|
||||
def __init__(self, *, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
|
||||
def is_set(self) -> bool: ...
|
||||
def set(self) -> None: ...
|
||||
def clear(self) -> None: ...
|
||||
async def wait(self) -> Literal[True]: ...
|
||||
|
||||
class Condition(_ContextManagerMixin, _LoopBoundMixin):
|
||||
_waiters: deque[Future[Any]]
|
||||
if sys.version_info >= (3, 10):
|
||||
def __init__(self, lock: Lock | None = None) -> None: ...
|
||||
else:
|
||||
def __init__(self, lock: Lock | None = None, *, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
|
||||
def locked(self) -> bool: ...
|
||||
async def acquire(self) -> Literal[True]: ...
|
||||
def release(self) -> None: ...
|
||||
async def wait(self) -> Literal[True]: ...
|
||||
async def wait_for(self, predicate: Callable[[], _T]) -> _T: ...
|
||||
def notify(self, n: int = 1) -> None: ...
|
||||
def notify_all(self) -> None: ...
|
||||
|
||||
class Semaphore(_ContextManagerMixin, _LoopBoundMixin):
|
||||
_value: int
|
||||
_waiters: deque[Future[Any]] | None
|
||||
if sys.version_info >= (3, 10):
|
||||
def __init__(self, value: int = 1) -> None: ...
|
||||
else:
|
||||
def __init__(self, value: int = 1, *, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
|
||||
def locked(self) -> bool: ...
|
||||
async def acquire(self) -> Literal[True]: ...
|
||||
def release(self) -> None: ...
|
||||
def _wake_up_next(self) -> None: ...
|
||||
|
||||
class BoundedSemaphore(Semaphore): ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
class _BarrierState(enum.Enum): # undocumented
|
||||
FILLING = "filling"
|
||||
DRAINING = "draining"
|
||||
RESETTING = "resetting"
|
||||
BROKEN = "broken"
|
||||
|
||||
class Barrier(_LoopBoundMixin):
|
||||
def __init__(self, parties: int) -> None: ...
|
||||
async def __aenter__(self) -> Self: ...
|
||||
async def __aexit__(self, *args: Unused) -> None: ...
|
||||
async def wait(self) -> int: ...
|
||||
async def abort(self) -> None: ...
|
||||
async def reset(self) -> None: ...
|
||||
@property
|
||||
def parties(self) -> int: ...
|
||||
@property
|
||||
def n_waiting(self) -> int: ...
|
||||
@property
|
||||
def broken(self) -> bool: ...
|
||||
@@ -1,3 +0,0 @@
|
||||
import logging
|
||||
|
||||
logger: logging.Logger
|
||||
@@ -1,9 +0,0 @@
|
||||
import sys
|
||||
import threading
|
||||
from typing_extensions import Never
|
||||
|
||||
_global_lock: threading.Lock
|
||||
|
||||
class _LoopBoundMixin:
|
||||
if sys.version_info < (3, 11):
|
||||
def __init__(self, *, loop: Never = ...) -> None: ...
|
||||
@@ -1,65 +0,0 @@
|
||||
import sys
|
||||
from collections.abc import Mapping
|
||||
from socket import socket
|
||||
from typing import Any, ClassVar, Literal
|
||||
|
||||
from . import base_events, constants, events, futures, streams, transports
|
||||
|
||||
__all__ = ("BaseProactorEventLoop",)
|
||||
|
||||
class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTransport):
|
||||
def __init__(
|
||||
self,
|
||||
loop: events.AbstractEventLoop,
|
||||
sock: socket,
|
||||
protocol: streams.StreamReaderProtocol,
|
||||
waiter: futures.Future[Any] | None = None,
|
||||
extra: Mapping[Any, Any] | None = None,
|
||||
server: events.AbstractServer | None = None,
|
||||
) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
|
||||
class _ProactorReadPipeTransport(_ProactorBasePipeTransport, transports.ReadTransport):
|
||||
if sys.version_info >= (3, 10):
|
||||
def __init__(
|
||||
self,
|
||||
loop: events.AbstractEventLoop,
|
||||
sock: socket,
|
||||
protocol: streams.StreamReaderProtocol,
|
||||
waiter: futures.Future[Any] | None = None,
|
||||
extra: Mapping[Any, Any] | None = None,
|
||||
server: events.AbstractServer | None = None,
|
||||
buffer_size: int = 65536,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self,
|
||||
loop: events.AbstractEventLoop,
|
||||
sock: socket,
|
||||
protocol: streams.StreamReaderProtocol,
|
||||
waiter: futures.Future[Any] | None = None,
|
||||
extra: Mapping[Any, Any] | None = None,
|
||||
server: events.AbstractServer | None = None,
|
||||
) -> None: ...
|
||||
|
||||
class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport, transports.WriteTransport): ...
|
||||
class _ProactorWritePipeTransport(_ProactorBaseWritePipeTransport): ...
|
||||
class _ProactorDuplexPipeTransport(_ProactorReadPipeTransport, _ProactorBaseWritePipeTransport, transports.Transport): ...
|
||||
|
||||
class _ProactorSocketTransport(_ProactorReadPipeTransport, _ProactorBaseWritePipeTransport, transports.Transport):
|
||||
_sendfile_compatible: ClassVar[constants._SendfileMode]
|
||||
def __init__(
|
||||
self,
|
||||
loop: events.AbstractEventLoop,
|
||||
sock: socket,
|
||||
protocol: streams.StreamReaderProtocol,
|
||||
waiter: futures.Future[Any] | None = None,
|
||||
extra: Mapping[Any, Any] | None = None,
|
||||
server: events.AbstractServer | None = None,
|
||||
) -> None: ...
|
||||
def _set_extra(self, sock: socket) -> None: ...
|
||||
def can_write_eof(self) -> Literal[True]: ...
|
||||
|
||||
class BaseProactorEventLoop(base_events.BaseEventLoop):
|
||||
def __init__(self, proactor: Any) -> None: ...
|
||||
async def sock_recv(self, sock: socket, n: int) -> bytes: ...
|
||||
@@ -1,35 +0,0 @@
|
||||
from _typeshed import ReadableBuffer
|
||||
from asyncio import transports
|
||||
from typing import Any
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
__all__ = ("BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol", "BufferedProtocol")
|
||||
|
||||
class BaseProtocol:
|
||||
def connection_made(self, transport: transports.BaseTransport) -> None: ...
|
||||
def connection_lost(self, exc: Exception | None) -> None: ...
|
||||
def pause_writing(self) -> None: ...
|
||||
def resume_writing(self) -> None: ...
|
||||
|
||||
class Protocol(BaseProtocol):
|
||||
def data_received(self, data: bytes) -> None: ...
|
||||
def eof_received(self) -> bool | None: ...
|
||||
|
||||
class BufferedProtocol(BaseProtocol):
|
||||
def get_buffer(self, sizehint: int) -> ReadableBuffer: ...
|
||||
def buffer_updated(self, nbytes: int) -> None: ...
|
||||
def eof_received(self) -> bool | None: ...
|
||||
|
||||
class DatagramProtocol(BaseProtocol):
|
||||
def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override]
|
||||
# addr can be a tuple[int, int] for some unusual protocols like socket.AF_NETLINK.
|
||||
# Use tuple[str | Any, int] to not cause typechecking issues on most usual cases.
|
||||
# This could be improved by using tuple[AnyOf[str, int], int] if the AnyOf feature is accepted.
|
||||
# See https://github.com/python/typing/issues/566
|
||||
def datagram_received(self, data: bytes, addr: tuple[str | Any, int]) -> None: ...
|
||||
def error_received(self, exc: Exception) -> None: ...
|
||||
|
||||
class SubprocessProtocol(BaseProtocol):
|
||||
def pipe_data_received(self, fd: int, data: bytes) -> None: ...
|
||||
def pipe_connection_lost(self, fd: int, exc: Exception | None) -> None: ...
|
||||
def process_exited(self) -> None: ...
|
||||
@@ -1,57 +0,0 @@
|
||||
import sys
|
||||
from asyncio.events import AbstractEventLoop
|
||||
from typing import Any, Generic, TypeVar
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from .mixins import _LoopBoundMixin
|
||||
else:
|
||||
_LoopBoundMixin = object
|
||||
|
||||
class QueueEmpty(Exception): ...
|
||||
class QueueFull(Exception): ...
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 13):
|
||||
__all__ = ("Queue", "PriorityQueue", "LifoQueue", "QueueFull", "QueueEmpty", "QueueShutDown")
|
||||
|
||||
else:
|
||||
__all__ = ("Queue", "PriorityQueue", "LifoQueue", "QueueFull", "QueueEmpty")
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
class QueueShutDown(Exception): ...
|
||||
|
||||
# If Generic[_T] is last and _LoopBoundMixin is object, pyright is unhappy.
|
||||
# We can remove the noqa pragma when dropping 3.9 support.
|
||||
class Queue(Generic[_T], _LoopBoundMixin): # noqa: Y059
|
||||
if sys.version_info >= (3, 10):
|
||||
def __init__(self, maxsize: int = 0) -> None: ...
|
||||
else:
|
||||
def __init__(self, maxsize: int = 0, *, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
|
||||
def _init(self, maxsize: int) -> None: ...
|
||||
def _get(self) -> _T: ...
|
||||
def _put(self, item: _T) -> None: ...
|
||||
def _format(self) -> str: ...
|
||||
def qsize(self) -> int: ...
|
||||
@property
|
||||
def maxsize(self) -> int: ...
|
||||
def empty(self) -> bool: ...
|
||||
def full(self) -> bool: ...
|
||||
async def put(self, item: _T) -> None: ...
|
||||
def put_nowait(self, item: _T) -> None: ...
|
||||
async def get(self) -> _T: ...
|
||||
def get_nowait(self) -> _T: ...
|
||||
async def join(self) -> None: ...
|
||||
def task_done(self) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, type: Any, /) -> GenericAlias: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
def shutdown(self, immediate: bool = False) -> None: ...
|
||||
|
||||
class PriorityQueue(Queue[_T]): ...
|
||||
class LifoQueue(Queue[_T]): ...
|
||||
@@ -1,33 +0,0 @@
|
||||
import sys
|
||||
from _typeshed import Unused
|
||||
from collections.abc import Callable, Coroutine
|
||||
from contextvars import Context
|
||||
from typing import Any, TypeVar, final
|
||||
from typing_extensions import Self
|
||||
|
||||
from .events import AbstractEventLoop
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 11):
|
||||
__all__ = ("Runner", "run")
|
||||
else:
|
||||
__all__ = ("run",)
|
||||
_T = TypeVar("_T")
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
@final
|
||||
class Runner:
|
||||
def __init__(self, *, debug: bool | None = None, loop_factory: Callable[[], AbstractEventLoop] | None = None) -> None: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(self, exc_type: Unused, exc_val: Unused, exc_tb: Unused) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def get_loop(self) -> AbstractEventLoop: ...
|
||||
def run(self, coro: Coroutine[Any, Any, _T], *, context: Context | None = None) -> _T: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
def run(
|
||||
main: Coroutine[Any, Any, _T], *, debug: bool | None = ..., loop_factory: Callable[[], AbstractEventLoop] | None = ...
|
||||
) -> _T: ...
|
||||
|
||||
else:
|
||||
def run(main: Coroutine[Any, Any, _T], *, debug: bool | None = None) -> _T: ...
|
||||
@@ -1,10 +0,0 @@
|
||||
import selectors
|
||||
from socket import socket
|
||||
|
||||
from . import base_events
|
||||
|
||||
__all__ = ("BaseSelectorEventLoop",)
|
||||
|
||||
class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
||||
def __init__(self, selector: selectors.BaseSelector | None = None) -> None: ...
|
||||
async def sock_recv(self, sock: socket, n: int) -> bytes: ...
|
||||
@@ -1,165 +0,0 @@
|
||||
import ssl
|
||||
import sys
|
||||
from collections import deque
|
||||
from collections.abc import Callable
|
||||
from enum import Enum
|
||||
from typing import Any, ClassVar, Final, Literal
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from . import constants, events, futures, protocols, transports
|
||||
|
||||
def _create_transport_context(server_side: bool, server_hostname: str | None) -> ssl.SSLContext: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
SSLAgainErrors: tuple[type[ssl.SSLWantReadError], type[ssl.SSLSyscallError]]
|
||||
|
||||
class SSLProtocolState(Enum):
|
||||
UNWRAPPED = "UNWRAPPED"
|
||||
DO_HANDSHAKE = "DO_HANDSHAKE"
|
||||
WRAPPED = "WRAPPED"
|
||||
FLUSHING = "FLUSHING"
|
||||
SHUTDOWN = "SHUTDOWN"
|
||||
|
||||
class AppProtocolState(Enum):
|
||||
STATE_INIT = "STATE_INIT"
|
||||
STATE_CON_MADE = "STATE_CON_MADE"
|
||||
STATE_EOF = "STATE_EOF"
|
||||
STATE_CON_LOST = "STATE_CON_LOST"
|
||||
|
||||
def add_flowcontrol_defaults(high: int | None, low: int | None, kb: int) -> tuple[int, int]: ...
|
||||
|
||||
else:
|
||||
_UNWRAPPED: Final = "UNWRAPPED"
|
||||
_DO_HANDSHAKE: Final = "DO_HANDSHAKE"
|
||||
_WRAPPED: Final = "WRAPPED"
|
||||
_SHUTDOWN: Final = "SHUTDOWN"
|
||||
|
||||
if sys.version_info < (3, 11):
|
||||
class _SSLPipe:
|
||||
max_size: ClassVar[int]
|
||||
|
||||
_context: ssl.SSLContext
|
||||
_server_side: bool
|
||||
_server_hostname: str | None
|
||||
_state: str
|
||||
_incoming: ssl.MemoryBIO
|
||||
_outgoing: ssl.MemoryBIO
|
||||
_sslobj: ssl.SSLObject | None
|
||||
_need_ssldata: bool
|
||||
_handshake_cb: Callable[[BaseException | None], None] | None
|
||||
_shutdown_cb: Callable[[], None] | None
|
||||
def __init__(self, context: ssl.SSLContext, server_side: bool, server_hostname: str | None = None) -> None: ...
|
||||
@property
|
||||
def context(self) -> ssl.SSLContext: ...
|
||||
@property
|
||||
def ssl_object(self) -> ssl.SSLObject | None: ...
|
||||
@property
|
||||
def need_ssldata(self) -> bool: ...
|
||||
@property
|
||||
def wrapped(self) -> bool: ...
|
||||
def do_handshake(self, callback: Callable[[BaseException | None], object] | None = None) -> list[bytes]: ...
|
||||
def shutdown(self, callback: Callable[[], object] | None = None) -> list[bytes]: ...
|
||||
def feed_eof(self) -> None: ...
|
||||
def feed_ssldata(self, data: bytes, only_handshake: bool = False) -> tuple[list[bytes], list[bytes]]: ...
|
||||
def feed_appdata(self, data: bytes, offset: int = 0) -> tuple[list[bytes], int]: ...
|
||||
|
||||
class _SSLProtocolTransport(transports._FlowControlMixin, transports.Transport):
|
||||
_sendfile_compatible: ClassVar[constants._SendfileMode]
|
||||
|
||||
_loop: events.AbstractEventLoop
|
||||
if sys.version_info >= (3, 11):
|
||||
_ssl_protocol: SSLProtocol | None
|
||||
else:
|
||||
_ssl_protocol: SSLProtocol
|
||||
_closed: bool
|
||||
def __init__(self, loop: events.AbstractEventLoop, ssl_protocol: SSLProtocol) -> None: ...
|
||||
def get_extra_info(self, name: str, default: Any | None = None) -> dict[str, Any]: ...
|
||||
@property
|
||||
def _protocol_paused(self) -> bool: ...
|
||||
def write(self, data: bytes | bytearray | memoryview[Any]) -> None: ... # any memoryview format or shape
|
||||
def can_write_eof(self) -> Literal[False]: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
def get_write_buffer_limits(self) -> tuple[int, int]: ...
|
||||
def get_read_buffer_limits(self) -> tuple[int, int]: ...
|
||||
def set_read_buffer_limits(self, high: int | None = None, low: int | None = None) -> None: ...
|
||||
def get_read_buffer_size(self) -> int: ...
|
||||
|
||||
def __del__(self) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
_SSLProtocolBase: TypeAlias = protocols.BufferedProtocol
|
||||
else:
|
||||
_SSLProtocolBase: TypeAlias = protocols.Protocol
|
||||
|
||||
class SSLProtocol(_SSLProtocolBase):
|
||||
_server_side: bool
|
||||
_server_hostname: str | None
|
||||
_sslcontext: ssl.SSLContext
|
||||
_extra: dict[str, Any]
|
||||
_write_backlog: deque[tuple[bytes, int]]
|
||||
_write_buffer_size: int
|
||||
_waiter: futures.Future[Any]
|
||||
_loop: events.AbstractEventLoop
|
||||
_app_transport: _SSLProtocolTransport
|
||||
_transport: transports.BaseTransport | None
|
||||
_ssl_handshake_timeout: int | None
|
||||
_app_protocol: protocols.BaseProtocol
|
||||
_app_protocol_is_buffer: bool
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
max_size: ClassVar[int]
|
||||
else:
|
||||
_sslpipe: _SSLPipe | None
|
||||
_session_established: bool
|
||||
_call_connection_made: bool
|
||||
_in_handshake: bool
|
||||
_in_shutdown: bool
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def __init__(
|
||||
self,
|
||||
loop: events.AbstractEventLoop,
|
||||
app_protocol: protocols.BaseProtocol,
|
||||
sslcontext: ssl.SSLContext,
|
||||
waiter: futures.Future[Any],
|
||||
server_side: bool = False,
|
||||
server_hostname: str | None = None,
|
||||
call_connection_made: bool = True,
|
||||
ssl_handshake_timeout: int | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self,
|
||||
loop: events.AbstractEventLoop,
|
||||
app_protocol: protocols.BaseProtocol,
|
||||
sslcontext: ssl.SSLContext,
|
||||
waiter: futures.Future[Any],
|
||||
server_side: bool = False,
|
||||
server_hostname: str | None = None,
|
||||
call_connection_made: bool = True,
|
||||
ssl_handshake_timeout: int | None = None,
|
||||
) -> None: ...
|
||||
|
||||
def _set_app_protocol(self, app_protocol: protocols.BaseProtocol) -> None: ...
|
||||
def _wakeup_waiter(self, exc: BaseException | None = None) -> None: ...
|
||||
def connection_lost(self, exc: BaseException | None) -> None: ...
|
||||
def eof_received(self) -> None: ...
|
||||
def _get_extra_info(self, name: str, default: Any | None = None) -> Any: ...
|
||||
def _start_shutdown(self) -> None: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
def _write_appdata(self, list_of_data: list[bytes]) -> None: ...
|
||||
else:
|
||||
def _write_appdata(self, data: bytes) -> None: ...
|
||||
|
||||
def _start_handshake(self) -> None: ...
|
||||
def _check_handshake_timeout(self) -> None: ...
|
||||
def _on_handshake_complete(self, handshake_exc: BaseException | None) -> None: ...
|
||||
def _fatal_error(self, exc: BaseException, message: str = "Fatal error on transport") -> None: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
def _abort(self, exc: BaseException | None) -> None: ...
|
||||
def get_buffer(self, n: int) -> memoryview: ...
|
||||
else:
|
||||
def _abort(self) -> None: ...
|
||||
def _finalize(self) -> None: ...
|
||||
def _process_write_backlog(self) -> None: ...
|
||||
@@ -1,10 +0,0 @@
|
||||
from collections.abc import Awaitable, Callable, Iterable
|
||||
from typing import Any
|
||||
|
||||
from . import events
|
||||
|
||||
__all__ = ("staggered_race",)
|
||||
|
||||
async def staggered_race(
|
||||
coro_fns: Iterable[Callable[[], Awaitable[Any]]], delay: float | None, *, loop: events.AbstractEventLoop | None = None
|
||||
) -> tuple[Any, int | None, list[Exception | None]]: ...
|
||||
@@ -1,158 +0,0 @@
|
||||
import ssl
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer, StrPath
|
||||
from collections.abc import Awaitable, Callable, Iterable, Sequence, Sized
|
||||
from types import ModuleType
|
||||
from typing import Any, Protocol, SupportsIndex
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
from . import events, protocols, transports
|
||||
from .base_events import Server
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.platform == "win32":
|
||||
__all__ = ("StreamReader", "StreamWriter", "StreamReaderProtocol", "open_connection", "start_server")
|
||||
else:
|
||||
__all__ = (
|
||||
"StreamReader",
|
||||
"StreamWriter",
|
||||
"StreamReaderProtocol",
|
||||
"open_connection",
|
||||
"start_server",
|
||||
"open_unix_connection",
|
||||
"start_unix_server",
|
||||
)
|
||||
|
||||
_ClientConnectedCallback: TypeAlias = Callable[[StreamReader, StreamWriter], Awaitable[None] | None]
|
||||
|
||||
class _ReaduntilBuffer(ReadableBuffer, Sized, Protocol): ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
async def open_connection(
|
||||
host: str | None = None,
|
||||
port: int | str | None = None,
|
||||
*,
|
||||
limit: int = 65536,
|
||||
ssl_handshake_timeout: float | None = ...,
|
||||
**kwds: Any,
|
||||
) -> tuple[StreamReader, StreamWriter]: ...
|
||||
async def start_server(
|
||||
client_connected_cb: _ClientConnectedCallback,
|
||||
host: str | Sequence[str] | None = None,
|
||||
port: int | str | None = None,
|
||||
*,
|
||||
limit: int = 65536,
|
||||
ssl_handshake_timeout: float | None = ...,
|
||||
**kwds: Any,
|
||||
) -> Server: ...
|
||||
|
||||
else:
|
||||
async def open_connection(
|
||||
host: str | None = None,
|
||||
port: int | str | None = None,
|
||||
*,
|
||||
loop: events.AbstractEventLoop | None = None,
|
||||
limit: int = 65536,
|
||||
ssl_handshake_timeout: float | None = ...,
|
||||
**kwds: Any,
|
||||
) -> tuple[StreamReader, StreamWriter]: ...
|
||||
async def start_server(
|
||||
client_connected_cb: _ClientConnectedCallback,
|
||||
host: str | None = None,
|
||||
port: int | str | None = None,
|
||||
*,
|
||||
loop: events.AbstractEventLoop | None = None,
|
||||
limit: int = 65536,
|
||||
ssl_handshake_timeout: float | None = ...,
|
||||
**kwds: Any,
|
||||
) -> Server: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
if sys.version_info >= (3, 10):
|
||||
async def open_unix_connection(
|
||||
path: StrPath | None = None, *, limit: int = 65536, **kwds: Any
|
||||
) -> tuple[StreamReader, StreamWriter]: ...
|
||||
async def start_unix_server(
|
||||
client_connected_cb: _ClientConnectedCallback, path: StrPath | None = None, *, limit: int = 65536, **kwds: Any
|
||||
) -> Server: ...
|
||||
else:
|
||||
async def open_unix_connection(
|
||||
path: StrPath | None = None, *, loop: events.AbstractEventLoop | None = None, limit: int = 65536, **kwds: Any
|
||||
) -> tuple[StreamReader, StreamWriter]: ...
|
||||
async def start_unix_server(
|
||||
client_connected_cb: _ClientConnectedCallback,
|
||||
path: StrPath | None = None,
|
||||
*,
|
||||
loop: events.AbstractEventLoop | None = None,
|
||||
limit: int = 65536,
|
||||
**kwds: Any,
|
||||
) -> Server: ...
|
||||
|
||||
class FlowControlMixin(protocols.Protocol):
|
||||
def __init__(self, loop: events.AbstractEventLoop | None = None) -> None: ...
|
||||
|
||||
class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
|
||||
def __init__(
|
||||
self,
|
||||
stream_reader: StreamReader,
|
||||
client_connected_cb: _ClientConnectedCallback | None = None,
|
||||
loop: events.AbstractEventLoop | None = None,
|
||||
) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
|
||||
class StreamWriter:
|
||||
def __init__(
|
||||
self,
|
||||
transport: transports.WriteTransport,
|
||||
protocol: protocols.BaseProtocol,
|
||||
reader: StreamReader | None,
|
||||
loop: events.AbstractEventLoop,
|
||||
) -> None: ...
|
||||
@property
|
||||
def transport(self) -> transports.WriteTransport: ...
|
||||
def write(self, data: bytes | bytearray | memoryview) -> None: ...
|
||||
def writelines(self, data: Iterable[bytes | bytearray | memoryview]) -> None: ...
|
||||
def write_eof(self) -> None: ...
|
||||
def can_write_eof(self) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
def is_closing(self) -> bool: ...
|
||||
async def wait_closed(self) -> None: ...
|
||||
def get_extra_info(self, name: str, default: Any = None) -> Any: ...
|
||||
async def drain(self) -> None: ...
|
||||
if sys.version_info >= (3, 12):
|
||||
async def start_tls(
|
||||
self,
|
||||
sslcontext: ssl.SSLContext,
|
||||
*,
|
||||
server_hostname: str | None = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
) -> None: ...
|
||||
elif sys.version_info >= (3, 11):
|
||||
async def start_tls(
|
||||
self, sslcontext: ssl.SSLContext, *, server_hostname: str | None = None, ssl_handshake_timeout: float | None = None
|
||||
) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
def __del__(self, warnings: ModuleType = ...) -> None: ...
|
||||
elif sys.version_info >= (3, 11):
|
||||
def __del__(self) -> None: ...
|
||||
|
||||
class StreamReader:
|
||||
def __init__(self, limit: int = 65536, loop: events.AbstractEventLoop | None = None) -> None: ...
|
||||
def exception(self) -> Exception: ...
|
||||
def set_exception(self, exc: Exception) -> None: ...
|
||||
def set_transport(self, transport: transports.BaseTransport) -> None: ...
|
||||
def feed_eof(self) -> None: ...
|
||||
def at_eof(self) -> bool: ...
|
||||
def feed_data(self, data: Iterable[SupportsIndex]) -> None: ...
|
||||
async def readline(self) -> bytes: ...
|
||||
if sys.version_info >= (3, 13):
|
||||
async def readuntil(self, separator: _ReaduntilBuffer | tuple[_ReaduntilBuffer, ...] = b"\n") -> bytes: ...
|
||||
else:
|
||||
async def readuntil(self, separator: _ReaduntilBuffer = b"\n") -> bytes: ...
|
||||
|
||||
async def read(self, n: int = -1) -> bytes: ...
|
||||
async def readexactly(self, n: int) -> bytes: ...
|
||||
def __aiter__(self) -> Self: ...
|
||||
async def __anext__(self) -> bytes: ...
|
||||
@@ -1,230 +0,0 @@
|
||||
import subprocess
|
||||
import sys
|
||||
from _typeshed import StrOrBytesPath
|
||||
from asyncio import events, protocols, streams, transports
|
||||
from collections.abc import Callable, Collection
|
||||
from typing import IO, Any, Literal
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
__all__ = ("create_subprocess_exec", "create_subprocess_shell")
|
||||
|
||||
PIPE: int
|
||||
STDOUT: int
|
||||
DEVNULL: int
|
||||
|
||||
class SubprocessStreamProtocol(streams.FlowControlMixin, protocols.SubprocessProtocol):
|
||||
stdin: streams.StreamWriter | None
|
||||
stdout: streams.StreamReader | None
|
||||
stderr: streams.StreamReader | None
|
||||
def __init__(self, limit: int, loop: events.AbstractEventLoop) -> None: ...
|
||||
def pipe_data_received(self, fd: int, data: bytes | str) -> None: ...
|
||||
|
||||
class Process:
|
||||
stdin: streams.StreamWriter | None
|
||||
stdout: streams.StreamReader | None
|
||||
stderr: streams.StreamReader | None
|
||||
pid: int
|
||||
def __init__(
|
||||
self, transport: transports.BaseTransport, protocol: protocols.BaseProtocol, loop: events.AbstractEventLoop
|
||||
) -> None: ...
|
||||
@property
|
||||
def returncode(self) -> int | None: ...
|
||||
async def wait(self) -> int: ...
|
||||
def send_signal(self, signal: int) -> None: ...
|
||||
def terminate(self) -> None: ...
|
||||
def kill(self) -> None: ...
|
||||
async def communicate(self, input: bytes | bytearray | memoryview | None = None) -> tuple[bytes, bytes]: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
async def create_subprocess_shell(
|
||||
cmd: str | bytes,
|
||||
stdin: int | IO[Any] | None = None,
|
||||
stdout: int | IO[Any] | None = None,
|
||||
stderr: int | IO[Any] | None = None,
|
||||
limit: int = 65536,
|
||||
*,
|
||||
# These parameters are forced to these values by BaseEventLoop.subprocess_shell
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[True] = True,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = None,
|
||||
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
|
||||
executable: StrOrBytesPath | None = None,
|
||||
preexec_fn: Callable[[], Any] | None = None,
|
||||
close_fds: bool = True,
|
||||
cwd: StrOrBytesPath | None = None,
|
||||
env: subprocess._ENV | None = None,
|
||||
startupinfo: Any | None = None,
|
||||
creationflags: int = 0,
|
||||
restore_signals: bool = True,
|
||||
start_new_session: bool = False,
|
||||
pass_fds: Collection[int] = ...,
|
||||
group: None | str | int = None,
|
||||
extra_groups: None | Collection[str | int] = None,
|
||||
user: None | str | int = None,
|
||||
umask: int = -1,
|
||||
process_group: int | None = None,
|
||||
pipesize: int = -1,
|
||||
) -> Process: ...
|
||||
async def create_subprocess_exec(
|
||||
program: StrOrBytesPath,
|
||||
*args: StrOrBytesPath,
|
||||
stdin: int | IO[Any] | None = None,
|
||||
stdout: int | IO[Any] | None = None,
|
||||
stderr: int | IO[Any] | None = None,
|
||||
limit: int = 65536,
|
||||
# These parameters are forced to these values by BaseEventLoop.subprocess_exec
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[False] = False,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = None,
|
||||
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
|
||||
executable: StrOrBytesPath | None = None,
|
||||
preexec_fn: Callable[[], Any] | None = None,
|
||||
close_fds: bool = True,
|
||||
cwd: StrOrBytesPath | None = None,
|
||||
env: subprocess._ENV | None = None,
|
||||
startupinfo: Any | None = None,
|
||||
creationflags: int = 0,
|
||||
restore_signals: bool = True,
|
||||
start_new_session: bool = False,
|
||||
pass_fds: Collection[int] = ...,
|
||||
group: None | str | int = None,
|
||||
extra_groups: None | Collection[str | int] = None,
|
||||
user: None | str | int = None,
|
||||
umask: int = -1,
|
||||
process_group: int | None = None,
|
||||
pipesize: int = -1,
|
||||
) -> Process: ...
|
||||
|
||||
elif sys.version_info >= (3, 10):
|
||||
async def create_subprocess_shell(
|
||||
cmd: str | bytes,
|
||||
stdin: int | IO[Any] | None = None,
|
||||
stdout: int | IO[Any] | None = None,
|
||||
stderr: int | IO[Any] | None = None,
|
||||
limit: int = 65536,
|
||||
*,
|
||||
# These parameters are forced to these values by BaseEventLoop.subprocess_shell
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[True] = True,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = None,
|
||||
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
|
||||
executable: StrOrBytesPath | None = None,
|
||||
preexec_fn: Callable[[], Any] | None = None,
|
||||
close_fds: bool = True,
|
||||
cwd: StrOrBytesPath | None = None,
|
||||
env: subprocess._ENV | None = None,
|
||||
startupinfo: Any | None = None,
|
||||
creationflags: int = 0,
|
||||
restore_signals: bool = True,
|
||||
start_new_session: bool = False,
|
||||
pass_fds: Collection[int] = ...,
|
||||
group: None | str | int = None,
|
||||
extra_groups: None | Collection[str | int] = None,
|
||||
user: None | str | int = None,
|
||||
umask: int = -1,
|
||||
pipesize: int = -1,
|
||||
) -> Process: ...
|
||||
async def create_subprocess_exec(
|
||||
program: StrOrBytesPath,
|
||||
*args: StrOrBytesPath,
|
||||
stdin: int | IO[Any] | None = None,
|
||||
stdout: int | IO[Any] | None = None,
|
||||
stderr: int | IO[Any] | None = None,
|
||||
limit: int = 65536,
|
||||
# These parameters are forced to these values by BaseEventLoop.subprocess_exec
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[False] = False,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = None,
|
||||
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
|
||||
executable: StrOrBytesPath | None = None,
|
||||
preexec_fn: Callable[[], Any] | None = None,
|
||||
close_fds: bool = True,
|
||||
cwd: StrOrBytesPath | None = None,
|
||||
env: subprocess._ENV | None = None,
|
||||
startupinfo: Any | None = None,
|
||||
creationflags: int = 0,
|
||||
restore_signals: bool = True,
|
||||
start_new_session: bool = False,
|
||||
pass_fds: Collection[int] = ...,
|
||||
group: None | str | int = None,
|
||||
extra_groups: None | Collection[str | int] = None,
|
||||
user: None | str | int = None,
|
||||
umask: int = -1,
|
||||
pipesize: int = -1,
|
||||
) -> Process: ...
|
||||
|
||||
else: # >= 3.9
|
||||
async def create_subprocess_shell(
|
||||
cmd: str | bytes,
|
||||
stdin: int | IO[Any] | None = None,
|
||||
stdout: int | IO[Any] | None = None,
|
||||
stderr: int | IO[Any] | None = None,
|
||||
loop: events.AbstractEventLoop | None = None,
|
||||
limit: int = 65536,
|
||||
*,
|
||||
# These parameters are forced to these values by BaseEventLoop.subprocess_shell
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[True] = True,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = None,
|
||||
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
|
||||
executable: StrOrBytesPath | None = None,
|
||||
preexec_fn: Callable[[], Any] | None = None,
|
||||
close_fds: bool = True,
|
||||
cwd: StrOrBytesPath | None = None,
|
||||
env: subprocess._ENV | None = None,
|
||||
startupinfo: Any | None = None,
|
||||
creationflags: int = 0,
|
||||
restore_signals: bool = True,
|
||||
start_new_session: bool = False,
|
||||
pass_fds: Collection[int] = ...,
|
||||
group: None | str | int = None,
|
||||
extra_groups: None | Collection[str | int] = None,
|
||||
user: None | str | int = None,
|
||||
umask: int = -1,
|
||||
) -> Process: ...
|
||||
async def create_subprocess_exec(
|
||||
program: StrOrBytesPath,
|
||||
*args: StrOrBytesPath,
|
||||
stdin: int | IO[Any] | None = None,
|
||||
stdout: int | IO[Any] | None = None,
|
||||
stderr: int | IO[Any] | None = None,
|
||||
loop: events.AbstractEventLoop | None = None,
|
||||
limit: int = 65536,
|
||||
# These parameters are forced to these values by BaseEventLoop.subprocess_exec
|
||||
universal_newlines: Literal[False] = False,
|
||||
shell: Literal[False] = False,
|
||||
bufsize: Literal[0] = 0,
|
||||
encoding: None = None,
|
||||
errors: None = None,
|
||||
text: Literal[False] | None = None,
|
||||
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
|
||||
executable: StrOrBytesPath | None = None,
|
||||
preexec_fn: Callable[[], Any] | None = None,
|
||||
close_fds: bool = True,
|
||||
cwd: StrOrBytesPath | None = None,
|
||||
env: subprocess._ENV | None = None,
|
||||
startupinfo: Any | None = None,
|
||||
creationflags: int = 0,
|
||||
restore_signals: bool = True,
|
||||
start_new_session: bool = False,
|
||||
pass_fds: Collection[int] = ...,
|
||||
group: None | str | int = None,
|
||||
extra_groups: None | Collection[str | int] = None,
|
||||
user: None | str | int = None,
|
||||
umask: int = -1,
|
||||
) -> Process: ...
|
||||
@@ -1,26 +0,0 @@
|
||||
import sys
|
||||
from contextvars import Context
|
||||
from types import TracebackType
|
||||
from typing import Any, TypeVar
|
||||
from typing_extensions import Self
|
||||
|
||||
from . import _CoroutineLike
|
||||
from .events import AbstractEventLoop
|
||||
from .tasks import Task
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 12):
|
||||
__all__ = ("TaskGroup",)
|
||||
else:
|
||||
__all__ = ["TaskGroup"]
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
class TaskGroup:
|
||||
_loop: AbstractEventLoop | None
|
||||
_tasks: set[Task[Any]]
|
||||
|
||||
async def __aenter__(self) -> Self: ...
|
||||
async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ...
|
||||
def create_task(self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None) -> Task[_T]: ...
|
||||
def _on_task_done(self, task: Task[object]) -> None: ...
|
||||
@@ -1,462 +0,0 @@
|
||||
import concurrent.futures
|
||||
import sys
|
||||
from _asyncio import (
|
||||
Task as Task,
|
||||
_enter_task as _enter_task,
|
||||
_leave_task as _leave_task,
|
||||
_register_task as _register_task,
|
||||
_unregister_task as _unregister_task,
|
||||
)
|
||||
from collections.abc import AsyncIterator, Awaitable, Coroutine, Generator, Iterable, Iterator
|
||||
from typing import Any, Literal, Protocol, TypeVar, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from . import _CoroutineLike
|
||||
from .events import AbstractEventLoop
|
||||
from .futures import Future
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from contextvars import Context
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.version_info >= (3, 12):
|
||||
__all__ = (
|
||||
"Task",
|
||||
"create_task",
|
||||
"FIRST_COMPLETED",
|
||||
"FIRST_EXCEPTION",
|
||||
"ALL_COMPLETED",
|
||||
"wait",
|
||||
"wait_for",
|
||||
"as_completed",
|
||||
"sleep",
|
||||
"gather",
|
||||
"shield",
|
||||
"ensure_future",
|
||||
"run_coroutine_threadsafe",
|
||||
"current_task",
|
||||
"all_tasks",
|
||||
"create_eager_task_factory",
|
||||
"eager_task_factory",
|
||||
"_register_task",
|
||||
"_unregister_task",
|
||||
"_enter_task",
|
||||
"_leave_task",
|
||||
)
|
||||
else:
|
||||
__all__ = (
|
||||
"Task",
|
||||
"create_task",
|
||||
"FIRST_COMPLETED",
|
||||
"FIRST_EXCEPTION",
|
||||
"ALL_COMPLETED",
|
||||
"wait",
|
||||
"wait_for",
|
||||
"as_completed",
|
||||
"sleep",
|
||||
"gather",
|
||||
"shield",
|
||||
"ensure_future",
|
||||
"run_coroutine_threadsafe",
|
||||
"current_task",
|
||||
"all_tasks",
|
||||
"_register_task",
|
||||
"_unregister_task",
|
||||
"_enter_task",
|
||||
"_leave_task",
|
||||
)
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_T_co = TypeVar("_T_co", covariant=True)
|
||||
_T1 = TypeVar("_T1")
|
||||
_T2 = TypeVar("_T2")
|
||||
_T3 = TypeVar("_T3")
|
||||
_T4 = TypeVar("_T4")
|
||||
_T5 = TypeVar("_T5")
|
||||
_T6 = TypeVar("_T6")
|
||||
_FT = TypeVar("_FT", bound=Future[Any])
|
||||
if sys.version_info >= (3, 12):
|
||||
_FutureLike: TypeAlias = Future[_T] | Awaitable[_T]
|
||||
else:
|
||||
_FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T]
|
||||
|
||||
_TaskYieldType: TypeAlias = Future[object] | None
|
||||
|
||||
FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED
|
||||
FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION
|
||||
ALL_COMPLETED = concurrent.futures.ALL_COMPLETED
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
class _SyncAndAsyncIterator(Iterator[_T_co], AsyncIterator[_T_co], Protocol[_T_co]): ...
|
||||
|
||||
def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> _SyncAndAsyncIterator[Future[_T]]: ...
|
||||
|
||||
elif sys.version_info >= (3, 10):
|
||||
def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> Iterator[Future[_T]]: ...
|
||||
|
||||
else:
|
||||
def as_completed(
|
||||
fs: Iterable[_FutureLike[_T]], *, loop: AbstractEventLoop | None = None, timeout: float | None = None
|
||||
) -> Iterator[Future[_T]]: ...
|
||||
|
||||
@overload
|
||||
def ensure_future(coro_or_future: _FT, *, loop: AbstractEventLoop | None = None) -> _FT: ... # type: ignore[overload-overlap]
|
||||
@overload
|
||||
def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | None = None) -> Task[_T]: ...
|
||||
|
||||
# `gather()` actually returns a list with length equal to the number
|
||||
# of tasks passed; however, Tuple is used similar to the annotation for
|
||||
# zip() because typing does not support variadic type variables. See
|
||||
# typing PR #1550 for discussion.
|
||||
#
|
||||
# N.B. Having overlapping overloads is the only way to get acceptable type inference in all edge cases.
|
||||
if sys.version_info >= (3, 10):
|
||||
@overload
|
||||
def gather(coro_or_future1: _FutureLike[_T1], /, *, return_exceptions: Literal[False] = False) -> Future[tuple[_T1]]: ... # type: ignore[overload-overlap]
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1], coro_or_future2: _FutureLike[_T2], /, *, return_exceptions: Literal[False] = False
|
||||
) -> Future[tuple[_T1, _T2]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
/,
|
||||
*,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
/,
|
||||
*,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
coro_or_future5: _FutureLike[_T5],
|
||||
/,
|
||||
*,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
coro_or_future5: _FutureLike[_T5],
|
||||
coro_or_future6: _FutureLike[_T6],
|
||||
/,
|
||||
*,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ...
|
||||
@overload
|
||||
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: Literal[False] = False) -> Future[list[_T]]: ... # type: ignore[overload-overlap]
|
||||
@overload
|
||||
def gather(coro_or_future1: _FutureLike[_T1], /, *, return_exceptions: bool) -> Future[tuple[_T1 | BaseException]]: ...
|
||||
@overload
|
||||
def gather(
|
||||
coro_or_future1: _FutureLike[_T1], coro_or_future2: _FutureLike[_T2], /, *, return_exceptions: bool
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ...
|
||||
@overload
|
||||
def gather(
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
/,
|
||||
*,
|
||||
return_exceptions: bool,
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ...
|
||||
@overload
|
||||
def gather(
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
/,
|
||||
*,
|
||||
return_exceptions: bool,
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ...
|
||||
@overload
|
||||
def gather(
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
coro_or_future5: _FutureLike[_T5],
|
||||
/,
|
||||
*,
|
||||
return_exceptions: bool,
|
||||
) -> Future[
|
||||
tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException]
|
||||
]: ...
|
||||
@overload
|
||||
def gather(
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
coro_or_future5: _FutureLike[_T5],
|
||||
coro_or_future6: _FutureLike[_T6],
|
||||
/,
|
||||
*,
|
||||
return_exceptions: bool,
|
||||
) -> Future[
|
||||
tuple[
|
||||
_T1 | BaseException,
|
||||
_T2 | BaseException,
|
||||
_T3 | BaseException,
|
||||
_T4 | BaseException,
|
||||
_T5 | BaseException,
|
||||
_T6 | BaseException,
|
||||
]
|
||||
]: ...
|
||||
@overload
|
||||
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: bool) -> Future[list[_T | BaseException]]: ...
|
||||
|
||||
else:
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1], /, *, loop: AbstractEventLoop | None = None, return_exceptions: Literal[False] = False
|
||||
) -> Future[tuple[_T1]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
coro_or_future5: _FutureLike[_T5],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
coro_or_future5: _FutureLike[_T5],
|
||||
coro_or_future6: _FutureLike[_T6],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
*coros_or_futures: _FutureLike[_T], loop: AbstractEventLoop | None = None, return_exceptions: Literal[False] = False
|
||||
) -> Future[list[_T]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1], /, *, loop: AbstractEventLoop | None = None, return_exceptions: bool
|
||||
) -> Future[tuple[_T1 | BaseException]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: bool,
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: bool,
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: bool,
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[overload-overlap]
|
||||
coro_or_future1: _FutureLike[_T1],
|
||||
coro_or_future2: _FutureLike[_T2],
|
||||
coro_or_future3: _FutureLike[_T3],
|
||||
coro_or_future4: _FutureLike[_T4],
|
||||
coro_or_future5: _FutureLike[_T5],
|
||||
coro_or_future6: _FutureLike[_T6],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: bool,
|
||||
) -> Future[
|
||||
tuple[
|
||||
_T1 | BaseException,
|
||||
_T2 | BaseException,
|
||||
_T3 | BaseException,
|
||||
_T4 | BaseException,
|
||||
_T5 | BaseException,
|
||||
_T6 | BaseException,
|
||||
]
|
||||
]: ...
|
||||
@overload
|
||||
def gather(
|
||||
*coros_or_futures: _FutureLike[_T], loop: AbstractEventLoop | None = None, return_exceptions: bool
|
||||
) -> Future[list[_T | BaseException]]: ...
|
||||
|
||||
# unlike some asyncio apis, This does strict runtime checking of actually being a coroutine, not of any future-like.
|
||||
def run_coroutine_threadsafe(coro: Coroutine[Any, Any, _T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
def shield(arg: _FutureLike[_T]) -> Future[_T]: ...
|
||||
@overload
|
||||
async def sleep(delay: float) -> None: ...
|
||||
@overload
|
||||
async def sleep(delay: float, result: _T) -> _T: ...
|
||||
async def wait_for(fut: _FutureLike[_T], timeout: float | None) -> _T: ...
|
||||
|
||||
else:
|
||||
def shield(arg: _FutureLike[_T], *, loop: AbstractEventLoop | None = None) -> Future[_T]: ...
|
||||
@overload
|
||||
async def sleep(delay: float, *, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
@overload
|
||||
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = None) -> _T: ...
|
||||
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
@overload
|
||||
async def wait(
|
||||
fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
|
||||
) -> tuple[set[_FT], set[_FT]]: ...
|
||||
@overload
|
||||
async def wait(
|
||||
fs: Iterable[Task[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
|
||||
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
|
||||
|
||||
elif sys.version_info >= (3, 10):
|
||||
@overload
|
||||
async def wait( # type: ignore[overload-overlap]
|
||||
fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
|
||||
) -> tuple[set[_FT], set[_FT]]: ...
|
||||
@overload
|
||||
async def wait(
|
||||
fs: Iterable[Awaitable[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
|
||||
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
|
||||
|
||||
else:
|
||||
@overload
|
||||
async def wait( # type: ignore[overload-overlap]
|
||||
fs: Iterable[_FT],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
timeout: float | None = None,
|
||||
return_when: str = "ALL_COMPLETED",
|
||||
) -> tuple[set[_FT], set[_FT]]: ...
|
||||
@overload
|
||||
async def wait(
|
||||
fs: Iterable[Awaitable[_T]],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
timeout: float | None = None,
|
||||
return_when: str = "ALL_COMPLETED",
|
||||
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
_TaskCompatibleCoro: TypeAlias = Coroutine[Any, Any, _T_co]
|
||||
elif sys.version_info >= (3, 9):
|
||||
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Coroutine[Any, Any, _T_co]
|
||||
else:
|
||||
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co]
|
||||
|
||||
def all_tasks(loop: AbstractEventLoop | None = None) -> set[Task[Any]]: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def create_task(coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None) -> Task[_T]: ...
|
||||
|
||||
else:
|
||||
def create_task(coro: _CoroutineLike[_T], *, name: str | None = None) -> Task[_T]: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
from _asyncio import current_task as current_task
|
||||
else:
|
||||
def current_task(loop: AbstractEventLoop | None = None) -> Task[Any] | None: ...
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
_TaskT_co = TypeVar("_TaskT_co", bound=Task[Any], covariant=True)
|
||||
|
||||
class _CustomTaskConstructor(Protocol[_TaskT_co]):
|
||||
def __call__(
|
||||
self,
|
||||
coro: _TaskCompatibleCoro[Any],
|
||||
/,
|
||||
*,
|
||||
loop: AbstractEventLoop,
|
||||
name: str | None,
|
||||
context: Context | None,
|
||||
eager_start: bool,
|
||||
) -> _TaskT_co: ...
|
||||
|
||||
class _EagerTaskFactoryType(Protocol[_TaskT_co]):
|
||||
def __call__(
|
||||
self,
|
||||
loop: AbstractEventLoop,
|
||||
coro: _TaskCompatibleCoro[Any],
|
||||
*,
|
||||
name: str | None = None,
|
||||
context: Context | None = None,
|
||||
) -> _TaskT_co: ...
|
||||
|
||||
def create_eager_task_factory(
|
||||
custom_task_constructor: _CustomTaskConstructor[_TaskT_co],
|
||||
) -> _EagerTaskFactoryType[_TaskT_co]: ...
|
||||
def eager_task_factory(
|
||||
loop: AbstractEventLoop | None,
|
||||
coro: _TaskCompatibleCoro[_T_co],
|
||||
*,
|
||||
name: str | None = None,
|
||||
context: Context | None = None,
|
||||
) -> Task[_T_co]: ...
|
||||
@@ -1,10 +0,0 @@
|
||||
from collections.abc import Callable
|
||||
from typing import TypeVar
|
||||
from typing_extensions import ParamSpec
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
__all__ = ("to_thread",)
|
||||
_P = ParamSpec("_P")
|
||||
_R = TypeVar("_R")
|
||||
|
||||
async def to_thread(func: Callable[_P, _R], /, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
|
||||
@@ -1,20 +0,0 @@
|
||||
from types import TracebackType
|
||||
from typing import final
|
||||
from typing_extensions import Self
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
__all__ = ("Timeout", "timeout", "timeout_at")
|
||||
|
||||
@final
|
||||
class Timeout:
|
||||
def __init__(self, when: float | None) -> None: ...
|
||||
def when(self) -> float | None: ...
|
||||
def reschedule(self, when: float | None) -> None: ...
|
||||
def expired(self) -> bool: ...
|
||||
async def __aenter__(self) -> Self: ...
|
||||
async def __aexit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
def timeout(delay: float | None) -> Timeout: ...
|
||||
def timeout_at(when: float | None) -> Timeout: ...
|
||||
@@ -1,50 +0,0 @@
|
||||
from asyncio.events import AbstractEventLoop
|
||||
from asyncio.protocols import BaseProtocol
|
||||
from collections.abc import Iterable, Mapping
|
||||
from socket import _Address
|
||||
from typing import Any
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
__all__ = ("BaseTransport", "ReadTransport", "WriteTransport", "Transport", "DatagramTransport", "SubprocessTransport")
|
||||
|
||||
class BaseTransport:
|
||||
def __init__(self, extra: Mapping[str, Any] | None = None) -> None: ...
|
||||
def get_extra_info(self, name: str, default: Any = None) -> Any: ...
|
||||
def is_closing(self) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
def set_protocol(self, protocol: BaseProtocol) -> None: ...
|
||||
def get_protocol(self) -> BaseProtocol: ...
|
||||
|
||||
class ReadTransport(BaseTransport):
|
||||
def is_reading(self) -> bool: ...
|
||||
def pause_reading(self) -> None: ...
|
||||
def resume_reading(self) -> None: ...
|
||||
|
||||
class WriteTransport(BaseTransport):
|
||||
def set_write_buffer_limits(self, high: int | None = None, low: int | None = None) -> None: ...
|
||||
def get_write_buffer_size(self) -> int: ...
|
||||
def get_write_buffer_limits(self) -> tuple[int, int]: ...
|
||||
def write(self, data: bytes | bytearray | memoryview[Any]) -> None: ... # any memoryview format or shape
|
||||
def writelines(
|
||||
self, list_of_data: Iterable[bytes | bytearray | memoryview[Any]]
|
||||
) -> None: ... # any memoryview format or shape
|
||||
def write_eof(self) -> None: ...
|
||||
def can_write_eof(self) -> bool: ...
|
||||
def abort(self) -> None: ...
|
||||
|
||||
class Transport(ReadTransport, WriteTransport): ...
|
||||
|
||||
class DatagramTransport(BaseTransport):
|
||||
def sendto(self, data: bytes | bytearray | memoryview, addr: _Address | None = None) -> None: ...
|
||||
def abort(self) -> None: ...
|
||||
|
||||
class SubprocessTransport(BaseTransport):
|
||||
def get_pid(self) -> int: ...
|
||||
def get_returncode(self) -> int | None: ...
|
||||
def get_pipe_transport(self, fd: int) -> BaseTransport | None: ...
|
||||
def send_signal(self, signal: int) -> None: ...
|
||||
def terminate(self) -> None: ...
|
||||
def kill(self) -> None: ...
|
||||
|
||||
class _FlowControlMixin(Transport):
|
||||
def __init__(self, extra: Mapping[str, Any] | None = None, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
@@ -1,94 +0,0 @@
|
||||
import socket
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer
|
||||
from builtins import type as Type # alias to avoid name clashes with property named "type"
|
||||
from collections.abc import Iterable
|
||||
from types import TracebackType
|
||||
from typing import Any, BinaryIO, NoReturn, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
# These are based in socket, maybe move them out into _typeshed.pyi or such
|
||||
_Address: TypeAlias = socket._Address
|
||||
_RetAddress: TypeAlias = Any
|
||||
_WriteBuffer: TypeAlias = bytearray | memoryview
|
||||
_CMSG: TypeAlias = tuple[int, int, bytes]
|
||||
|
||||
class TransportSocket:
|
||||
def __init__(self, sock: socket.socket) -> None: ...
|
||||
@property
|
||||
def family(self) -> int: ...
|
||||
@property
|
||||
def type(self) -> int: ...
|
||||
@property
|
||||
def proto(self) -> int: ...
|
||||
def __getstate__(self) -> NoReturn: ...
|
||||
def fileno(self) -> int: ...
|
||||
def dup(self) -> socket.socket: ...
|
||||
def get_inheritable(self) -> bool: ...
|
||||
def shutdown(self, how: int) -> None: ...
|
||||
@overload
|
||||
def getsockopt(self, level: int, optname: int) -> int: ...
|
||||
@overload
|
||||
def getsockopt(self, level: int, optname: int, buflen: int) -> bytes: ...
|
||||
@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: ...
|
||||
def getpeername(self) -> _RetAddress: ...
|
||||
def getsockname(self) -> _RetAddress: ...
|
||||
def getsockbyname(self) -> NoReturn: ... # This method doesn't exist on socket, yet is passed through?
|
||||
def settimeout(self, value: float | None) -> None: ...
|
||||
def gettimeout(self) -> float | None: ...
|
||||
def setblocking(self, flag: bool) -> None: ...
|
||||
if sys.version_info < (3, 11):
|
||||
def _na(self, what: str) -> None: ...
|
||||
def accept(self) -> tuple[socket.socket, _RetAddress]: ...
|
||||
def connect(self, address: _Address) -> None: ...
|
||||
def connect_ex(self, address: _Address) -> int: ...
|
||||
def bind(self, address: _Address) -> None: ...
|
||||
if sys.platform == "win32":
|
||||
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> None: ...
|
||||
else:
|
||||
def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> NoReturn: ...
|
||||
|
||||
def listen(self, backlog: int = ..., /) -> None: ...
|
||||
def makefile(self) -> BinaryIO: ...
|
||||
def sendfile(self, file: BinaryIO, offset: int = ..., count: int | None = ...) -> int: ...
|
||||
def close(self) -> None: ...
|
||||
def detach(self) -> int: ...
|
||||
if sys.platform == "linux":
|
||||
def sendmsg_afalg(
|
||||
self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ...
|
||||
) -> int: ...
|
||||
else:
|
||||
def sendmsg_afalg(
|
||||
self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ...
|
||||
) -> NoReturn: ...
|
||||
|
||||
def sendmsg(
|
||||
self, buffers: Iterable[ReadableBuffer], ancdata: Iterable[_CMSG] = ..., flags: int = ..., address: _Address = ..., /
|
||||
) -> int: ...
|
||||
@overload
|
||||
def sendto(self, data: ReadableBuffer, address: _Address) -> int: ...
|
||||
@overload
|
||||
def sendto(self, data: ReadableBuffer, flags: int, address: _Address) -> int: ...
|
||||
def send(self, data: ReadableBuffer, flags: int = ...) -> int: ...
|
||||
def sendall(self, data: ReadableBuffer, flags: int = ...) -> None: ...
|
||||
def set_inheritable(self, inheritable: bool) -> None: ...
|
||||
if sys.platform == "win32":
|
||||
def share(self, process_id: int) -> bytes: ...
|
||||
else:
|
||||
def share(self, process_id: int) -> NoReturn: ...
|
||||
|
||||
def recv_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> int: ...
|
||||
def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> tuple[int, _RetAddress]: ...
|
||||
def recvmsg_into(
|
||||
self, buffers: Iterable[_WriteBuffer], ancbufsize: int = ..., flags: int = ..., /
|
||||
) -> tuple[int, list[_CMSG], int, Any]: ...
|
||||
def recvmsg(self, bufsize: int, ancbufsize: int = ..., flags: int = ..., /) -> tuple[bytes, list[_CMSG], int, Any]: ...
|
||||
def recvfrom(self, bufsize: int, flags: int = ...) -> tuple[bytes, _RetAddress]: ...
|
||||
def recv(self, bufsize: int, flags: int = ...) -> bytes: ...
|
||||
def __enter__(self) -> socket.socket: ...
|
||||
def __exit__(
|
||||
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
@@ -1,254 +0,0 @@
|
||||
import sys
|
||||
import types
|
||||
from _typeshed import StrPath
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections.abc import Callable
|
||||
from socket import socket
|
||||
from typing import Literal
|
||||
from typing_extensions import Self, TypeVarTuple, Unpack, deprecated
|
||||
|
||||
from .base_events import Server, _ProtocolFactory, _SSLContext
|
||||
from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy
|
||||
from .selector_events import BaseSelectorEventLoop
|
||||
|
||||
_Ts = TypeVarTuple("_Ts")
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.platform != "win32":
|
||||
if sys.version_info >= (3, 14):
|
||||
__all__ = ("SelectorEventLoop", "DefaultEventLoopPolicy", "EventLoop")
|
||||
elif sys.version_info >= (3, 13):
|
||||
# Adds EventLoop
|
||||
__all__ = (
|
||||
"SelectorEventLoop",
|
||||
"AbstractChildWatcher",
|
||||
"SafeChildWatcher",
|
||||
"FastChildWatcher",
|
||||
"PidfdChildWatcher",
|
||||
"MultiLoopChildWatcher",
|
||||
"ThreadedChildWatcher",
|
||||
"DefaultEventLoopPolicy",
|
||||
"EventLoop",
|
||||
)
|
||||
elif sys.version_info >= (3, 9):
|
||||
# adds PidfdChildWatcher
|
||||
__all__ = (
|
||||
"SelectorEventLoop",
|
||||
"AbstractChildWatcher",
|
||||
"SafeChildWatcher",
|
||||
"FastChildWatcher",
|
||||
"PidfdChildWatcher",
|
||||
"MultiLoopChildWatcher",
|
||||
"ThreadedChildWatcher",
|
||||
"DefaultEventLoopPolicy",
|
||||
)
|
||||
else:
|
||||
__all__ = (
|
||||
"SelectorEventLoop",
|
||||
"AbstractChildWatcher",
|
||||
"SafeChildWatcher",
|
||||
"FastChildWatcher",
|
||||
"MultiLoopChildWatcher",
|
||||
"ThreadedChildWatcher",
|
||||
"DefaultEventLoopPolicy",
|
||||
)
|
||||
|
||||
# This is also technically not available on Win,
|
||||
# but other parts of typeshed need this definition.
|
||||
# So, it is special cased.
|
||||
if sys.version_info < (3, 14):
|
||||
if sys.version_info >= (3, 12):
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
class AbstractChildWatcher:
|
||||
@abstractmethod
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
@abstractmethod
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
@abstractmethod
|
||||
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
@abstractmethod
|
||||
def close(self) -> None: ...
|
||||
@abstractmethod
|
||||
def __enter__(self) -> Self: ...
|
||||
@abstractmethod
|
||||
def __exit__(
|
||||
self, typ: type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None
|
||||
) -> None: ...
|
||||
@abstractmethod
|
||||
def is_active(self) -> bool: ...
|
||||
|
||||
else:
|
||||
class AbstractChildWatcher:
|
||||
@abstractmethod
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
@abstractmethod
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
@abstractmethod
|
||||
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
@abstractmethod
|
||||
def close(self) -> None: ...
|
||||
@abstractmethod
|
||||
def __enter__(self) -> Self: ...
|
||||
@abstractmethod
|
||||
def __exit__(
|
||||
self, typ: type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None
|
||||
) -> None: ...
|
||||
@abstractmethod
|
||||
def is_active(self) -> bool: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
if sys.version_info < (3, 14):
|
||||
if sys.version_info >= (3, 12):
|
||||
# Doesn't actually have ABCMeta metaclass at runtime, but mypy complains if we don't have it in the stub.
|
||||
# See discussion in #7412
|
||||
class BaseChildWatcher(AbstractChildWatcher, metaclass=ABCMeta):
|
||||
def close(self) -> None: ...
|
||||
def is_active(self) -> bool: ...
|
||||
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
class SafeChildWatcher(BaseChildWatcher):
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None
|
||||
) -> None: ...
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
class FastChildWatcher(BaseChildWatcher):
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None
|
||||
) -> None: ...
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
|
||||
else:
|
||||
# Doesn't actually have ABCMeta metaclass at runtime, but mypy complains if we don't have it in the stub.
|
||||
# See discussion in #7412
|
||||
class BaseChildWatcher(AbstractChildWatcher, metaclass=ABCMeta):
|
||||
def close(self) -> None: ...
|
||||
def is_active(self) -> bool: ...
|
||||
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
|
||||
class SafeChildWatcher(BaseChildWatcher):
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None
|
||||
) -> None: ...
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
|
||||
class FastChildWatcher(BaseChildWatcher):
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None
|
||||
) -> None: ...
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
|
||||
class _UnixSelectorEventLoop(BaseSelectorEventLoop):
|
||||
if sys.version_info >= (3, 13):
|
||||
async def create_unix_server(
|
||||
self,
|
||||
protocol_factory: _ProtocolFactory,
|
||||
path: StrPath | None = None,
|
||||
*,
|
||||
sock: socket | None = None,
|
||||
backlog: int = 100,
|
||||
ssl: _SSLContext = None,
|
||||
ssl_handshake_timeout: float | None = None,
|
||||
ssl_shutdown_timeout: float | None = None,
|
||||
start_serving: bool = True,
|
||||
cleanup_socket: bool = True,
|
||||
) -> Server: ...
|
||||
|
||||
class _UnixDefaultEventLoopPolicy(BaseDefaultEventLoopPolicy):
|
||||
if sys.version_info < (3, 14):
|
||||
if sys.version_info >= (3, 12):
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
def get_child_watcher(self) -> AbstractChildWatcher: ...
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
def set_child_watcher(self, watcher: AbstractChildWatcher | None) -> None: ...
|
||||
else:
|
||||
def get_child_watcher(self) -> AbstractChildWatcher: ...
|
||||
def set_child_watcher(self, watcher: AbstractChildWatcher | None) -> None: ...
|
||||
|
||||
SelectorEventLoop = _UnixSelectorEventLoop
|
||||
|
||||
DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
EventLoop = SelectorEventLoop
|
||||
|
||||
if sys.version_info < (3, 14):
|
||||
if sys.version_info >= (3, 12):
|
||||
@deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14")
|
||||
class MultiLoopChildWatcher(AbstractChildWatcher):
|
||||
def is_active(self) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
|
||||
) -> None: ...
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
|
||||
else:
|
||||
class MultiLoopChildWatcher(AbstractChildWatcher):
|
||||
def is_active(self) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
|
||||
) -> None: ...
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
|
||||
if sys.version_info < (3, 14):
|
||||
class ThreadedChildWatcher(AbstractChildWatcher):
|
||||
def is_active(self) -> Literal[True]: ...
|
||||
def close(self) -> None: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
|
||||
) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
class PidfdChildWatcher(AbstractChildWatcher):
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
|
||||
) -> None: ...
|
||||
def is_active(self) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
|
||||
def add_child_handler(
|
||||
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
|
||||
) -> None: ...
|
||||
def remove_child_handler(self, pid: int) -> bool: ...
|
||||
@@ -1,101 +0,0 @@
|
||||
import socket
|
||||
import sys
|
||||
from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer
|
||||
from collections.abc import Callable
|
||||
from typing import IO, Any, ClassVar, Final, NoReturn
|
||||
|
||||
from . import events, futures, proactor_events, selector_events, streams, windows_utils
|
||||
|
||||
# Keep asyncio.__all__ updated with any changes to __all__ here
|
||||
if sys.platform == "win32":
|
||||
if sys.version_info >= (3, 13):
|
||||
# 3.13 added `EventLoop`.
|
||||
__all__ = (
|
||||
"SelectorEventLoop",
|
||||
"ProactorEventLoop",
|
||||
"IocpProactor",
|
||||
"DefaultEventLoopPolicy",
|
||||
"WindowsSelectorEventLoopPolicy",
|
||||
"WindowsProactorEventLoopPolicy",
|
||||
"EventLoop",
|
||||
)
|
||||
else:
|
||||
__all__ = (
|
||||
"SelectorEventLoop",
|
||||
"ProactorEventLoop",
|
||||
"IocpProactor",
|
||||
"DefaultEventLoopPolicy",
|
||||
"WindowsSelectorEventLoopPolicy",
|
||||
"WindowsProactorEventLoopPolicy",
|
||||
)
|
||||
|
||||
NULL: Final = 0
|
||||
INFINITE: Final = 0xFFFFFFFF
|
||||
ERROR_CONNECTION_REFUSED: Final = 1225
|
||||
ERROR_CONNECTION_ABORTED: Final = 1236
|
||||
CONNECT_PIPE_INIT_DELAY: float
|
||||
CONNECT_PIPE_MAX_DELAY: float
|
||||
|
||||
class PipeServer:
|
||||
def __init__(self, address: str) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
def closed(self) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
class _WindowsSelectorEventLoop(selector_events.BaseSelectorEventLoop): ...
|
||||
|
||||
class ProactorEventLoop(proactor_events.BaseProactorEventLoop):
|
||||
def __init__(self, proactor: IocpProactor | None = None) -> None: ...
|
||||
async def create_pipe_connection(
|
||||
self, protocol_factory: Callable[[], streams.StreamReaderProtocol], address: str
|
||||
) -> tuple[proactor_events._ProactorDuplexPipeTransport, streams.StreamReaderProtocol]: ...
|
||||
async def start_serving_pipe(
|
||||
self, protocol_factory: Callable[[], streams.StreamReaderProtocol], address: str
|
||||
) -> list[PipeServer]: ...
|
||||
|
||||
class IocpProactor:
|
||||
def __init__(self, concurrency: int = 0xFFFFFFFF) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
def set_loop(self, loop: events.AbstractEventLoop) -> None: ...
|
||||
def select(self, timeout: int | None = None) -> list[futures.Future[Any]]: ...
|
||||
def recv(self, conn: socket.socket, nbytes: int, flags: int = 0) -> futures.Future[bytes]: ...
|
||||
def recv_into(self, conn: socket.socket, buf: WriteableBuffer, flags: int = 0) -> futures.Future[Any]: ...
|
||||
def recvfrom(
|
||||
self, conn: socket.socket, nbytes: int, flags: int = 0
|
||||
) -> futures.Future[tuple[bytes, socket._RetAddress]]: ...
|
||||
def sendto(
|
||||
self, conn: socket.socket, buf: ReadableBuffer, flags: int = 0, addr: socket._Address | None = None
|
||||
) -> futures.Future[int]: ...
|
||||
def send(self, conn: socket.socket, buf: WriteableBuffer, flags: int = 0) -> futures.Future[Any]: ...
|
||||
def accept(self, listener: socket.socket) -> futures.Future[Any]: ...
|
||||
def connect(
|
||||
self,
|
||||
conn: socket.socket,
|
||||
address: tuple[Incomplete, Incomplete] | tuple[Incomplete, Incomplete, Incomplete, Incomplete],
|
||||
) -> futures.Future[Any]: ...
|
||||
def sendfile(self, sock: socket.socket, file: IO[bytes], offset: int, count: int) -> futures.Future[Any]: ...
|
||||
def accept_pipe(self, pipe: socket.socket) -> futures.Future[Any]: ...
|
||||
async def connect_pipe(self, address: str) -> windows_utils.PipeHandle: ...
|
||||
def wait_for_handle(self, handle: windows_utils.PipeHandle, timeout: int | None = None) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
def recvfrom_into(
|
||||
self, conn: socket.socket, buf: WriteableBuffer, flags: int = 0
|
||||
) -> futures.Future[tuple[int, socket._RetAddress]]: ...
|
||||
|
||||
SelectorEventLoop = _WindowsSelectorEventLoop
|
||||
|
||||
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
|
||||
_loop_factory: ClassVar[type[SelectorEventLoop]]
|
||||
if sys.version_info < (3, 14):
|
||||
def get_child_watcher(self) -> NoReturn: ...
|
||||
def set_child_watcher(self, watcher: Any) -> NoReturn: ...
|
||||
|
||||
class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
|
||||
_loop_factory: ClassVar[type[ProactorEventLoop]]
|
||||
def get_child_watcher(self) -> NoReturn: ...
|
||||
def set_child_watcher(self, watcher: Any) -> NoReturn: ...
|
||||
|
||||
DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy
|
||||
if sys.version_info >= (3, 13):
|
||||
EventLoop = ProactorEventLoop
|
||||
@@ -1,49 +0,0 @@
|
||||
import subprocess
|
||||
import sys
|
||||
from collections.abc import Callable
|
||||
from types import TracebackType
|
||||
from typing import Any, AnyStr, Final
|
||||
from typing_extensions import Self
|
||||
|
||||
if sys.platform == "win32":
|
||||
__all__ = ("pipe", "Popen", "PIPE", "PipeHandle")
|
||||
|
||||
BUFSIZE: Final = 8192
|
||||
PIPE = subprocess.PIPE
|
||||
STDOUT = subprocess.STDOUT
|
||||
def pipe(*, duplex: bool = False, overlapped: tuple[bool, bool] = (True, True), bufsize: int = 8192) -> tuple[int, int]: ...
|
||||
|
||||
class PipeHandle:
|
||||
def __init__(self, handle: int) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
|
||||
@property
|
||||
def handle(self) -> int: ...
|
||||
def fileno(self) -> int: ...
|
||||
def close(self, *, CloseHandle: Callable[[int], object] = ...) -> None: ...
|
||||
|
||||
class Popen(subprocess.Popen[AnyStr]):
|
||||
stdin: PipeHandle | None # type: ignore[assignment]
|
||||
stdout: PipeHandle | None # type: ignore[assignment]
|
||||
stderr: PipeHandle | None # type: ignore[assignment]
|
||||
# For simplicity we omit the full overloaded __new__ signature of
|
||||
# subprocess.Popen. The arguments are mostly the same, but
|
||||
# subprocess.Popen takes other positional-or-keyword arguments before
|
||||
# stdin.
|
||||
def __new__(
|
||||
cls,
|
||||
args: subprocess._CMD,
|
||||
stdin: subprocess._FILE | None = ...,
|
||||
stdout: subprocess._FILE | None = ...,
|
||||
stderr: subprocess._FILE | None = ...,
|
||||
**kwds: Any,
|
||||
) -> Self: ...
|
||||
def __init__(
|
||||
self,
|
||||
args: subprocess._CMD,
|
||||
stdin: subprocess._FILE | None = None,
|
||||
stdout: subprocess._FILE | None = None,
|
||||
stderr: subprocess._FILE | None = None,
|
||||
**kwds: Any,
|
||||
) -> None: ...
|
||||
@@ -1,51 +0,0 @@
|
||||
import sys
|
||||
|
||||
from ._base import (
|
||||
ALL_COMPLETED as ALL_COMPLETED,
|
||||
FIRST_COMPLETED as FIRST_COMPLETED,
|
||||
FIRST_EXCEPTION as FIRST_EXCEPTION,
|
||||
BrokenExecutor as BrokenExecutor,
|
||||
CancelledError as CancelledError,
|
||||
Executor as Executor,
|
||||
Future as Future,
|
||||
InvalidStateError as InvalidStateError,
|
||||
TimeoutError as TimeoutError,
|
||||
as_completed as as_completed,
|
||||
wait as wait,
|
||||
)
|
||||
from .process import ProcessPoolExecutor as ProcessPoolExecutor
|
||||
from .thread import ThreadPoolExecutor as ThreadPoolExecutor
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
__all__ = (
|
||||
"FIRST_COMPLETED",
|
||||
"FIRST_EXCEPTION",
|
||||
"ALL_COMPLETED",
|
||||
"CancelledError",
|
||||
"TimeoutError",
|
||||
"InvalidStateError",
|
||||
"BrokenExecutor",
|
||||
"Future",
|
||||
"Executor",
|
||||
"wait",
|
||||
"as_completed",
|
||||
"ProcessPoolExecutor",
|
||||
"ThreadPoolExecutor",
|
||||
)
|
||||
else:
|
||||
__all__ = (
|
||||
"FIRST_COMPLETED",
|
||||
"FIRST_EXCEPTION",
|
||||
"ALL_COMPLETED",
|
||||
"CancelledError",
|
||||
"TimeoutError",
|
||||
"BrokenExecutor",
|
||||
"Future",
|
||||
"Executor",
|
||||
"wait",
|
||||
"as_completed",
|
||||
"ProcessPoolExecutor",
|
||||
"ThreadPoolExecutor",
|
||||
)
|
||||
|
||||
def __dir__() -> tuple[str, ...]: ...
|
||||
@@ -1,126 +0,0 @@
|
||||
import sys
|
||||
import threading
|
||||
from _typeshed import Unused
|
||||
from collections.abc import Callable, Collection, Iterable, Iterator
|
||||
from logging import Logger
|
||||
from types import TracebackType
|
||||
from typing import Any, Final, Generic, NamedTuple, Protocol, TypeVar
|
||||
from typing_extensions import ParamSpec, Self
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
FIRST_COMPLETED: Final = "FIRST_COMPLETED"
|
||||
FIRST_EXCEPTION: Final = "FIRST_EXCEPTION"
|
||||
ALL_COMPLETED: Final = "ALL_COMPLETED"
|
||||
PENDING: Final = "PENDING"
|
||||
RUNNING: Final = "RUNNING"
|
||||
CANCELLED: Final = "CANCELLED"
|
||||
CANCELLED_AND_NOTIFIED: Final = "CANCELLED_AND_NOTIFIED"
|
||||
FINISHED: Final = "FINISHED"
|
||||
_FUTURE_STATES: list[str]
|
||||
_STATE_TO_DESCRIPTION_MAP: dict[str, str]
|
||||
LOGGER: Logger
|
||||
|
||||
class Error(Exception): ...
|
||||
class CancelledError(Error): ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from builtins import TimeoutError as TimeoutError
|
||||
else:
|
||||
class TimeoutError(Error): ...
|
||||
|
||||
class InvalidStateError(Error): ...
|
||||
class BrokenExecutor(RuntimeError): ...
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_T_co = TypeVar("_T_co", covariant=True)
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
class Future(Generic[_T]):
|
||||
_condition: threading.Condition
|
||||
_state: str
|
||||
_result: _T | None
|
||||
_exception: BaseException | None
|
||||
_waiters: list[_Waiter]
|
||||
def cancel(self) -> bool: ...
|
||||
def cancelled(self) -> bool: ...
|
||||
def running(self) -> bool: ...
|
||||
def done(self) -> bool: ...
|
||||
def add_done_callback(self, fn: Callable[[Future[_T]], object]) -> None: ...
|
||||
def result(self, timeout: float | None = None) -> _T: ...
|
||||
def set_running_or_notify_cancel(self) -> bool: ...
|
||||
def set_result(self, result: _T) -> None: ...
|
||||
def exception(self, timeout: float | None = None) -> BaseException | None: ...
|
||||
def set_exception(self, exception: BaseException | None) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
class Executor:
|
||||
if sys.version_info >= (3, 9):
|
||||
def submit(self, fn: Callable[_P, _T], /, *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: ...
|
||||
else:
|
||||
def submit(self, fn: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: ...
|
||||
|
||||
def map(
|
||||
self, fn: Callable[..., _T], *iterables: Iterable[Any], timeout: float | None = None, chunksize: int = 1
|
||||
) -> Iterator[_T]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def shutdown(self, wait: bool = True, *, cancel_futures: bool = False) -> None: ...
|
||||
else:
|
||||
def shutdown(self, wait: bool = True) -> None: ...
|
||||
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> bool | None: ...
|
||||
|
||||
class _AsCompletedFuture(Protocol[_T_co]):
|
||||
# as_completed only mutates non-generic aspects of passed Futures and does not do any nominal
|
||||
# checks. Therefore, we can use a Protocol here to allow as_completed to act covariantly.
|
||||
# See the tests for concurrent.futures
|
||||
_condition: threading.Condition
|
||||
_state: str
|
||||
_waiters: list[_Waiter]
|
||||
# Not used by as_completed, but needed to propagate the generic type
|
||||
def result(self, timeout: float | None = None) -> _T_co: ...
|
||||
|
||||
def as_completed(fs: Iterable[_AsCompletedFuture[_T]], timeout: float | None = None) -> Iterator[Future[_T]]: ...
|
||||
|
||||
class DoneAndNotDoneFutures(NamedTuple, Generic[_T]):
|
||||
done: set[Future[_T]]
|
||||
not_done: set[Future[_T]]
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
def wait(
|
||||
fs: Iterable[Future[_T]], timeout: float | None = None, return_when: str = "ALL_COMPLETED"
|
||||
) -> DoneAndNotDoneFutures[_T]: ...
|
||||
|
||||
else:
|
||||
def wait(
|
||||
fs: Collection[Future[_T]], timeout: float | None = None, return_when: str = "ALL_COMPLETED"
|
||||
) -> DoneAndNotDoneFutures[_T]: ...
|
||||
|
||||
class _Waiter:
|
||||
event: threading.Event
|
||||
finished_futures: list[Future[Any]]
|
||||
def add_result(self, future: Future[Any]) -> None: ...
|
||||
def add_exception(self, future: Future[Any]) -> None: ...
|
||||
def add_cancelled(self, future: Future[Any]) -> None: ...
|
||||
|
||||
class _AsCompletedWaiter(_Waiter):
|
||||
lock: threading.Lock
|
||||
|
||||
class _FirstCompletedWaiter(_Waiter): ...
|
||||
|
||||
class _AllCompletedWaiter(_Waiter):
|
||||
num_pending_calls: int
|
||||
stop_on_exception: bool
|
||||
lock: threading.Lock
|
||||
def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ...
|
||||
|
||||
class _AcquireFutures:
|
||||
futures: Iterable[Future[Any]]
|
||||
def __init__(self, futures: Iterable[Future[Any]]) -> None: ...
|
||||
def __enter__(self) -> None: ...
|
||||
def __exit__(self, *args: Unused) -> None: ...
|
||||
@@ -1,244 +0,0 @@
|
||||
import sys
|
||||
from collections.abc import Callable, Generator, Iterable, Mapping, MutableMapping, MutableSequence
|
||||
from multiprocessing.connection import Connection
|
||||
from multiprocessing.context import BaseContext, Process
|
||||
from multiprocessing.queues import Queue, SimpleQueue
|
||||
from threading import Lock, Semaphore, Thread
|
||||
from types import TracebackType
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
from typing_extensions import TypeVarTuple, Unpack
|
||||
from weakref import ref
|
||||
|
||||
from ._base import BrokenExecutor, Executor, Future
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_Ts = TypeVarTuple("_Ts")
|
||||
|
||||
_threads_wakeups: MutableMapping[Any, Any]
|
||||
_global_shutdown: bool
|
||||
|
||||
class _ThreadWakeup:
|
||||
_closed: bool
|
||||
# Any: Unused send and recv methods
|
||||
_reader: Connection[Any, Any]
|
||||
_writer: Connection[Any, Any]
|
||||
def close(self) -> None: ...
|
||||
def wakeup(self) -> None: ...
|
||||
def clear(self) -> None: ...
|
||||
|
||||
def _python_exit() -> None: ...
|
||||
|
||||
EXTRA_QUEUED_CALLS: int
|
||||
|
||||
_MAX_WINDOWS_WORKERS: int
|
||||
|
||||
class _RemoteTraceback(Exception):
|
||||
tb: str
|
||||
def __init__(self, tb: TracebackType) -> None: ...
|
||||
|
||||
class _ExceptionWithTraceback:
|
||||
exc: BaseException
|
||||
tb: TracebackType
|
||||
def __init__(self, exc: BaseException, tb: TracebackType) -> None: ...
|
||||
def __reduce__(self) -> str | tuple[Any, ...]: ...
|
||||
|
||||
def _rebuild_exc(exc: Exception, tb: str) -> Exception: ...
|
||||
|
||||
class _WorkItem(Generic[_T]):
|
||||
future: Future[_T]
|
||||
fn: Callable[..., _T]
|
||||
args: Iterable[Any]
|
||||
kwargs: Mapping[str, Any]
|
||||
def __init__(self, future: Future[_T], fn: Callable[..., _T], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
|
||||
|
||||
class _ResultItem:
|
||||
work_id: int
|
||||
exception: Exception
|
||||
result: Any
|
||||
if sys.version_info >= (3, 11):
|
||||
exit_pid: int | None
|
||||
def __init__(
|
||||
self, work_id: int, exception: Exception | None = None, result: Any | None = None, exit_pid: int | None = None
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(self, work_id: int, exception: Exception | None = None, result: Any | None = None) -> None: ...
|
||||
|
||||
class _CallItem:
|
||||
work_id: int
|
||||
fn: Callable[..., Any]
|
||||
args: Iterable[Any]
|
||||
kwargs: Mapping[str, Any]
|
||||
def __init__(self, work_id: int, fn: Callable[..., Any], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
|
||||
|
||||
class _SafeQueue(Queue[Future[Any]]):
|
||||
pending_work_items: dict[int, _WorkItem[Any]]
|
||||
if sys.version_info < (3, 12):
|
||||
shutdown_lock: Lock
|
||||
thread_wakeup: _ThreadWakeup
|
||||
if sys.version_info >= (3, 12):
|
||||
def __init__(
|
||||
self,
|
||||
max_size: int | None = 0,
|
||||
*,
|
||||
ctx: BaseContext,
|
||||
pending_work_items: dict[int, _WorkItem[Any]],
|
||||
thread_wakeup: _ThreadWakeup,
|
||||
) -> None: ...
|
||||
elif sys.version_info >= (3, 9):
|
||||
def __init__(
|
||||
self,
|
||||
max_size: int | None = 0,
|
||||
*,
|
||||
ctx: BaseContext,
|
||||
pending_work_items: dict[int, _WorkItem[Any]],
|
||||
shutdown_lock: Lock,
|
||||
thread_wakeup: _ThreadWakeup,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self, max_size: int | None = 0, *, ctx: BaseContext, pending_work_items: dict[int, _WorkItem[Any]]
|
||||
) -> None: ...
|
||||
|
||||
def _on_queue_feeder_error(self, e: Exception, obj: _CallItem) -> None: ...
|
||||
|
||||
def _get_chunks(*iterables: Any, chunksize: int) -> Generator[tuple[Any, ...], None, None]: ...
|
||||
def _process_chunk(fn: Callable[..., _T], chunk: Iterable[tuple[Any, ...]]) -> list[_T]: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def _sendback_result(
|
||||
result_queue: SimpleQueue[_WorkItem[Any]],
|
||||
work_id: int,
|
||||
result: Any | None = None,
|
||||
exception: Exception | None = None,
|
||||
exit_pid: int | None = None,
|
||||
) -> None: ...
|
||||
|
||||
else:
|
||||
def _sendback_result(
|
||||
result_queue: SimpleQueue[_WorkItem[Any]], work_id: int, result: Any | None = None, exception: Exception | None = None
|
||||
) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
def _process_worker(
|
||||
call_queue: Queue[_CallItem],
|
||||
result_queue: SimpleQueue[_ResultItem],
|
||||
initializer: Callable[[Unpack[_Ts]], object] | None,
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
max_tasks: int | None = None,
|
||||
) -> None: ...
|
||||
|
||||
else:
|
||||
def _process_worker(
|
||||
call_queue: Queue[_CallItem],
|
||||
result_queue: SimpleQueue[_ResultItem],
|
||||
initializer: Callable[[Unpack[_Ts]], object] | None,
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
class _ExecutorManagerThread(Thread):
|
||||
thread_wakeup: _ThreadWakeup
|
||||
shutdown_lock: Lock
|
||||
executor_reference: ref[Any]
|
||||
processes: MutableMapping[int, Process]
|
||||
call_queue: Queue[_CallItem]
|
||||
result_queue: SimpleQueue[_ResultItem]
|
||||
work_ids_queue: Queue[int]
|
||||
pending_work_items: dict[int, _WorkItem[Any]]
|
||||
def __init__(self, executor: ProcessPoolExecutor) -> None: ...
|
||||
def run(self) -> None: ...
|
||||
def add_call_item_to_queue(self) -> None: ...
|
||||
def wait_result_broken_or_wakeup(self) -> tuple[Any, bool, str]: ...
|
||||
def process_result_item(self, result_item: int | _ResultItem) -> None: ...
|
||||
def is_shutting_down(self) -> bool: ...
|
||||
def terminate_broken(self, cause: str) -> None: ...
|
||||
def flag_executor_shutting_down(self) -> None: ...
|
||||
def shutdown_workers(self) -> None: ...
|
||||
def join_executor_internals(self) -> None: ...
|
||||
def get_n_children_alive(self) -> int: ...
|
||||
|
||||
_system_limits_checked: bool
|
||||
_system_limited: bool | None
|
||||
|
||||
def _check_system_limits() -> None: ...
|
||||
def _chain_from_iterable_of_lists(iterable: Iterable[MutableSequence[Any]]) -> Any: ...
|
||||
|
||||
class BrokenProcessPool(BrokenExecutor): ...
|
||||
|
||||
class ProcessPoolExecutor(Executor):
|
||||
_mp_context: BaseContext | None
|
||||
_initializer: Callable[..., None] | None
|
||||
_initargs: tuple[Any, ...]
|
||||
_executor_manager_thread: _ThreadWakeup
|
||||
_processes: MutableMapping[int, Process]
|
||||
_shutdown_thread: bool
|
||||
_shutdown_lock: Lock
|
||||
_idle_worker_semaphore: Semaphore
|
||||
_broken: bool
|
||||
_queue_count: int
|
||||
_pending_work_items: dict[int, _WorkItem[Any]]
|
||||
_cancel_pending_futures: bool
|
||||
_executor_manager_thread_wakeup: _ThreadWakeup
|
||||
_result_queue: SimpleQueue[Any]
|
||||
_work_ids: Queue[Any]
|
||||
if sys.version_info >= (3, 11):
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None = None,
|
||||
mp_context: BaseContext | None = None,
|
||||
initializer: Callable[[], object] | None = None,
|
||||
initargs: tuple[()] = (),
|
||||
*,
|
||||
max_tasks_per_child: int | None = None,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None = None,
|
||||
mp_context: BaseContext | None = None,
|
||||
*,
|
||||
initializer: Callable[[Unpack[_Ts]], object],
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
max_tasks_per_child: int | None = None,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None,
|
||||
mp_context: BaseContext | None,
|
||||
initializer: Callable[[Unpack[_Ts]], object],
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
*,
|
||||
max_tasks_per_child: int | None = None,
|
||||
) -> None: ...
|
||||
else:
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None = None,
|
||||
mp_context: BaseContext | None = None,
|
||||
initializer: Callable[[], object] | None = None,
|
||||
initargs: tuple[()] = (),
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None = None,
|
||||
mp_context: BaseContext | None = None,
|
||||
*,
|
||||
initializer: Callable[[Unpack[_Ts]], object],
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None,
|
||||
mp_context: BaseContext | None,
|
||||
initializer: Callable[[Unpack[_Ts]], object],
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def _start_executor_manager_thread(self) -> None: ...
|
||||
|
||||
def _adjust_process_count(self) -> None: ...
|
||||
@@ -1,80 +0,0 @@
|
||||
import queue
|
||||
import sys
|
||||
from collections.abc import Callable, Iterable, Mapping, Set as AbstractSet
|
||||
from threading import Lock, Semaphore, Thread
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
from typing_extensions import TypeVarTuple, Unpack
|
||||
from weakref import ref
|
||||
|
||||
from ._base import BrokenExecutor, Executor, Future
|
||||
|
||||
_Ts = TypeVarTuple("_Ts")
|
||||
|
||||
_threads_queues: Mapping[Any, Any]
|
||||
_shutdown: bool
|
||||
_global_shutdown_lock: Lock
|
||||
|
||||
def _python_exit() -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
_S = TypeVar("_S")
|
||||
|
||||
class _WorkItem(Generic[_S]):
|
||||
future: Future[_S]
|
||||
fn: Callable[..., _S]
|
||||
args: Iterable[Any]
|
||||
kwargs: Mapping[str, Any]
|
||||
def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
|
||||
def run(self) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
def _worker(
|
||||
executor_reference: ref[Any],
|
||||
work_queue: queue.SimpleQueue[Any],
|
||||
initializer: Callable[[Unpack[_Ts]], object],
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
) -> None: ...
|
||||
|
||||
class BrokenThreadPool(BrokenExecutor): ...
|
||||
|
||||
class ThreadPoolExecutor(Executor):
|
||||
_max_workers: int
|
||||
_idle_semaphore: Semaphore
|
||||
_threads: AbstractSet[Thread]
|
||||
_broken: bool
|
||||
_shutdown: bool
|
||||
_shutdown_lock: Lock
|
||||
_thread_name_prefix: str | None
|
||||
_initializer: Callable[..., None] | None
|
||||
_initargs: tuple[Any, ...]
|
||||
_work_queue: queue.SimpleQueue[_WorkItem[Any]]
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None = None,
|
||||
thread_name_prefix: str = "",
|
||||
initializer: Callable[[], object] | None = None,
|
||||
initargs: tuple[()] = (),
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None = None,
|
||||
thread_name_prefix: str = "",
|
||||
*,
|
||||
initializer: Callable[[Unpack[_Ts]], object],
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
max_workers: int | None,
|
||||
thread_name_prefix: str,
|
||||
initializer: Callable[[Unpack[_Ts]], object],
|
||||
initargs: tuple[Unpack[_Ts]],
|
||||
) -> None: ...
|
||||
def _adjust_thread_count(self) -> None: ...
|
||||
def _initializer_failed(self) -> None: ...
|
||||
@@ -1,263 +0,0 @@
|
||||
import sys
|
||||
from _ctypes import (
|
||||
POINTER as POINTER,
|
||||
RTLD_GLOBAL as RTLD_GLOBAL,
|
||||
RTLD_LOCAL as RTLD_LOCAL,
|
||||
Array as Array,
|
||||
CFuncPtr as _CFuncPtr,
|
||||
Structure as Structure,
|
||||
Union as Union,
|
||||
_CanCastTo as _CanCastTo,
|
||||
_CArgObject as _CArgObject,
|
||||
_CData as _CData,
|
||||
_CDataType as _CDataType,
|
||||
_CField as _CField,
|
||||
_Pointer as _Pointer,
|
||||
_PointerLike as _PointerLike,
|
||||
_SimpleCData as _SimpleCData,
|
||||
addressof as addressof,
|
||||
alignment as alignment,
|
||||
byref as byref,
|
||||
get_errno as get_errno,
|
||||
pointer as pointer,
|
||||
resize as resize,
|
||||
set_errno as set_errno,
|
||||
sizeof as sizeof,
|
||||
)
|
||||
from _typeshed import StrPath
|
||||
from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure
|
||||
from typing import Any, ClassVar, Generic, TypeVar, type_check_only
|
||||
from typing_extensions import Self, TypeAlias, deprecated
|
||||
|
||||
if sys.platform == "win32":
|
||||
from _ctypes import FormatError as FormatError, get_last_error as get_last_error, set_last_error as set_last_error
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from ctypes._endian import BigEndianUnion as BigEndianUnion, LittleEndianUnion as LittleEndianUnion
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_DLLT = TypeVar("_DLLT", bound=CDLL)
|
||||
_CT = TypeVar("_CT", bound=_CData)
|
||||
|
||||
DEFAULT_MODE: int
|
||||
|
||||
class ArgumentError(Exception): ...
|
||||
|
||||
# defined within CDLL.__init__
|
||||
# Runtime name is ctypes.CDLL.__init__.<locals>._FuncPtr
|
||||
@type_check_only
|
||||
class _CDLLFuncPointer(_CFuncPtr):
|
||||
_flags_: ClassVar[int]
|
||||
_restype_: ClassVar[type[_CDataType]]
|
||||
|
||||
# Not a real class; _CDLLFuncPointer with a __name__ set on it.
|
||||
@type_check_only
|
||||
class _NamedFuncPointer(_CDLLFuncPointer):
|
||||
__name__: str
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
_NameTypes: TypeAlias = StrPath | None
|
||||
else:
|
||||
_NameTypes: TypeAlias = str | None
|
||||
|
||||
class CDLL:
|
||||
_func_flags_: ClassVar[int]
|
||||
_func_restype_: ClassVar[type[_CDataType]]
|
||||
_name: str
|
||||
_handle: int
|
||||
_FuncPtr: type[_CDLLFuncPointer]
|
||||
def __init__(
|
||||
self,
|
||||
name: _NameTypes,
|
||||
mode: int = ...,
|
||||
handle: int | None = None,
|
||||
use_errno: bool = False,
|
||||
use_last_error: bool = False,
|
||||
winmode: int | None = None,
|
||||
) -> None: ...
|
||||
def __getattr__(self, name: str) -> _NamedFuncPointer: ...
|
||||
def __getitem__(self, name_or_ordinal: str) -> _NamedFuncPointer: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
class OleDLL(CDLL): ...
|
||||
class WinDLL(CDLL): ...
|
||||
|
||||
class PyDLL(CDLL): ...
|
||||
|
||||
class LibraryLoader(Generic[_DLLT]):
|
||||
def __init__(self, dlltype: type[_DLLT]) -> None: ...
|
||||
def __getattr__(self, name: str) -> _DLLT: ...
|
||||
def __getitem__(self, name: str) -> _DLLT: ...
|
||||
def LoadLibrary(self, name: str) -> _DLLT: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
||||
|
||||
cdll: LibraryLoader[CDLL]
|
||||
if sys.platform == "win32":
|
||||
windll: LibraryLoader[WinDLL]
|
||||
oledll: LibraryLoader[OleDLL]
|
||||
pydll: LibraryLoader[PyDLL]
|
||||
pythonapi: PyDLL
|
||||
|
||||
# Class definition within CFUNCTYPE / WINFUNCTYPE / PYFUNCTYPE
|
||||
# Names at runtime are
|
||||
# ctypes.CFUNCTYPE.<locals>.CFunctionType
|
||||
# ctypes.WINFUNCTYPE.<locals>.WinFunctionType
|
||||
# ctypes.PYFUNCTYPE.<locals>.CFunctionType
|
||||
@type_check_only
|
||||
class _CFunctionType(_CFuncPtr):
|
||||
_argtypes_: ClassVar[list[type[_CData | _CDataType]]]
|
||||
_restype_: ClassVar[type[_CData | _CDataType] | None]
|
||||
_flags_: ClassVar[int]
|
||||
|
||||
# Alias for either function pointer type
|
||||
_FuncPointer: TypeAlias = _CDLLFuncPointer | _CFunctionType # noqa: Y047 # not used here
|
||||
|
||||
def CFUNCTYPE(
|
||||
restype: type[_CData | _CDataType] | None,
|
||||
*argtypes: type[_CData | _CDataType],
|
||||
use_errno: bool = False,
|
||||
use_last_error: bool = False,
|
||||
) -> type[_CFunctionType]: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
def WINFUNCTYPE(
|
||||
restype: type[_CData | _CDataType] | None,
|
||||
*argtypes: type[_CData | _CDataType],
|
||||
use_errno: bool = False,
|
||||
use_last_error: bool = False,
|
||||
) -> type[_CFunctionType]: ...
|
||||
|
||||
def PYFUNCTYPE(restype: type[_CData | _CDataType] | None, *argtypes: type[_CData | _CDataType]) -> type[_CFunctionType]: ...
|
||||
|
||||
# Any type that can be implicitly converted to c_void_p when passed as a C function argument.
|
||||
# (bytes is not included here, see below.)
|
||||
_CVoidPLike: TypeAlias = _PointerLike | Array[Any] | _CArgObject | int
|
||||
# Same as above, but including types known to be read-only (i. e. bytes).
|
||||
# This distinction is not strictly necessary (ctypes doesn't differentiate between const
|
||||
# and non-const pointers), but it catches errors like memmove(b'foo', buf, 4)
|
||||
# when memmove(buf, b'foo', 4) was intended.
|
||||
_CVoidConstPLike: TypeAlias = _CVoidPLike | bytes
|
||||
|
||||
_CastT = TypeVar("_CastT", bound=_CanCastTo)
|
||||
|
||||
def cast(obj: _CData | _CDataType | _CArgObject | int, typ: type[_CastT]) -> _CastT: ...
|
||||
def create_string_buffer(init: int | bytes, size: int | None = None) -> Array[c_char]: ...
|
||||
|
||||
c_buffer = create_string_buffer
|
||||
|
||||
def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_wchar]: ...
|
||||
@deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15")
|
||||
def SetPointerType(
|
||||
pointer: type[_Pointer[Any]], cls: Any # noqa: F811 # Redefinition of unused `pointer` from line 22
|
||||
) -> None: ...
|
||||
def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... # Soft Deprecated, no plans to remove
|
||||
|
||||
if sys.platform == "win32":
|
||||
def DllCanUnloadNow() -> int: ...
|
||||
def DllGetClassObject(rclsid: Any, riid: Any, ppv: Any) -> int: ... # TODO not documented
|
||||
|
||||
# Actually just an instance of _NamedFuncPointer (aka _CDLLFuncPointer),
|
||||
# but we want to set a more specific __call__
|
||||
@type_check_only
|
||||
class _GetLastErrorFunctionType(_NamedFuncPointer):
|
||||
def __call__(self) -> int: ...
|
||||
|
||||
GetLastError: _GetLastErrorFunctionType
|
||||
|
||||
# Actually just an instance of _CFunctionType, but we want to set a more
|
||||
# specific __call__.
|
||||
@type_check_only
|
||||
class _MemmoveFunctionType(_CFunctionType):
|
||||
def __call__(self, dst: _CVoidPLike, src: _CVoidConstPLike, count: int) -> int: ...
|
||||
|
||||
memmove: _MemmoveFunctionType
|
||||
|
||||
# Actually just an instance of _CFunctionType, but we want to set a more
|
||||
# specific __call__.
|
||||
@type_check_only
|
||||
class _MemsetFunctionType(_CFunctionType):
|
||||
def __call__(self, dst: _CVoidPLike, c: int, count: int) -> int: ...
|
||||
|
||||
memset: _MemsetFunctionType
|
||||
|
||||
def string_at(ptr: _CVoidConstPLike, size: int = -1) -> bytes: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
def WinError(code: int | None = None, descr: str | None = None) -> OSError: ...
|
||||
|
||||
def wstring_at(ptr: _CVoidConstPLike, size: int = -1) -> str: ...
|
||||
|
||||
class c_byte(_SimpleCData[int]): ...
|
||||
|
||||
class c_char(_SimpleCData[bytes]):
|
||||
def __init__(self, value: int | bytes | bytearray = ...) -> None: ...
|
||||
|
||||
class c_char_p(_PointerLike, _SimpleCData[bytes | None]):
|
||||
def __init__(self, value: int | bytes | None = ...) -> None: ...
|
||||
@classmethod
|
||||
def from_param(cls, value: Any, /) -> Self | _CArgObject: ...
|
||||
|
||||
class c_double(_SimpleCData[float]): ...
|
||||
class c_longdouble(_SimpleCData[float]): ... # can be an alias for c_double
|
||||
class c_float(_SimpleCData[float]): ...
|
||||
class c_int(_SimpleCData[int]): ... # can be an alias for c_long
|
||||
class c_long(_SimpleCData[int]): ...
|
||||
class c_longlong(_SimpleCData[int]): ... # can be an alias for c_long
|
||||
class c_short(_SimpleCData[int]): ...
|
||||
class c_size_t(_SimpleCData[int]): ... # alias for c_uint, c_ulong, or c_ulonglong
|
||||
class c_ssize_t(_SimpleCData[int]): ... # alias for c_int, c_long, or c_longlong
|
||||
class c_ubyte(_SimpleCData[int]): ...
|
||||
class c_uint(_SimpleCData[int]): ... # can be an alias for c_ulong
|
||||
class c_ulong(_SimpleCData[int]): ...
|
||||
class c_ulonglong(_SimpleCData[int]): ... # can be an alias for c_ulong
|
||||
class c_ushort(_SimpleCData[int]): ...
|
||||
|
||||
class c_void_p(_PointerLike, _SimpleCData[int | None]):
|
||||
@classmethod
|
||||
def from_param(cls, value: Any, /) -> Self | _CArgObject: ...
|
||||
|
||||
c_voidp = c_void_p # backwards compatibility (to a bug)
|
||||
|
||||
class c_wchar(_SimpleCData[str]): ...
|
||||
|
||||
c_int8 = c_byte
|
||||
|
||||
# these are actually dynamic aliases for c_short, c_int, c_long, or c_longlong
|
||||
class c_int16(_SimpleCData[int]): ...
|
||||
class c_int32(_SimpleCData[int]): ...
|
||||
class c_int64(_SimpleCData[int]): ...
|
||||
|
||||
c_uint8 = c_ubyte
|
||||
|
||||
# these are actually dynamic aliases for c_ushort, c_uint, c_ulong, or c_ulonglong
|
||||
class c_uint16(_SimpleCData[int]): ...
|
||||
class c_uint32(_SimpleCData[int]): ...
|
||||
class c_uint64(_SimpleCData[int]): ...
|
||||
|
||||
class c_wchar_p(_PointerLike, _SimpleCData[str | None]):
|
||||
def __init__(self, value: int | str | None = ...) -> None: ...
|
||||
@classmethod
|
||||
def from_param(cls, value: Any, /) -> Self | _CArgObject: ...
|
||||
|
||||
class c_bool(_SimpleCData[bool]):
|
||||
def __init__(self, value: bool = ...) -> None: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
class HRESULT(_SimpleCData[int]): ... # TODO undocumented
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
# At runtime, this is an alias for either c_int32 or c_int64,
|
||||
# which are themselves an alias for one of c_short, c_int, c_long, or c_longlong
|
||||
# This covers all our bases.
|
||||
c_time_t: type[c_int32 | c_int64 | c_short | c_int | c_long | c_longlong]
|
||||
|
||||
class py_object(_CanCastTo, _SimpleCData[_T]): ...
|
||||
|
||||
if sys.version_info >= (3, 14):
|
||||
class c_float_complex(_SimpleCData[complex]): ...
|
||||
class c_double_complex(_SimpleCData[complex]): ...
|
||||
class c_longdouble_complex(_SimpleCData[complex]): ...
|
||||
@@ -1,12 +0,0 @@
|
||||
import sys
|
||||
from ctypes import Structure, Union
|
||||
|
||||
# At runtime, the native endianness is an alias for Structure,
|
||||
# while the other is a subclass with a metaclass added in.
|
||||
class BigEndianStructure(Structure): ...
|
||||
class LittleEndianStructure(Structure): ...
|
||||
|
||||
# Same thing for these: one is an alias of Union at runtime
|
||||
if sys.version_info >= (3, 11):
|
||||
class BigEndianUnion(Union): ...
|
||||
class LittleEndianUnion(Union): ...
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user