Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require black and isort for contributions #3329

Merged
merged 21 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ jobs:
- name: "check file consistency"
script: ./tests/check_consistent.py
- name: "flake8"
install: pip install -r requirements-tests-py3.txt
install: pip install $(cat requirements-tests-py3.txt | grep flake8)
srittau marked this conversation as resolved.
Show resolved Hide resolved
script: flake8
- name: "black"
install: pip install $(cat requirements-tests-py3.txt | grep black)
script: black --check --diff stdlib third_party
- name: "isort"
install: pip install $(cat requirements-tests-py3.txt | grep isort)
script: isort --check-only --diff --recursive stdlib third_party
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ are important to the project's success.
* IMPORTANT: For new libraries, [get permission from the library owner first](#adding-a-new-library).
* Create your stubs [conforming to the coding style](#stub-file-coding-style).
* Make sure your tests pass cleanly on `mypy`, `pytype`, and `flake8`.
* Reformat your stubs with black and isort.
4. [Submit your changes](#submitting-changes):
* Open a pull request
* For new libraries, [include a reference to where you got permission](#adding-a-new-library)
Expand Down Expand Up @@ -238,8 +239,14 @@ rule is that they should be as concise as possible. Specifically:
* use variable annotations instead of type comments, even for stubs
that target older versions of Python;
* for arguments with a type and a default, use spaces around the `=`.
The code formatter [black](https://github.com/psf/black) will format
stubs according to this standard.

Stubs should be reformatted with the formatters
[black](https://github.com/psf/black) and
[isort](https://github.com/timothycrosley/isort) before submission.
These formatters are included in typeshed's `requirements-tests-py3.txt` file.
A sample `pre-commit` file is included in the typeshed repository. Copy it
to `.git/hooks` and adjust the path to your virtual environment's `bin`
directory to automatically reformat stubs before commit.

Stub files should only contain information necessary for the type
checker, and leave out unnecessary detail:
Expand Down
16 changes: 16 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
#
# An example hook script that will reformat stubs using black and isort
# prior to committing. Adjust BIN_DIR to where your black and isort
# scripts are located.
#
# To enable this hook, copy this file to ".git/hooks".

BIN_DIR=./.venv/bin

CHANGED_FILES=$(git diff --cached --name-only --diff-filter=AM | grep .pyi)

if test -n "${BIN_DIR}"; then
${BIN_DIR}/black ${CHANGED_FILES}
${BIN_DIR}/isort -y ${CHANGED_FILES}
fi
3 changes: 3 additions & 0 deletions stdlib/3/encodings/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This commit serves as a workaround for timothycrosley/isort#1027 and can
srittau marked this conversation as resolved.
Show resolved Hide resolved
# be removed when a release with a fix was released.

import codecs

def search_function(encoding: str) -> codecs.CodecInfo: ...
5 changes: 1 addition & 4 deletions stdlib/3/io.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from typing import (
List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, Tuple, Type, Any, IO, Iterable
)
import builtins
import codecs
from mmap import mmap
from types import TracebackType
from typing import TypeVar
from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, List, Optional, TextIO, Tuple, Type, TypeVar, Union

_bytearray_like = Union[bytearray, mmap]

Expand Down