Skip to content

Commit 4e82ce9

Browse files
author
hauntsaninja
committed
Merge remote-tracking branch 'upstream/master' into typevar2
2 parents fe6865b + 2c90912 commit 4e82ce9

File tree

885 files changed

+39590
-12979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

885 files changed

+39590
-12979
lines changed

.github/workflows/mypy_primer.yml

+15-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
mypy_primer:
1414
name: Run
1515
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
1618
strategy:
1719
matrix:
1820
shard-index: [0, 1, 2]
@@ -48,10 +50,20 @@ jobs:
4850
--num-shards 3 --shard-index ${{ matrix.shard-index }} \
4951
--debug \
5052
--output concise \
51-
| tee diff.txt
53+
| tee diff_${{ matrix.shard-index }}.txt
5254
) || [ $? -eq 1 ]
5355
- name: Upload mypy_primer diff
5456
uses: actions/upload-artifact@v2
5557
with:
56-
name: mypy_primer_diff_${{ matrix.shard-index }}
57-
path: diff.txt
58+
name: mypy_primer_diffs
59+
path: diff_${{ matrix.shard-index }}.txt
60+
- if: ${{ matrix.shard-index }} == 0
61+
name: Save PR number
62+
run: |
63+
echo ${{ github.event.pull_request.number }} | tee pr_number.txt
64+
- if: ${{ matrix.shard-index }} == 0
65+
name: Upload PR number
66+
uses: actions/upload-artifact@v2
67+
with:
68+
name: mypy_primer_diffs
69+
path: pr_number.txt
+72-77
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,99 @@
11
name: Comment with mypy_primer diff
22

33
on:
4-
# pull_request_target gives us access to a write token which we need to post a comment
5-
# The presence of a write token means that we can't run any untrusted code (i.e. malicious PRs),
6-
# which is why this its own workflow. Github Actions doesn't make it easy for workflows to talk to
7-
# each other, so the approach here is to poll for workflow runs, find the mypy_primer run for our
8-
# commit, wait till it's completed, and download and post the diff.
9-
pull_request_target:
10-
paths-ignore:
11-
- 'docs/**'
12-
- '**/*.rst'
13-
- '**/*.md'
14-
- 'mypyc/**'
4+
workflow_run:
5+
workflows:
6+
- Run mypy_primer
7+
types:
8+
- completed
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
1513

1614
jobs:
17-
mypy_primer:
18-
name: Comment
15+
comment:
16+
name: Comment PR from mypy_primer
1917
runs-on: ubuntu-latest
2018
steps:
21-
- name: Install dependencies
22-
run: npm install adm-zip
23-
- name: Post comment
19+
- name: Download diffs
2420
uses: actions/github-script@v3
2521
with:
26-
github-token: ${{secrets.GITHUB_TOKEN}}
2722
script: |
28-
const AdmZip = require(`${process.env.GITHUB_WORKSPACE}/node_modules/adm-zip`)
23+
const fs = require('fs');
24+
const artifacts = await github.actions.listWorkflowRunArtifacts({
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
run_id: ${{ github.event.workflow_run.id }},
28+
});
29+
const [matchArtifact] = artifacts.data.artifacts.filter((artifact) =>
30+
artifact.name == "mypy_primer_diffs");
2931
30-
// Because of pull_request_target, context.sha is the PR base branch
31-
// So we need to ask Github for the SHA of the PR's head commit
32-
const pull_request = await github.pulls.get({
33-
owner: context.repo.owner,
34-
repo: context.repo.repo,
35-
pull_number: context.issue.number,
36-
})
37-
const pr_commit_sha = pull_request.data.head.sha
38-
console.log("Looking for mypy_primer run for commit:", pr_commit_sha)
32+
const download = await github.actions.downloadArtifact({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
artifact_id: matchArtifact.id,
36+
archive_format: "zip",
37+
});
38+
fs.writeFileSync("diff.zip", Buffer.from(download.data));
3939
40-
// Find the mypy_primer run for our commit and wait till it's completed
41-
// We wait up to an hour before timing out
42-
async function check_mypy_primer() {
43-
// We're only looking at the first page, so in theory if we open enough PRs around
44-
// the same time, this will fail to find the run.
45-
const response = await github.actions.listWorkflowRuns({
46-
owner: context.repo.owner,
47-
repo: context.repo.repo,
48-
workflow_id: "mypy_primer.yml",
49-
})
50-
if (response) {
51-
return response.data.workflow_runs.find(run => run.head_sha == pr_commit_sha)
52-
}
53-
return undefined
54-
}
40+
- run: unzip diff.zip
5541

56-
const end_time = Number(new Date()) + 60 * 60 * 1000
57-
let primer_run = await check_mypy_primer()
58-
while (!primer_run || primer_run.status != "completed") {
59-
if (Number(new Date()) > end_time) {
60-
throw Error("Timed out waiting for mypy_primer")
61-
}
62-
console.log("Waiting for mypy_primer to complete...")
63-
await new Promise(r => setTimeout(r, 10000))
64-
primer_run = await check_mypy_primer()
65-
}
66-
console.log("Found mypy_primer run!")
67-
console.log(primer_run)
42+
# Based on https://github.com/kanga333/comment-hider
43+
- name: Hide old comments
44+
uses: actions/github-script@v3
45+
with:
46+
github-token: ${{secrets.GITHUB_TOKEN}}
47+
script: |
48+
const fs = require('fs')
6849
69-
// Download artifact(s) from the run
70-
const artifacts = await github.actions.listWorkflowRunArtifacts({
71-
owner: context.repo.owner,
72-
repo: context.repo.repo,
73-
run_id: primer_run.id,
50+
const response = await github.issues.listComments({
51+
issue_number: fs.readFileSync("pr_number.txt", { encoding: "utf8" }),
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
7454
})
75-
const filtered_artifacts = artifacts.data.artifacts.filter(
76-
a => a.name.startsWith("mypy_primer_diff")
77-
)
78-
console.log("Artifacts from mypy_primer:")
79-
console.log(filtered_artifacts)
55+
const botCommentIds = response.data
56+
.filter(comment => comment.user.login === 'github-actions[bot]')
57+
.map(comment => comment.node_id)
8058
81-
async function get_artifact_data(artifact) {
82-
const zip = await github.actions.downloadArtifact({
83-
owner: context.repo.owner,
84-
repo: context.repo.repo,
85-
artifact_id: artifact.id,
86-
archive_format: "zip",
87-
})
88-
const adm = new AdmZip(Buffer.from(zip.data))
89-
return adm.readAsText(adm.getEntry("diff.txt"))
59+
for (const id of botCommentIds) {
60+
const resp = await github.graphql(`
61+
mutation {
62+
minimizeComment(input: {classifier: OUTDATED, subjectId: "${id}"}) {
63+
minimizedComment {
64+
isMinimized
65+
}
66+
}
67+
}
68+
`)
69+
if (resp.errors) {
70+
throw new Error(resp.errors)
71+
}
9072
}
9173
92-
const all_data = await Promise.all(filtered_artifacts.map(get_artifact_data))
93-
const data = all_data.join("\n")
74+
- name: Post comment
75+
uses: actions/github-script@v3
76+
with:
77+
github-token: ${{secrets.GITHUB_TOKEN}}
78+
script: |
79+
const fs = require('fs')
80+
// Keep in sync with shards produced by mypy_primer workflow
81+
const data = (
82+
['diff_0.txt', 'diff_1.txt', 'diff_2.txt']
83+
.map(fileName => fs.readFileSync(fileName, { encoding: 'utf8' }))
84+
.join('')
85+
.substr(0, 30000) // About 300 lines
86+
)
9487
9588
console.log("Diff from mypy_primer:")
9689
console.log(data)
90+
9791
if (data.trim()) {
92+
const body = 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'
9893
await github.issues.createComment({
99-
issue_number: context.issue.number,
94+
issue_number: fs.readFileSync("pr_number.txt", { encoding: "utf8" }),
10095
owner: context.repo.owner,
10196
repo: context.repo.repo,
102-
body: 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'
97+
body
10398
})
10499
}

.github/workflows/test.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ jobs:
3535

3636
steps:
3737
- uses: actions/checkout@v2
38-
with:
39-
submodules: true
4038
- uses: actions/setup-python@v2
4139
with:
4240
python-version: ${{ matrix.python }}
4341
architecture: ${{ matrix.arch }}
4442
- name: install tox
45-
run: pip install --upgrade 'setuptools!=50' 'virtualenv<20' tox==3.20.1
43+
run: pip install --upgrade 'setuptools!=50' 'virtualenv<16.7.11' tox==3.20.1
4644
- name: setup tox environment
4745
run: tox -e ${{ matrix.toxenv }} --notest
4846
- name: test

.github/workflows/test_stubgenc.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ jobs:
2020

2121
- uses: actions/checkout@v2
2222

23-
- name: initialize submodules
24-
run: git submodule update --init
25-
2623
- name: Setup 🐍 3.8
2724
uses: actions/setup-python@v2
2825
with:
2926
python-version: 3.8
3027

3128
- name: Test stubgenc
32-
run: misc/test-stubgenc.sh
29+
run: misc/test-stubgenc.sh

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mypyc/doc/_build
1010
*.iml
1111
/out/
1212
.venv*/
13+
venv/
1314
.mypy_cache/
1415
.incremental_checker_cache.json
1516
.cache
@@ -44,6 +45,8 @@ htmlcov
4445
bin/
4546
lib/
4647
include/
48+
.python-version
49+
pyvenv.cfg
4750

4851
.tox
4952
pip-wheel-metadata

.travis.yml

+8-12
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,22 @@ env:
2424
jobs:
2525
fast_finish: true
2626
include:
27-
# Specifically request 3.5.1 because we need to be compatible with that.
28-
- name: "run test suite with python 3.5.1 (compiled with mypyc)"
29-
python: 3.5.1
30-
dist: trusty
27+
- name: "run test suite with python 3.6 (compiled with mypyc)"
28+
python: 3.6 # 3.6.3 pip 9.0.1
3129
env:
3230
- TOXENV=py
3331
- EXTRA_ARGS="-n 2"
3432
- TEST_MYPYC=1
35-
- name: "run test suite with python 3.6"
36-
python: 3.6 # 3.6.3 pip 9.0.1
37-
- name: "run test suite with python 3.7 (compiled with mypyc)"
33+
- name: "run test suite with python 3.7"
3834
python: 3.7
35+
- name: "run test suite with python 3.8"
36+
python: 3.8
37+
- name: "run test suite with python 3.9 (compiled with mypyc)"
38+
python: 3.9
3939
env:
4040
- TOXENV=py
4141
- EXTRA_ARGS="-n 2"
4242
- TEST_MYPYC=1
43-
- name: "run test suite with python 3.8"
44-
python: 3.8
45-
- name: "run test suite with python 3.9"
46-
python: 3.9
4743
- name: "run test suite with python nightly"
4844
python: nightly
4945
- name: "run mypyc runtime tests with python 3.6 debug build"
@@ -89,7 +85,7 @@ jobs:
8985
install:
9086
# pip 21.0 no longer works on Python 3.5
9187
- pip install -U pip==20.3.4 setuptools
92-
- pip install -U 'virtualenv<20'
88+
- pip install -U 'virtualenv<16.7.11'
9389
- pip install -U tox==3.20.1
9490
- python2 -m pip install --user -U typing
9591
- tox --notest

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Mypy (and mypyc) are licensed under the terms of the MIT license, reproduced bel
44

55
The MIT License
66

7-
Copyright (c) 2015-2019 Jukka Lehtosalo and contributors
7+
Copyright (c) 2015-2021 Jukka Lehtosalo and contributors
88

99
Permission is hereby granted, free of charge, to any person obtaining a
1010
copy of this software and associated documentation files (the "Software"),

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# stubs
55
prune mypy/typeshed
6+
include mypy/typeshed/LICENSE
67
include mypy/typeshed/stdlib/VERSIONS
78
recursive-include mypy/typeshed *.pyi
89

build-requirements.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
-r mypy-requirements.txt
22
types-typed-ast>=1.4.0,<1.5.0
3-
types-toml>=0.0
4-
types-enum34>=0.0; python_version == '3.5'

docs/source/class_basics.rst

+1-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ initialized within the class. Mypy infers the types of attributes:
2121
2222
a = A(1)
2323
a.x = 2 # OK!
24-
a.y = 3 # Error: 'A' has no attribute 'y'
24+
a.y = 3 # Error: "A" has no attribute "y"
2525
2626
This is a bit like each class having an implicitly defined
2727
:py:data:`__slots__ <object.__slots__>` attribute. This is only enforced during type
@@ -127,12 +127,6 @@ particular attribute should not be set on instances:
127127
a.x = 1 # Error: Cannot assign to class variable "x" via instance
128128
print(a.x) # OK -- can be read through an instance
129129
130-
.. note::
131-
132-
If you need to support Python 3 versions 3.5.2 or earlier, you have
133-
to import ``ClassVar`` from ``typing_extensions`` instead (available on
134-
PyPI). If you use Python 2.7, you can import it from ``typing``.
135-
136130
It's not necessary to annotate all class variables using
137131
:py:data:`~typing.ClassVar`. An attribute without the :py:data:`~typing.ClassVar` annotation can
138132
still be used as a class variable. However, mypy won't prevent it from

0 commit comments

Comments
 (0)