Updated documentation.

This commit is contained in:
Eric Traut 2019-03-11 21:30:44 -07:00
parent 66a03a9525
commit 6d6f2b6f4f
3 changed files with 67 additions and 47 deletions

View File

@ -1,6 +1,39 @@
# pyright
~[](https://github.com/Microsoft/pyright/blob/master/docs/img/PyrightLarge.png)
# Static type checker for the Python language
Pyright was created to address gaps in existing Python type checkers like [mypy](http://mypy-lang.org).
### Speed
Pyright is typically 5x or more faster than mypy and other type checkers that are written in Python. It is meant for large Python source bases. It can run in a "watch" mode and performs fast incremental updates when files are modified.
### No Python Dependence
Pyright is written in TypeScript and runs within node. It does not require a Python environment to be installed and does not rely on imported packages to be installed. This is especially useful when used with the VS Code editor, which uses node as its extension runtime.
### Configurability
Pyright supports a flexible configuration file that provides granular control over settings. Different "execution environments" can be specified for different subsets of a source base. Each environment can specify different PYTHON_PATH settings, python language version, and platform target.
### Type Checking Features
Pyright supports:
* [PEP 484](https://www.python.org/dev/peps/pep-0484/) type hints (currently missing support for generic)
* [PEP 526](https://www.python.org/dev/peps/pep-0526/) syntax for variable annotations
* [PEP 544](https://www.python.org/dev/peps/pep-0544/) structural subtyping
* Type inference for function return values, instance variables, class variables, and globals
* Smart conditional type exclusions
### Built-in Type Stubs
Pyright includes a recent copy of the stdlib type stubs from [Typeshed](https://github.com/python/typeshed). It can be configured to use another (perhaps more recent or modified) copy of the Typeshed type stubs. Of course, it also works with custom type stub files that are part of your project.
### Command-line or Language Service
Pyright includes both a command-line tool and a [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) plugin for VS Code.
### Language Service Features
Pyright offers the following language service features:
* Hover tool tips that display type information
* Links to symbol definitions
Static type checker for the Python language
## Build Instructions
@ -10,6 +43,38 @@ Static type checker for the Python language
4. Execute "npm run build"
## Code Structure
* client/src/extension.ts: Language Server Protocol (LSP) client entry point for VS Code extension.
* client/typeshed-fallback/: Recent copy of Typeshed type stub files for Python stdlib
* server/src/pyright.ts: Main entry point for command-line tool
* server/src/server.ts: Main entry point for LSP server
* server/src/analyzer: Modules that perform analysis passes over Python parse tree
* server/src/common: Modules that are common to the parser and analyzer
* server/src/parser: Modules that perform tokenization and parsing of Python source
* server/src/tests: Tests for the parser and analyzer
## TODO
Pyright is a work in progress. The following functionality is not yet finished. If you would like to contribute to any of these areas, contact the maintainers of the repo.
* Support for generics
* Add numeric codes to diagnostics and a configuration mechanism for disabling errors by code
* Move error strings out of the main code files so they can be localized
* Add lots of tests
* Address the many TODO comments in the code
* Parameter type inference based on default value assignment
* Special-casing @abstract methods so they don't need to return the specified type
* Validate that @abstract classes are not instantiated
* Support for Python 2.7 type annotations within comments
* Validate that __init__ always has None as return type
* Validate that overridden methods in subclass have same signature as base class methods
* Verify that exception classes inherit from base Exception
* Validate await / async consitency
* Flag assignments to read-only values (None, True, False, __debug__) as errors
## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a

View File

@ -1,44 +0,0 @@
"use strict";
/*
* extension.ts
*
* Provides client for Pyright Python language server. This portion runs
* in the context of the VS Code process and talks to the server, which
* runs in another process.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const vscode_1 = require("vscode");
const vscode_languageclient_1 = require("vscode-languageclient");
function activate(context) {
let serverModule = context.asAbsolutePath(path.join('server', 'server.js'));
let debugOptions = { execArgv: ["--nolazy", "--inspect=6600"] };
// If the extension is launched in debug mode, then the debug server options are used.
// Otherwise the run options are used.
let serverOptions = {
run: { module: serverModule, transport: vscode_languageclient_1.TransportKind.ipc },
debug: { module: serverModule, transport: vscode_languageclient_1.TransportKind.ipc, options: debugOptions }
};
// Options to control the language client
let clientOptions = {
// Register the server for plain text documents
documentSelector: [{
scheme: 'file',
language: 'python'
}],
synchronize: {
// Synchronize the setting section 'languageServerExample' to the server
configurationSection: 'python',
// Notify the server about file changes to '.clientrc files contain in the workspace
fileEvents: vscode_1.workspace.createFileSystemWatcher('**/.clientrc')
}
};
// Create the language client and start the client.
let languageClient = new vscode_languageclient_1.LanguageClient('python', 'Python', serverOptions, clientOptions);
let disposable = languageClient.start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation.
context.subscriptions.push(disposable);
}
exports.activate = activate;
//# sourceMappingURL=extension.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":";AAAA;;;;;;EAME;;AAEF,6BAA6B;AAC7B,mCAAqD;AACrD,iEAA4G;AAE5G,SAAgB,QAAQ,CAAC,OAAyB;IACjD,IAAI,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IAC5E,IAAI,YAAY,GAAG,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,gBAAgB,CAAC,EAAE,CAAC;IAEhE,sFAAsF;IACtF,sCAAsC;IACtC,IAAI,aAAa,GAAkB;QAClC,GAAG,EAAG,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,qCAAa,CAAC,GAAG,EAAE;QAC5D,KAAK,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,qCAAa,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE;KACpF,CAAA;IAED,yCAAyC;IACzC,IAAI,aAAa,GAA0B;QAC1C,+CAA+C;QAC/C,gBAAgB,EAAE,CAAC;gBAClB,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,QAAQ;aAClB,CAAC;QACF,WAAW,EAAE;YACZ,wEAAwE;YACxE,oBAAoB,EAAE,QAAQ;YAC9B,oFAAoF;YACpF,UAAU,EAAE,kBAAS,CAAC,uBAAuB,CAAC,cAAc,CAAC;SAC7D;KACD,CAAA;IAED,mDAAmD;IACnD,IAAI,cAAc,GAAG,IAAI,sCAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IAC1F,IAAI,UAAU,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC;IAExC,kEAAkE;IAClE,uDAAuD;IACvD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC;AAjCD,4BAiCC"}