Skip to content

Commit a040393

Browse files
authored
Merge branch 'master' into NarrowingTypeLen
2 parents e0a863c + 481db72 commit a040393

File tree

843 files changed

+36668
-12542
lines changed

Some content is hidden

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

843 files changed

+36668
-12542
lines changed

.github/workflows/mypy_primer.yml

Lines changed: 15 additions & 3 deletions
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
Lines changed: 72 additions & 77 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
python-version: ${{ matrix.python }}
4141
architecture: ${{ matrix.arch }}
4242
- name: install tox
43-
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
4444
- name: setup tox environment
4545
run: tox -e ${{ matrix.toxenv }} --notest
4646
- name: test

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
install:
8686
# pip 21.0 no longer works on Python 3.5
8787
- pip install -U pip==20.3.4 setuptools
88-
- pip install -U 'virtualenv<20'
88+
- pip install -U 'virtualenv<16.7.11'
8989
- pip install -U tox==3.20.1
9090
- python2 -m pip install --user -U typing
9191
- tox --notest

LICENSE

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

docs/source/command_line.rst

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,20 @@ for full details, see :ref:`running-mypy`.
5858
For instance, to avoid discovering any files named `setup.py` you could
5959
pass ``--exclude '/setup\.py$'``. Similarly, you can ignore discovering
6060
directories with a given name by e.g. ``--exclude /build/`` or
61-
those matching a subpath with ``--exclude /project/vendor/``.
61+
those matching a subpath with ``--exclude /project/vendor/``. To ignore
62+
multiple files / directories / paths, you can combine expressions with
63+
``|``, e.g ``--exclude '/setup\.py$|/build/'``.
6264

63-
Note that this flag only affects recursive discovery, that is, when mypy is
64-
discovering files within a directory tree or submodules of a package to
65-
check. If you pass a file or module explicitly it will still be checked. For
66-
instance, ``mypy --exclude '/setup.py$' but_still_check/setup.py``.
65+
Note that this flag only affects recursive directory tree discovery, that
66+
is, when mypy is discovering files within a directory tree or submodules of
67+
a package to check. If you pass a file or module explicitly it will still be
68+
checked. For instance, ``mypy --exclude '/setup.py$'
69+
but_still_check/setup.py``.
70+
71+
In particular, ``--exclude`` does not affect mypy's :ref:`import following
72+
<follow-imports>`. You can use a per-module :confval:`follow_imports` config
73+
option to additionally avoid mypy from following imports and checking code
74+
you do not wish to be checked.
6775

6876
Note that mypy will never recursively discover files and directories named
6977
"site-packages", "node_modules" or "__pycache__", or those whose name starts
@@ -687,6 +695,14 @@ in error messages.
687695

688696
Show absolute paths to files.
689697

698+
.. option:: --soft-error-limit N
699+
700+
This flag will adjust the limit after which mypy will (sometimes)
701+
disable reporting most additional errors. The limit only applies
702+
if it seems likely that most of the remaining errors will not be
703+
useful or they may be overly noisy. If ``N`` is negative, there is
704+
no limit. The default limit is 200.
705+
690706

691707
.. _incremental:
692708

@@ -876,8 +892,11 @@ Miscellaneous
876892

877893
This flag causes mypy to install known missing stub packages for
878894
third-party libraries using pip. It will display the pip command
879-
line to run, and expects a confirmation before installing
880-
anything.
895+
that will be run, and expects a confirmation before installing
896+
anything. For security reasons, these stubs are limited to only a
897+
small subset of manually selected packages that have been
898+
verified by the typeshed team. These packages include only stub
899+
files and no executable code.
881900

882901
If you use this option without providing any files or modules to
883902
type check, mypy will install stub packages suggested during the
@@ -889,8 +908,22 @@ Miscellaneous
889908
.. note::
890909

891910
This is new in mypy 0.900. Previous mypy versions included a
892-
selection of third-party package stubs, instead of having them
893-
installed separately.
911+
selection of third-party package stubs, instead of having
912+
them installed separately.
913+
914+
.. option:: --non-interactive
915+
916+
When used together with :option:`--install-types <mypy
917+
--install-types>`, this causes mypy to install all suggested stub
918+
packages using pip without asking for confirmation, and then
919+
continues to perform type checking using the installed stubs, if
920+
some files or modules are provided to type check.
921+
922+
This is implemented as up to two mypy runs internally. The first run
923+
is used to find missing stub packages, and output is shown from
924+
this run only if no missing stub packages were found. If missing
925+
stub packages were found, they are installed and then another run
926+
is performed.
894927

895928
.. option:: --junit-xml JUNIT_XML
896929

docs/source/common_issues.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Can't install mypy using pip
1414

1515
If installation fails, you've probably hit one of these issues:
1616

17-
* Mypy needs Python 3.5 or later to run.
17+
* Mypy needs Python 3.6 or later to run.
1818
* You may have to run pip like this:
1919
``python3 -m pip install mypy``.
2020

@@ -428,8 +428,8 @@ More specifically, mypy will understand the use of :py:data:`sys.version_info` a
428428
import sys
429429
430430
# Distinguishing between different versions of Python:
431-
if sys.version_info >= (3, 5):
432-
# Python 3.5+ specific definitions and imports
431+
if sys.version_info >= (3, 8):
432+
# Python 3.8+ specific definitions and imports
433433
elif sys.version_info[0] >= 3:
434434
# Python 3 specific definitions and imports
435435
else:

0 commit comments

Comments
 (0)