Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
jbradaric committed Jun 16, 2023
2 parents c20305a + b90abab commit cf55ea0
Show file tree
Hide file tree
Showing 343 changed files with 12,880 additions and 5,215 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Bug report
about: Create a report to help us improve pyright
about: Report incorrect or unintended behaviors
title: ''
labels: ''
labels: bug
assignees: ''

---
Expand All @@ -20,7 +20,7 @@ Steps to reproduce the behavior.
**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots or Code**
**Code or Screenshots**
If possible, provide a minimal, self-contained code sample (surrounded by triple back ticks) to demonstrate the issue. The code should define or imports all referenced symbols.

```python
Expand All @@ -31,7 +31,7 @@ def foo(self) -> str:
If your code relies on symbols that are imported from a third-party library, include the associated import statements and specify which versions of those libraries you have installed.

**VS Code extension or command-line**
Are you running pyright as a VS Code extension or a command-line tool? Which version? You can find the version of the VS Code extension by clicking on the Pyright icon in the extensions panel.
Are you running pyright as a VS Code extension, a language server in another editor, or the command-line tool? Which version?

**Additional context**
Add any other context about the problem here.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
name: Feature request
about: Suggest an idea for pyright
about: Suggest an idea or improvement
title: ''
labels: enhancement request
assignees: ''

---

If you have a question about a behavior that you’re seeing in Pyright, consider posting to the [Pyright discussion forum](https://github.com/microsoft/pyright/discussions).

**Is your feature request related to a problem? Please describe.**
A clear and concise description of the problem.

Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/mypy_primer_comment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# This workflow runs when the "Run mypy_primer on PR" workflow completes.
# It downloads the diff from the other workflow instances and creates
# a summary comment in the PR.
name: Comment with mypy_primer diff

on:
workflow_run:
workflows:
- Run mypy_primer on PR
types:
- completed

permissions:
contents: read
pull-requests: write

jobs:
comment:
name: Comment PR from mypy_primer
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download diffs
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const artifacts = await github.rest.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");
const download = await github.rest.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));
- run: unzip diff.zip
- run: |
cat diff_*.txt | tee fulldiff.txt
- name: Post comment
id: post-comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const MAX_CHARACTERS = 30000
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3
const fs = require('fs')
let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' })
function truncateIfNeeded(original, maxLength) {
if (original.length <= maxLength) {
return original
}
let truncated = original.substring(0, maxLength)
// further, remove last line that might be truncated
truncated = truncated.substring(0, truncated.lastIndexOf('\n'))
let lines_truncated = original.split('\n').length - truncated.split('\n').length
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...`
}
const projects = data.split('\n\n')
// don't let one project dominate
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n')
// posting comment fails if too long, so truncate
data = truncateIfNeeded(data, MAX_CHARACTERS)
console.log("Diff from mypy_primer:")
console.log(data)
let body
if (data.trim()) {
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 + '```'
} else {
body = "According to [mypy_primer](https://github.com/hauntsaninja/mypy_primer), this change doesn't affect type check results on a corpus of open source code. ✅"
}
const prNumber = parseInt(fs.readFileSync("pr_number.txt", { encoding: "utf8" }))
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
return prNumber
- name: Hide old comments
# v0.4.0
uses: kanga333/comment-hider@c12bb20b48aeb8fc098e35967de8d4f8018fffdf
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
leave_visible: 1
issue_number: ${{ steps.post-comment.outputs.result }}
91 changes: 91 additions & 0 deletions .github/workflows/mypy_primer_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# This workflow runs mypy_primer, a tool that runs pyright on a variety
# of open-source Python projects that are known to type check with pyright.
# It builds pyright from the latest PR commit and the merge base of the PR
# and compares the output of both. It uploads the diffs as an artifact and
# creates a PR comment with the results (with the help of the
# mypy_primer_comment action).

# This workflow definition borrows liberally from the mypy repo. The original
# workflow was designed to work in a sharded manner where n copies of
# mypy_primer are started in parallel. Each instance runs 1/n of the projects.
# For now, we run only one instance because pyright is fast, and the number
# of projects that use pyright for type checking is small. To change this in
# the future, change the 'shard_index' matrix to [0, 1, ..., n-1] and set
# 'num-shards' to n.

name: Run mypy_primer on PR

on:
# Run on the creation or update of a PR.
pull_request:
paths:
- 'packages/pyright/**'
- 'packages/pyright-internal/src/**'
- 'packages/pyright-internal/typeshed-fallback/**'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
mypy_primer:
name: Run mypy_primer on PR
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
shard-index: [0, 1]
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
path: pyright_to_test
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install -U pip
pip install git+https://github.com/hauntsaninja/mypy_primer.git
- name: Run mypy_primer
shell: bash
run: |
cd pyright_to_test
echo "new commit"
git rev-list --format=%s --max-count=1 $GITHUB_SHA
MERGE_BASE=$(git merge-base $GITHUB_SHA origin/$GITHUB_BASE_REF)
git checkout -b base_commit $MERGE_BASE
echo "base commit"
git rev-list --format=%s --max-count=1 base_commit
echo ''
cd ..
# fail action if exit code isn't zero or one
(
mypy_primer \
--repo pyright_to_test \
--type-checker pyright \
--new $GITHUB_SHA --old base_commit \
--num-shards 2 --shard-index ${{ matrix.shard-index }} \
--debug \
--output concise \
| tee diff_${{ matrix.shard-index }}.txt
) || [ $? -eq 1 ]
- name: Upload mypy_primer diff
uses: actions/upload-artifact@v3
with:
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@v3
with:
name: mypy_primer_diffs
path: pr_number.txt
65 changes: 65 additions & 0 deletions .github/workflows/mypy_primer_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This workflow runs mypy_primer, a tool that runs pyright on a variety
# of open-source Python projects that are known to type check with pyright.
# It builds pyright from the latest commit and the last release tag and
# compares the output of both. It uploads the diffs as an artifact.
name: Run mypy_primer on push

on:
# Run on all pushes to main.
push:
branches:
- main
paths:
- 'packages/pyright/**'
- 'packages/pyright-internal/src/**'
- 'packages/pyright-internal/typeshed-fallback/**'
# Also run manually if requested.
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
mypy_primer:
name: Run mypy_primer on push
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
path: pyright_to_test
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install -U pip
pip install git+https://github.com/hauntsaninja/mypy_primer.git
- name: Run mypy_primer
shell: bash
run: |
cd pyright_to_test
echo "new commit"
git rev-list --format=%s --max-count=1 $GITHUB_SHA
cd ..
# fail action if exit code isn't zero or one
(
mypy_primer \
--repo pyright_to_test \
--type-checker pyright \
--new $GITHUB_SHA \
--debug \
--output concise \
| tee diff.txt
) || [ $? -eq 1 ]
- name: Upload mypy_primer diff
uses: actions/upload-artifact@v3
with:
name: mypy_primer_diffs
path: diff.txt
22 changes: 11 additions & 11 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"fileLocation": "absolute",
"pattern": [
{
"regexp": "\\[tsl\\] (ERROR|WARNING) in (.*)?\\((\\d+),(\\d+)\\)",
"severity": 1,
"file": 2,
"line": 3,
"column": 4
},
{
"regexp": "\\s*TS(\\d+):\\s*(.*)$",
"code": 1,
"message": 2
}
"regexp": "\\[tsl\\] (ERROR|WARNING) in (.*)?\\((\\d+),(\\d+)\\)",
"severity": 1,
"file": 2,
"line": 3,
"column": 4
},
{
"regexp": "\\s*TS(\\d+):\\s*(.*)$",
"code": 1,
"message": 2
}
],
"background": {
"activeOnStart": true,
Expand Down
1 change: 1 addition & 0 deletions docs/ci-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ job_name:
- npm i -g pyright-to-gitlab-ci
script:
- pyright <python source> --outputjson > report_raw.json
after_script:
- pyright-to-gitlab-ci --src report_raw.json --output report.json --base_path .
artifacts:
paths:
Expand Down
2 changes: 1 addition & 1 deletion docs/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Pyright can be run as either a VS Code extension or as a node-based command-line
| -v, --venvpath `<DIRECTORY>` | Directory that contains virtual environments (4) |
| --verbose | Emit verbose diagnostics |
| --verifytypes `<IMPORT>` | Verify completeness of types in py.typed package |
| --version | Print pyright version |
| --version | Print pyright version and exit |
| --warnings | Use exit code of 1 if warnings are reported |
| -w, --watch | Continue to run and watch for changes (5) |

Expand Down
15 changes: 14 additions & 1 deletion docs/mypy-comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,20 @@ Pyright’s approach gives developers more control. It provides a way to be expl

### Overload Resolution

Overload resolution rules are under-specified in PEP 484. Pyright and mypy apply similar rules, but there are likely some complex edge cases where different results will be produced. For full documentation of pyright’s overload behaviors, refer to [this documentation](type-concepts-advanced.md#overloads).
Overload resolution rules are under-specified in PEP 484. Pyright and mypy apply similar rules, but there are inevitably cases where different results will be produced. For full documentation of pyright’s overload behaviors, refer to [this documentation](type-concepts-advanced.md#overloads).

One known difference is in the handling of ambiguous overloads due to `Any` argument types where one return type is the supertype of all other return types. In this case, pyright evaluates the resulting return type as the supertype, but mypy evaluates the return type as `Any`. Pyright’s behavior here tries to preserve as much type information as possible, which is important for completion suggestions.

```python
@overload
def func1(x: int) -> int: ...

@overload
def func1(x: str) -> float: ...

def func2(val: Any):
reveal_type(func1(val)) # mypy: Any, pyright: float
```


### Import Statements
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "1.1.313",
"version": "1.1.314",
"command": {
"version": {
"push": false,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"typescript": "~4.4.4",
"yargs": "^16.2.0"
}
}
}
Loading

0 comments on commit cf55ea0

Please sign in to comment.