Skip to content

Commit 4f0e68b

Browse files
authored
Finish Strict Typing (#885)
1 parent 3a03835 commit 4f0e68b

File tree

15 files changed

+434
-413
lines changed

15 files changed

+434
-413
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ci:
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.4.0
7+
rev: v4.5.0
88
hooks:
99
- id: check-case-conflict
1010
- id: check-ast
@@ -33,7 +33,7 @@ repos:
3333
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]
3434

3535
- repo: https://github.com/pre-commit/mirrors-prettier
36-
rev: "v3.0.2"
36+
rev: "v3.0.3"
3737
hooks:
3838
- id: prettier
3939
types_or: [yaml, html, json]
@@ -44,13 +44,8 @@ repos:
4444
- id: blacken-docs
4545
additional_dependencies: [black==23.7.0]
4646

47-
- repo: https://github.com/psf/black-pre-commit-mirror
48-
rev: 23.9.1
49-
hooks:
50-
- id: black
51-
5247
- repo: https://github.com/codespell-project/codespell
53-
rev: "v2.2.5"
48+
rev: "v2.2.6"
5449
hooks:
5550
- id: codespell
5651
args: ["-L", "sur,nd"]
@@ -63,13 +58,14 @@ repos:
6358
- id: rst-inline-touching-normal
6459

6560
- repo: https://github.com/astral-sh/ruff-pre-commit
66-
rev: v0.1.1
61+
rev: v0.1.3
6762
hooks:
6863
- id: ruff
6964
args: ["--fix", "--show-fixes"]
65+
- id: ruff-format
7066

7167
- repo: https://github.com/scientific-python/cookie
72-
rev: "2023.08.23"
68+
rev: "2023.10.27"
7369
hooks:
7470
- id: sp-repo-review
7571
additional_dependencies: ["repo-review[cli]"]

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ complete rewrite, so if you have an application that does use the
358358
parsing logic of traitlets you may see changes in behavior, and now have
359359
access to more features. There was also a cleanup of what was considered
360360
a part of the public API, certain previously exposed utility functions
361-
and types are no longer available. Please see an exhausive list below.
361+
and types are no longer available. Please see an exhaustive list below.
362362

363363
::: seealso
364364
`commandline` docs for details about
@@ -521,7 +521,7 @@ description.
521521
### API changes
522522

523523
This list is auto-generated by `frappuccino`, comparing with traitlets
524-
4.3.3 API and editied for shortness:
524+
4.3.3 API and edited for shortness:
525525

526526
```
527527
The following items are new:

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
# Theme options are theme-specific and customize the look and feel of a theme
144144
# further. For a list of options available for each theme, see the
145145
# documentation.
146-
# html_theme_options = {}
146+
html_theme_options = {"navigation_with_keys": False}
147147

148148
# Add any paths that contain custom themes here, relative to this directory.
149149
# html_theme_path = []
@@ -311,7 +311,7 @@
311311

312312

313313
# Example configuration for intersphinx: refer to the Python standard library.
314-
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
314+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
315315

316316

317317
def setup(app):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Example config used by load_config_app.py
22

33
c = get_config() # noqa
4-
c.MyClass.name = 'Harvard'
4+
c.MyClass.name = "Harvard"
55
c.MyClass.ranking = 100

examples/docs/configs/main_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
c = get_config() # noqa
44

55
# Load everything from base_config.py
6-
load_subconfig('base_config.py') # noqa
6+
load_subconfig("base_config.py") # noqa
77

88
# Now override one of the values
9-
c.School.name = 'Caltech'
9+
c.School.name = "Caltech"

pyproject.toml

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,28 @@ features = ["test"]
7575
test = "mypy --install-types --non-interactive {args}"
7676

7777
[tool.hatch.envs.lint]
78-
dependencies = ["black==23.3.0", "mdformat>0.7", "ruff==0.1.1"]
78+
dependencies = ["mdformat>0.7", "ruff==0.1.3"]
7979
detached = true
8080
[tool.hatch.envs.lint.scripts]
8181
style = [
8282
"ruff {args:.}",
83-
"black --check --diff {args:.}",
83+
"ruff format {args:.}",
8484
"mdformat --check {args:docs *.md}"
8585
]
8686
fmt = [
87-
"black {args:.}",
8887
"ruff --fix {args:.}",
88+
"ruff format {args:.}",
8989
"mdformat {args:docs *.md}"
9090
]
9191

9292
[tool.mypy]
9393
files = "traitlets"
9494
python_version = "3.8"
95-
strict = false
96-
check_untyped_defs = true
97-
disallow_any_generics = false
98-
disable_error_code = ["no-untyped-call"]
95+
strict = true
9996
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
100-
no_implicit_reexport = false
10197
pretty = true
10298
show_error_context = true
10399
show_error_codes = true
104-
warn_return_any = false
105100
warn_unreachable = true
106101
exclude = ["examples/docs/configs", "traitlets/tests/test_typing.py"]
107102

@@ -162,27 +157,16 @@ exclude_lines = [
162157
relative_files = true
163158
source = ["traitlets"]
164159

165-
[tool.black]
166-
line-length = 100
167-
skip-string-normalization = true
168-
target-version = ["py37"]
169-
170160
[tool.ruff]
171-
target-version = "py37"
161+
target-version = "py38"
172162
line-length = 100
163+
164+
[tool.ruff.lint]
173165
select = [
174-
"A", "ANN", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
166+
"A", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
175167
"UP", "W", "YTT",
176168
]
177169
ignore = [
178-
# Dynamically typed expressions (typing.Any) are disallowed in `key`
179-
"ANN401",
180-
# Missing type annotation for `self` in method
181-
"ANN101",
182-
# Missing type annotation for `cls` in classmethod
183-
"ANN102",
184-
# ANN202 Missing return type annotation for private function
185-
"ANN202",
186170
# Allow non-abstract empty methods in abstract base classes
187171
"B027",
188172
# Ignore McCabe complexity
@@ -231,7 +215,7 @@ unfixable = [
231215
"RUF100",
232216
]
233217

234-
[tool.ruff.per-file-ignores]
218+
[tool.ruff.lint.per-file-ignores]
235219
# B011 Do not call assert False since python -O removes these calls
236220
# F841 local variable 'foo' is assigned to but never used
237221
# C408 Unnecessary `dict` call
@@ -242,15 +226,13 @@ unfixable = [
242226
# F841 Local variable `t` is assigned to but never used
243227
# B018 Found useless expression
244228
# S301 `pickle` and modules that wrap..."
245-
"tests/*" = ["ANN", "B011", "F841", "C408", "E402", "T201", "B007", "N802", "F841",
229+
"tests/*" = ["B011", "F841", "C408", "E402", "T201", "B007", "N802", "F841",
246230
"B018", "S301"]
247231
# B003 Assigning to os.environ doesn't clear the environment
248232
"tests/config/*" = ["B003", "B018", "S301"]
249233
# F401 `_version.__version__` imported but unused
250234
# F403 `from .traitlets import *` used; unable to detect undefined names
251235
"traitlets/*__init__.py" = ["F401", "F403"]
252-
"docs/*" = ["ANN"]
253-
"examples/*" = ["ANN"]
254236

255237
[tool.repo-review]
256238
ignore = ["PY007", "PP308", "GH102", "PC140", "MY101"]

tests/config/test_application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_basic(self):
130130
self.assertEqual(app.config_file, "")
131131

132132
def test_app_name_set_via_constructor(self):
133-
app = MyApp(name='set_via_constructor')
133+
app = MyApp(name="set_via_constructor")
134134
assert app.name == "set_via_constructor"
135135

136136
def test_mro_discovery(self):

tests/config/test_argcomplete.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,21 @@ def run_completer(
133133
def test_complete_simple_app(self, argcomplete_on):
134134
app = ArgcompleteApp()
135135
expected = [
136-
'--help',
137-
'--debug',
138-
'--show-config',
139-
'--show-config-json',
140-
'--log-level',
141-
'--Application.',
142-
'--ArgcompleteApp.',
136+
"--help",
137+
"--debug",
138+
"--show-config",
139+
"--show-config-json",
140+
"--log-level",
141+
"--Application.",
142+
"--ArgcompleteApp.",
143143
]
144144
assert set(self.run_completer(app, "app --")) == set(expected)
145145

146146
# completing class traits
147147
assert set(self.run_completer(app, "app --App")) > {
148-
'--Application.show_config',
149-
'--Application.log_level',
150-
'--Application.log_format',
148+
"--Application.show_config",
149+
"--Application.log_level",
150+
"--Application.log_format",
151151
}
152152

153153
def test_complete_custom_completers(self, argcomplete_on):
@@ -195,9 +195,9 @@ def test_complete_subcommands_subapp1(self, argcomplete_on):
195195
app = MainApp()
196196
try:
197197
assert set(self.run_completer(app, "app subapp1 --Sub")) > {
198-
'--SubApp1.show_config',
199-
'--SubApp1.log_level',
200-
'--SubApp1.log_format',
198+
"--SubApp1.show_config",
199+
"--SubApp1.log_level",
200+
"--SubApp1.log_format",
201201
}
202202
finally:
203203
SubApp1.clear_instance()
@@ -206,14 +206,14 @@ def test_complete_subcommands_subapp2(self, argcomplete_on):
206206
app = MainApp()
207207
try:
208208
assert set(self.run_completer(app, "app subapp2 --")) > {
209-
'--Application.',
210-
'--SubApp2.',
209+
"--Application.",
210+
"--SubApp2.",
211211
}
212212
finally:
213213
SubApp2.clear_instance()
214214

215215
def test_complete_subcommands_main(self, argcomplete_on):
216216
app = MainApp()
217217
completions = set(self.run_completer(app, "app --"))
218-
assert completions > {'--Application.', '--MainApp.'}
218+
assert completions > {"--Application.", "--MainApp."}
219219
assert "--SubApp1." not in completions and "--SubApp2." not in completions

0 commit comments

Comments
 (0)