Skip to content

Commit 510bfee

Browse files
Merge pull request #9 from microbit-foundation/three-microbit-update
Update microbit branch from browser branch. Minor test fix-ups after merge.
2 parents b91acaf + 8ff72b4 commit 510bfee

File tree

2,171 files changed

+99229
-34791
lines changed

Some content is hidden

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

2,171 files changed

+99229
-34791
lines changed

.eslintrc.json

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,61 @@
6262
"args": "none"
6363
}
6464
],
65-
"@typescript-eslint/no-use-before-define": 0
65+
"@typescript-eslint/no-use-before-define": 0,
66+
"@typescript-eslint/naming-convention": [
67+
"error",
68+
{
69+
"selector": [
70+
"classProperty",
71+
"typeProperty",
72+
"parameterProperty",
73+
"classMethod",
74+
"typeMethod",
75+
"accessor"
76+
],
77+
"modifiers": ["private"],
78+
"leadingUnderscore": "require",
79+
"format": ["camelCase"],
80+
"filter": {
81+
"regex": "^(test_| )",
82+
"match": false
83+
}
84+
},
85+
{
86+
"selector": [
87+
"classProperty",
88+
"typeProperty",
89+
"parameterProperty",
90+
"classMethod",
91+
"typeMethod",
92+
"accessor"
93+
],
94+
"modifiers": ["protected"],
95+
"leadingUnderscore": "allow",
96+
"format": ["camelCase"],
97+
"filter": {
98+
"regex": "^(test_| )",
99+
"match": false
100+
}
101+
},
102+
{
103+
"selector": [
104+
"classProperty",
105+
"typeProperty",
106+
"parameterProperty",
107+
"classMethod",
108+
"typeMethod",
109+
"accessor"
110+
],
111+
"modifiers": ["public"],
112+
"leadingUnderscore": "forbid",
113+
"format": ["camelCase"],
114+
"filter": {
115+
"regex": "^(test_| )",
116+
"match": false
117+
}
118+
}
119+
]
66120
},
67121
"overrides": [
68122
{

.github/workflows/validation.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Validation'
22

33
env:
4-
NODE_VERSION: '12' # Shipped with VS Code.
4+
NODE_VERSION: '14' # Shipped with VS Code.
55

66
on:
77
push:
@@ -14,7 +14,7 @@ on:
1414
jobs:
1515
typecheck:
1616
if: github.repository == 'microsoft/pyright'
17-
runs-on: ubuntu-18.04
17+
runs-on: ubuntu-latest
1818
name: Typecheck
1919

2020
steps:
@@ -41,7 +41,7 @@ jobs:
4141

4242
style:
4343
if: github.repository == 'microsoft/pyright'
44-
runs-on: ubuntu-18.04
44+
runs-on: ubuntu-latest
4545
name: Style
4646

4747
steps:
@@ -73,7 +73,7 @@ jobs:
7373
strategy:
7474
fail-fast: false
7575
matrix:
76-
os: [macos-10.15, windows-2019, ubuntu-18.04]
76+
os: [macos-latest, windows-2019, ubuntu-latest]
7777

7878
name: Test ${{ matrix.os }}
7979
runs-on: ${{ matrix.os }}
@@ -108,7 +108,7 @@ jobs:
108108
working-directory: packages/pyright-internal
109109

110110
build:
111-
runs-on: ubuntu-18.04
111+
runs-on: ubuntu-latest
112112
name: Build
113113
needs: typecheck
114114

@@ -139,7 +139,7 @@ jobs:
139139
working-directory: packages/vscode-pyright
140140

141141
required:
142-
runs-on: ubuntu-18.04
142+
runs-on: ubuntu-latest
143143
name: Required
144144
needs:
145145
- typecheck

.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@
7676
"disableOptimisticBPs": true,
7777
"program": "${workspaceFolder}/packages/pyright-internal/node_modules/jest/bin/jest"
7878
},
79+
{
80+
"name": "Pyright jest selected test",
81+
"type": "node",
82+
"request": "launch",
83+
"args": ["${fileBasenameNoExtension}", "--runInBand", "-t", "${selectedText}"],
84+
"cwd": "${workspaceRoot}/packages/pyright-internal",
85+
"console": "integratedTerminal",
86+
"internalConsoleOptions": "neverOpen",
87+
"disableOptimisticBPs": true,
88+
"program": "${workspaceFolder}/packages/pyright-internal/node_modules/jest/bin/jest"
89+
},
7990
{
8091
"name": "Pyright fourslash current file",
8192
"type": "node",

README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ Pyright supports [configuration files](/docs/configuration.md) that provide gran
2525
* [PEP 612](https://www.python.org/dev/peps/pep-0612/) parameter specification variables
2626
* [PEP 613](https://www.python.org/dev/peps/pep-0613/) explicit type aliases
2727
* [PEP 635](https://www.python.org/dev/peps/pep-0635/) structural pattern matching
28-
* [PEP 637](https://www.python.org/dev/peps/pep-0637/) indexing with keyword arguments
2928
* [PEP 646](https://www.python.org/dev/peps/pep-0646/) variadic generics
3029
* [PEP 647](https://www.python.org/dev/peps/pep-0647/) user-defined type guards
3130
* [PEP 655](https://www.python.org/dev/peps/pep-0655/) required typed dictionary items
31+
* [PEP 673](https://www.python.org/dev/peps/pep-0673/) Self type
32+
* [PEP 675](https://www.python.org/dev/peps/pep-0675/) arbitrary literal strings
33+
* [PEP 681](https://www.python.org/dev/peps/pep-0681/) dataclass transform
3234
* Type inference for function return values, instance variables, class variables, and globals
3335
* Type guards that understand conditional code flow constructs like if/else statements
3436

@@ -61,40 +63,45 @@ For rich Python editing and debugging capabilities with Visual Studio Code, be s
6163

6264
## Installation
6365
### VS Code Extension
64-
For most VS Code users, we recommend using the Pylance extension rather than Pyright. Pylance incorporates the pyright type checker but features additional capabilities such as IntelliCode and semantic token highlighting. You can install the latest-published version of the Pylance VS Code extension directly from VS Code. Simply open the extensions panel and search for `pylance`.
66+
For most VS Code users, we recommend using the Pylance extension rather than Pyright. Pylance incorporates the Pyright type checker but features additional capabilities such as IntelliCode and semantic token highlighting. You can install the latest-published version of the Pylance VS Code extension directly from VS Code. Simply open the extensions panel and search for “Pylance”.
6567

6668
### Vim
67-
For vim/neovim users, you can install [coc-pyright](https://github.com/fannheyward/coc-pyright), the Pyright extension for coc.nvim.
69+
Vim/neovim users can install [coc-pyright](https://github.com/fannheyward/coc-pyright), the Pyright extension for coc.nvim.
6870

6971
Alternatively, [ALE](https://github.com/dense-analysis/ale) will automatically check your code with Pyright, without requiring any additional configuration.
7072

7173
### Sublime Text
72-
For sublime text users, you can install the [LSP-pyright](https://github.com/sublimelsp/LSP-pyright) plugin from [package control](https://packagecontrol.io/packages/LSP-pyright).
74+
Sublime text users can install the [LSP-pyright](https://github.com/sublimelsp/LSP-pyright) plugin from [package control](https://packagecontrol.io/packages/LSP-pyright).
7375

7476
### Emacs
75-
For emacs users, you can install [lsp-mode](https://github.com/emacs-lsp/lsp-mode) that includes [lsp-pyright](https://github.com/emacs-lsp/lsp-pyright).
77+
Emacs users can install [lsp-mode](https://github.com/emacs-lsp/lsp-mode) that includes [lsp-pyright](https://github.com/emacs-lsp/lsp-pyright).
7678
To activate the pyright extension follow the instructions in the [docs](https://emacs-lsp.github.io/lsp-pyright/).
7779

7880
### Command-line
79-
The latest version of the command-line tool can be installed with npm, which is part of node. If you don't have a recent version of node on your system, install that first from [nodejs.org](https://nodejs.org).
81+
A [community-maintained](https://github.com/RobertCraigie/pyright-python) Python package by the name of “pyright” is available on pypi and conda-forge. This package will automatically install node (which Pyright requires) and keep Pyright up to date.
82+
83+
`pip install pyright`
84+
85+
or
86+
87+
`conda install pyright`
88+
89+
Once installed, you can run the tool from the command line as follows:
90+
`pyright <options>`
91+
92+
93+
Alternatively, you can install the command-line version of Pyright directly from npm, which is part of node. If you don't have a recent version of node on your system, install that first from [nodejs.org](https://nodejs.org).
8094

8195
To install pyright globally:
8296
`npm install -g pyright`
8397

8498
On MacOS or Linux, sudo is required to install globally:
8599
`sudo npm install -g pyright`
86100

87-
Once installed, you can run the tool from the command line as follows:
88-
`pyright <options>`
89-
90101
To update to the latest version:
91102
`sudo npm update -g pyright`
92103

93104

94-
## Using Pyright with VS Code Python Extension
95-
Pyright’s type-checking functionality and language features are now incorporated into a VS Code extension called [Pylance](https://github.com/microsoft/pylance-release), the officially supported Python Language Server from Microsoft. Pylance is designed to work with the Python extension for VS Code. In addition to Pyright’s functionality, Pylance adds compatibility with several advanced features including IntelliCode for AI-assisted completions. If you are a VS Code user, we recommend that you uninstall Pyright and instead install Pylance. You will get all the benefits of Pyright and more!
96-
97-
98105
## Documentation
99106
* [Getting Started with Type Checking](/docs/getting-started.md)
100107
* [Type Concepts](/docs/type-concepts.md)
@@ -105,6 +112,7 @@ Pyright’s type-checking functionality and language features are now incorporat
105112
* [Comments](/docs/comments.md)
106113
* [Type Inference](/docs/type-inference.md)
107114
* [Import Resolution](/docs/import-resolution.md)
115+
* [Extending Builtins](/docs/builtins.md)
108116
* [Type Stubs](/docs/type-stubs.md)
109117
* [Types in Libraries](/docs/typed-libraries.md)
110118
* [Commands](/docs/commands.md)
@@ -114,12 +122,14 @@ Pyright’s type-checking functionality and language features are now incorporat
114122
For additional information about Python static typing, refer to this community-maintained [Python Type School](https://github.com/python/typing/discussions).
115123

116124
## Limitations
117-
Pyright provides support for Python 3.0 and newer. There is currently no plan to support older versions.
125+
Pyright provides support for Python 3.0 and newer. There are no plans to support older versions.
118126

119127

120128
## Community
121129
Do you have questions about Pyright or Python type annotations in general? Post your questions in [the discussion section](https://github.com/microsoft/pyright/discussions).
122130

131+
If you would like to report a bug or request an enhancement, file a new issue in either the [pyright](https://github.com/microsoft/pyright/issues) or [pylance-release](https://github.com/microsoft/pylance-release/issues) issue tracker. In general, core type checking functionality is associated with Pyright while language service functionality is associated with Pylance, but the same contributors monitor both repos. For best results, provide the information requested in the issue template.
132+
123133

124134
## FAQ
125135
**Q:** What is the difference between Pyright and [Pylance](https://github.com/microsoft/pylance-release)?
@@ -128,12 +138,12 @@ Do you have questions about Pyright or Python type annotations in general? Post
128138

129139
**Q:** What is the long-term plan for Pyright?
130140

131-
**A:** Pyright is now an officially-supported Microsoft type checker for Python. It will continue to be developed and maintained as an open-source project under its original MIT license terms. The Pyright extension for VSCode is a reference implementation and is not guaranteed to be fully functional or maintained long-term.
141+
**A:** Pyright is an officially-supported Microsoft type checker for Python. It will continue to be developed and maintained as an open-source project under its original MIT license terms. The Pyright extension for VS Code is a reference implementation and is not guaranteed to be fully functional or maintained long-term.
132142

133143

134144
## Contributing
135145

136-
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
146+
This project welcomes contributions and suggestions. For feature and complex bug fix contributions, it is recommended that you first discuss the proposed change with Pyright’s maintainers before submitting the pull request. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
137147

138148
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
139149

build/lib/updateDeps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function updatePackage(packageFile, transitive, reject = undefined) {
4747
reject: reject,
4848
});
4949

50-
if (!transitive && Object.keys(updateResult).length === 0) {
50+
if (!transitive && Object.keys(/**@type {any}*/ (updateResult)).length === 0) {
5151
// If nothing changed and we aren't updating transitive deps, don't run npm install.
5252
return;
5353
}

build/updateDeps.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ async function main() {
1414
// These packages impact compatibility with VS Code and other users;
1515
// ensure they remained pinned exactly.
1616
'@types/vscode',
17+
'vsce',
1718
'vscode-jsonrpc',
1819
'vscode-languageclient',
1920
'vscode-languageserver',

docs/build-debug.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ The resulting package (pyright-X.Y.Z.vsix) can be found in the client directory.
2424
To install in VS Code, go to the extensions panel and choose “Install from VSIX...” from the menu, then select the package.
2525

2626

27+
## Running Pyright tests
28+
29+
1. cd to the `packages/pyright-internal` directory
30+
2. Execute `npm run test`
31+
32+
2733
## Debugging Pyright
2834

2935
To debug pyright, open the root source directory within VS Code. Open the debug sub-panel and choose “Pyright CLI” from the debug target menu. Click on the green “run” icon or press F5 to build and launch the command-line version in the VS Code debugger.

docs/builtins.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Extending Builtins
2+
3+
The Python interpreter implicitly adds a set of symbols that are available within every module even though they are not explicitly imported. These so-called “built in” symbols include commonly-used types and functions such as “list”, “dict”, “int”, “float”, “min”, and “len”.
4+
5+
Pyright gains knowledge of which types are included in “builtins” scope through the type stub file `builtins.pyi`. This stub file comes from the typeshed github repo and is bundled with pyright, along with type stubs that describe other stdlib modules.
6+
7+
Some Python environments are customized to include additional builtins symbols. If you are using such an environment, you may want to tell Pyright about these additional symbols that are available at runtime. To do so, you can add a local type stub file called `__builtins__.pyi`. This file can be placed at the root of your project directory or at the root of the subdirectory specified in the `stubPath` setting (which is named `typings` by default).
8+

docs/ci-integration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ You can configure pyright to run as a git hook (e.g. prior to each check-in) by
1313
language: node
1414
pass_filenames: false
1515
types: [python]
16-
additional_dependencies: ['[email protected]']
16+
# Replace the version below with the latest pyright version
17+
additional_dependencies: ['[email protected]']
1718
```
1819
1920
### Running Pyright from a CI script

docs/command-line.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ Pyright can be run as either a VS Code extension or as a node-based command-line
1515
| -p, --project `<FILE OR DIRECTORY>` | Use the configuration file at this location |
1616
| --pythonplatform `<PLATFORM>` | Analyze for platform (Darwin, Linux, Windows) |
1717
| --pythonversion `<VERSION>` | Analyze for version (3.3, 3.4, etc.) |
18+
| --skipunannotated | Skip type analysis of unannotated functions? |
1819
| --stats | Print detailed performance stats |
1920
| -t, --typeshed-path `<DIRECTORY>` | Use typeshed type stubs at this location (2) |
2021
| -v, --venv-path `<DIRECTORY>` | Directory that contains virtual environments (3) |
2122
| --verbose | Emit verbose diagnostics |
2223
| --verifytypes `<IMPORT>` | Verify completeness of types in py.typed package |
2324
| --version | Print pyright version |
25+
| --warnings | Use exit code of 1 if warnings are reported |
2426
| -w, --watch | Continue to run and watch for changes (4) |
2527

2628
(1) If specific files are specified on the command line, the pyrightconfig.json file is ignored.
@@ -61,7 +63,7 @@ If the “--outputjson” option is specified on the command line, diagnostics a
6163
}
6264
```
6365

64-
Each Diagnostic is formatted output in the following format:
66+
Each Diagnostic is output in the following format:
6567

6668
```javascript
6769
{
@@ -83,3 +85,5 @@ Each Diagnostic is formatted output in the following format:
8385
```
8486

8587
Diagnostic line and character numbers are zero-based.
88+
89+
Not all diagnostics have an associated diagnostic rule. Diagnostic rules are used only for diagnostics that can be disabled or enabled. If a rule is associated with the diagnostic, it is included in the output. If it’s not, the rule field is omitted from the JSON output.

docs/comments.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@ self._target = 3 # type: Union[int, str]
1212
```
1313

1414
## File-level Type Controls
15-
Strict typing controls (where all supported type-checking switches generate errors) can be enabled for a file through the use of a special comment. Typically this comment is placed at or near the top of a code file on its own line.
15+
Strict type checking, where most supported type-checking switches generate errors, can be enabled for a file through the use of a special comment. Typically this comment is placed at or near the top of a code file on its own line.
1616

1717
```python
1818
# pyright: strict
1919
```
2020

21-
Individual configuration settings can also be overridden on a per-file basis and combined with “strict” typing. For example, if you want to enable all type checks except for “reportPrivateUsage”, you could add the following comment:
21+
Likewise, basic type checking can be enabled for a file.
22+
23+
```python
24+
# pyright: basic
25+
```
26+
27+
Individual configuration settings can also be overridden on a per-file basis and optionally combined with “strict” or “basic” type checking. For example, if you want to enable all type checks except for “reportPrivateUsage”, you could add the following comment:
2228

2329
```python
2430
# pyright: strict, reportPrivateUsage=false

0 commit comments

Comments
 (0)