Skip to content

Commit 6c0caa6

Browse files
committed
refactor: simplify, better static typing
1 parent 4aa2108 commit 6c0caa6

22 files changed

+190
-206
lines changed

.pre-commit-config.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ repos:
3030
- id: requirements-txt-fixer
3131
- id: trailing-whitespace
3232

33+
# Upgrade old Python syntax
3334
- repo: https://github.com/asottile/pyupgrade
3435
rev: v2.31.0
3536
hooks:
3637
- id: pyupgrade
3738
args: [--py3-plus]
3839

40+
# Nicely sort includes
3941
- repo: https://github.com/PyCQA/isort
4042
rev: 5.10.1
4143
hooks:
@@ -47,6 +49,7 @@ repos:
4749
hooks:
4850
- id: black
4951

52+
# Also code format the docs
5053
- repo: https://github.com/asottile/blacken-docs
5154
rev: v1.12.1
5255
hooks:
@@ -66,12 +69,15 @@ repos:
6669
hooks:
6770
- id: pycln
6871

72+
# Checking for common mistakes
6973
- repo: https://github.com/pre-commit/pygrep-hooks
7074
rev: v1.9.0
7175
hooks:
7276
- id: python-check-blanket-noqa
7377
- id: python-check-blanket-type-ignore
7478
- id: python-no-log-warn
79+
# Python 3.6
80+
# - id: python-use-type-annotations
7581
- id: rst-backticks
7682
- id: rst-directive-colons
7783
- id: rst-inline-touching-normal
@@ -86,6 +92,7 @@ repos:
8692
- pep8-naming
8793
exclude: ^(docs/.*|tools/.*)$
8894

95+
# Automatically remove noqa that are not used
8996
- repo: https://github.com/asottile/yesqa
9097
rev: v1.3.0
9198
hooks:
@@ -106,9 +113,9 @@ repos:
106113
rev: v0.931
107114
hooks:
108115
- id: mypy
109-
# Running per-file misbehaves a bit, so just run on all files, it's fast
110-
pass_filenames: false
111-
additional_dependencies: [typed_ast]
116+
args: [--show-error-codes]
117+
exclude: ^(tests|docs)/
118+
additional_dependencies: [nox, rich]
112119

113120
# Checks the manifest for missing files (native support)
114121
- repo: https://github.com/mgedmin/check-manifest
@@ -119,27 +126,30 @@ repos:
119126
stages: [manual]
120127
additional_dependencies: [cmake, ninja]
121128

129+
# Check for spelling
122130
- repo: https://github.com/codespell-project/codespell
123131
rev: v2.1.0
124132
hooks:
125133
- id: codespell
126134
exclude: ".supp$"
127135
args: ["-L", "nd,ot,thist"]
128136

137+
# Check for common shell mistakes
129138
- repo: https://github.com/shellcheck-py/shellcheck-py
130139
rev: v0.8.0.4
131140
hooks:
132141
- id: shellcheck
133142

134-
# The original pybind11 checks for a few C++ style items
143+
# Disallow some common capitalization mistakes
135144
- repo: local
136145
hooks:
137146
- id: disallow-caps
138147
name: Disallow improper capitalization
139148
language: pygrep
140149
entry: PyBind|Numpy|Cmake|CCache|PyTest
141-
exclude: .pre-commit-config.yaml
150+
exclude: ^\.pre-commit-config.yaml$
142151

152+
# The original pybind11 checks for a few C++ style items
143153
- repo: local
144154
hooks:
145155
- id: check-style

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
recursive-include pybind11/include/pybind11 *.h
22
recursive-include pybind11 *.py
33
recursive-include pybind11 py.typed
4-
recursive-include pybind11 *.pyi
54
include pybind11/share/cmake/pybind11/*.cmake
65
include LICENSE README.rst pyproject.toml setup.py setup.cfg

pybind11/__main__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from .commands import get_cmake_dir, get_include
66

77

8-
def print_includes():
9-
# type: () -> None
8+
def print_includes() -> None:
109
dirs = [
1110
sysconfig.get_path("include"),
1211
sysconfig.get_path("platinclude"),
@@ -22,8 +21,7 @@ def print_includes():
2221
print(" ".join("-I" + d for d in unique_dirs))
2322

2423

25-
def main():
26-
# type: () -> None
24+
def main() -> None:
2725

2826
parser = argparse.ArgumentParser()
2927
parser.add_argument(

pybind11/_version.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
def _to_int(s):
1+
from typing import Union
2+
3+
4+
def _to_int(s: str) -> Union[int, str]:
25
try:
36
return int(s)
47
except ValueError:

pybind11/_version.pyi

Lines changed: 0 additions & 6 deletions
This file was deleted.

pybind11/commands.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
DIR = os.path.abspath(os.path.dirname(__file__))
44

55

6-
def get_include(user=False):
7-
# type: (bool) -> str
6+
def get_include(user: bool = False) -> str:
87
installed_path = os.path.join(DIR, "include")
98
source_path = os.path.join(os.path.dirname(DIR), "include")
109
return installed_path if os.path.exists(installed_path) else source_path
1110

1211

13-
def get_cmake_dir():
14-
# type: () -> str
12+
def get_cmake_dir() -> str:
1513
cmake_installed_path = os.path.join(DIR, "share", "cmake", "pybind11")
1614
if os.path.exists(cmake_installed_path):
1715
return cmake_installed_path

0 commit comments

Comments
 (0)