Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into typevar2
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Aug 2, 2021
2 parents fe6865b + 2c90912 commit 4e82ce9
Show file tree
Hide file tree
Showing 885 changed files with 39,590 additions and 12,979 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/mypy_primer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
mypy_primer:
name: Run
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
shard-index: [0, 1, 2]
Expand Down Expand Up @@ -48,10 +50,20 @@ jobs:
--num-shards 3 --shard-index ${{ matrix.shard-index }} \
--debug \
--output concise \
| tee diff.txt
| tee diff_${{ matrix.shard-index }}.txt
) || [ $? -eq 1 ]
- name: Upload mypy_primer diff
uses: actions/upload-artifact@v2
with:
name: mypy_primer_diff_${{ matrix.shard-index }}
path: diff.txt
name: mypy_primer_diffs
path: diff_${{ matrix.shard-index }}.txt
- if: ${{ matrix.shard-index }} == 0
name: Save PR number
run: |
echo ${{ github.event.pull_request.number }} | tee pr_number.txt
- if: ${{ matrix.shard-index }} == 0
name: Upload PR number
uses: actions/upload-artifact@v2
with:
name: mypy_primer_diffs
path: pr_number.txt
149 changes: 72 additions & 77 deletions .github/workflows/mypy_primer_comment.yml
Original file line number Diff line number Diff line change
@@ -1,104 +1,99 @@
name: Comment with mypy_primer diff

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

permissions:
contents: read
pull-requests: write

jobs:
mypy_primer:
name: Comment
comment:
name: Comment PR from mypy_primer
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: npm install adm-zip
- name: Post comment
- name: Download diffs
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const AdmZip = require(`${process.env.GITHUB_WORKSPACE}/node_modules/adm-zip`)
const fs = require('fs');
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const [matchArtifact] = artifacts.data.artifacts.filter((artifact) =>
artifact.name == "mypy_primer_diffs");
// Because of pull_request_target, context.sha is the PR base branch
// So we need to ask Github for the SHA of the PR's head commit
const pull_request = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
})
const pr_commit_sha = pull_request.data.head.sha
console.log("Looking for mypy_primer run for commit:", pr_commit_sha)
const download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: "zip",
});
fs.writeFileSync("diff.zip", Buffer.from(download.data));
// Find the mypy_primer run for our commit and wait till it's completed
// We wait up to an hour before timing out
async function check_mypy_primer() {
// We're only looking at the first page, so in theory if we open enough PRs around
// the same time, this will fail to find the run.
const response = await github.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "mypy_primer.yml",
})
if (response) {
return response.data.workflow_runs.find(run => run.head_sha == pr_commit_sha)
}
return undefined
}
- run: unzip diff.zip

const end_time = Number(new Date()) + 60 * 60 * 1000
let primer_run = await check_mypy_primer()
while (!primer_run || primer_run.status != "completed") {
if (Number(new Date()) > end_time) {
throw Error("Timed out waiting for mypy_primer")
}
console.log("Waiting for mypy_primer to complete...")
await new Promise(r => setTimeout(r, 10000))
primer_run = await check_mypy_primer()
}
console.log("Found mypy_primer run!")
console.log(primer_run)
# Based on https://github.com/kanga333/comment-hider
- name: Hide old comments
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
// Download artifact(s) from the run
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: primer_run.id,
const response = await github.issues.listComments({
issue_number: fs.readFileSync("pr_number.txt", { encoding: "utf8" }),
owner: context.repo.owner,
repo: context.repo.repo,
})
const filtered_artifacts = artifacts.data.artifacts.filter(
a => a.name.startsWith("mypy_primer_diff")
)
console.log("Artifacts from mypy_primer:")
console.log(filtered_artifacts)
const botCommentIds = response.data
.filter(comment => comment.user.login === 'github-actions[bot]')
.map(comment => comment.node_id)
async function get_artifact_data(artifact) {
const zip = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: "zip",
})
const adm = new AdmZip(Buffer.from(zip.data))
return adm.readAsText(adm.getEntry("diff.txt"))
for (const id of botCommentIds) {
const resp = await github.graphql(`
mutation {
minimizeComment(input: {classifier: OUTDATED, subjectId: "${id}"}) {
minimizedComment {
isMinimized
}
}
}
`)
if (resp.errors) {
throw new Error(resp.errors)
}
}
const all_data = await Promise.all(filtered_artifacts.map(get_artifact_data))
const data = all_data.join("\n")
- name: Post comment
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
// Keep in sync with shards produced by mypy_primer workflow
const data = (
['diff_0.txt', 'diff_1.txt', 'diff_2.txt']
.map(fileName => fs.readFileSync(fileName, { encoding: 'utf8' }))
.join('')
.substr(0, 30000) // About 300 lines
)
console.log("Diff from mypy_primer:")
console.log(data)
if (data.trim()) {
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 + '```'
await github.issues.createComment({
issue_number: context.issue.number,
issue_number: fs.readFileSync("pr_number.txt", { encoding: "utf8" }),
owner: context.repo.owner,
repo: context.repo.repo,
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 + '```'
body
})
}
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
architecture: ${{ matrix.arch }}
- name: install tox
run: pip install --upgrade 'setuptools!=50' 'virtualenv<20' tox==3.20.1
run: pip install --upgrade 'setuptools!=50' 'virtualenv<16.7.11' tox==3.20.1
- name: setup tox environment
run: tox -e ${{ matrix.toxenv }} --notest
- name: test
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/test_stubgenc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ jobs:

- uses: actions/checkout@v2

- name: initialize submodules
run: git submodule update --init

- name: Setup 🐍 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Test stubgenc
run: misc/test-stubgenc.sh
run: misc/test-stubgenc.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mypyc/doc/_build
*.iml
/out/
.venv*/
venv/
.mypy_cache/
.incremental_checker_cache.json
.cache
Expand Down Expand Up @@ -44,6 +45,8 @@ htmlcov
bin/
lib/
include/
.python-version
pyvenv.cfg

.tox
pip-wheel-metadata
Expand Down
20 changes: 8 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,22 @@ env:
jobs:
fast_finish: true
include:
# Specifically request 3.5.1 because we need to be compatible with that.
- name: "run test suite with python 3.5.1 (compiled with mypyc)"
python: 3.5.1
dist: trusty
- name: "run test suite with python 3.6 (compiled with mypyc)"
python: 3.6 # 3.6.3 pip 9.0.1
env:
- TOXENV=py
- EXTRA_ARGS="-n 2"
- TEST_MYPYC=1
- name: "run test suite with python 3.6"
python: 3.6 # 3.6.3 pip 9.0.1
- name: "run test suite with python 3.7 (compiled with mypyc)"
- name: "run test suite with python 3.7"
python: 3.7
- name: "run test suite with python 3.8"
python: 3.8
- name: "run test suite with python 3.9 (compiled with mypyc)"
python: 3.9
env:
- TOXENV=py
- EXTRA_ARGS="-n 2"
- TEST_MYPYC=1
- name: "run test suite with python 3.8"
python: 3.8
- name: "run test suite with python 3.9"
python: 3.9
- name: "run test suite with python nightly"
python: nightly
- name: "run mypyc runtime tests with python 3.6 debug build"
Expand Down Expand Up @@ -89,7 +85,7 @@ jobs:
install:
# pip 21.0 no longer works on Python 3.5
- pip install -U pip==20.3.4 setuptools
- pip install -U 'virtualenv<20'
- pip install -U 'virtualenv<16.7.11'
- pip install -U tox==3.20.1
- python2 -m pip install --user -U typing
- tox --notest
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Mypy (and mypyc) are licensed under the terms of the MIT license, reproduced bel

The MIT License

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

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# stubs
prune mypy/typeshed
include mypy/typeshed/LICENSE
include mypy/typeshed/stdlib/VERSIONS
recursive-include mypy/typeshed *.pyi

Expand Down
2 changes: 0 additions & 2 deletions build-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
-r mypy-requirements.txt
types-typed-ast>=1.4.0,<1.5.0
types-toml>=0.0
types-enum34>=0.0; python_version == '3.5'
8 changes: 1 addition & 7 deletions docs/source/class_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ initialized within the class. Mypy infers the types of attributes:
a = A(1)
a.x = 2 # OK!
a.y = 3 # Error: 'A' has no attribute 'y'
a.y = 3 # Error: "A" has no attribute "y"
This is a bit like each class having an implicitly defined
:py:data:`__slots__ <object.__slots__>` attribute. This is only enforced during type
Expand Down Expand Up @@ -127,12 +127,6 @@ particular attribute should not be set on instances:
a.x = 1 # Error: Cannot assign to class variable "x" via instance
print(a.x) # OK -- can be read through an instance
.. note::

If you need to support Python 3 versions 3.5.2 or earlier, you have
to import ``ClassVar`` from ``typing_extensions`` instead (available on
PyPI). If you use Python 2.7, you can import it from ``typing``.

It's not necessary to annotate all class variables using
:py:data:`~typing.ClassVar`. An attribute without the :py:data:`~typing.ClassVar` annotation can
still be used as a class variable. However, mypy won't prevent it from
Expand Down

0 comments on commit 4e82ce9

Please sign in to comment.