Skip to content

Commit

Permalink
Finish Strict Typing (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Oct 28, 2023
1 parent 3a03835 commit 4f0e68b
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 413 deletions.
16 changes: 6 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-ast
Expand Down Expand Up @@ -33,7 +33,7 @@ repos:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.2"
rev: "v3.0.3"
hooks:
- id: prettier
types_or: [yaml, html, json]
Expand All @@ -44,13 +44,8 @@ repos:
- id: blacken-docs
additional_dependencies: [black==23.7.0]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.5"
rev: "v2.2.6"
hooks:
- id: codespell
args: ["-L", "sur,nd"]
Expand All @@ -63,13 +58,14 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/scientific-python/cookie
rev: "2023.08.23"
rev: "2023.10.27"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ complete rewrite, so if you have an application that does use the
parsing logic of traitlets you may see changes in behavior, and now have
access to more features. There was also a cleanup of what was considered
a part of the public API, certain previously exposed utility functions
and types are no longer available. Please see an exhausive list below.
and types are no longer available. Please see an exhaustive list below.

::: seealso
`commandline` docs for details about
Expand Down Expand Up @@ -521,7 +521,7 @@ description.
### API changes

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

```
The following items are new:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}
html_theme_options = {"navigation_with_keys": False}

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


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


def setup(app):
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/configs/base_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Example config used by load_config_app.py

c = get_config() # noqa
c.MyClass.name = 'Harvard'
c.MyClass.name = "Harvard"
c.MyClass.ranking = 100
4 changes: 2 additions & 2 deletions examples/docs/configs/main_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
c = get_config() # noqa

# Load everything from base_config.py
load_subconfig('base_config.py') # noqa
load_subconfig("base_config.py") # noqa

# Now override one of the values
c.School.name = 'Caltech'
c.School.name = "Caltech"
38 changes: 10 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,28 @@ features = ["test"]
test = "mypy --install-types --non-interactive {args}"

[tool.hatch.envs.lint]
dependencies = ["black==23.3.0", "mdformat>0.7", "ruff==0.1.1"]
dependencies = ["mdformat>0.7", "ruff==0.1.3"]
detached = true
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
"ruff format {args:.}",
"mdformat --check {args:docs *.md}"
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"ruff format {args:.}",
"mdformat {args:docs *.md}"
]

[tool.mypy]
files = "traitlets"
python_version = "3.8"
strict = false
check_untyped_defs = true
disallow_any_generics = false
disable_error_code = ["no-untyped-call"]
strict = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
no_implicit_reexport = false
pretty = true
show_error_context = true
show_error_codes = true
warn_return_any = false
warn_unreachable = true
exclude = ["examples/docs/configs", "traitlets/tests/test_typing.py"]

Expand Down Expand Up @@ -162,27 +157,16 @@ exclude_lines = [
relative_files = true
source = ["traitlets"]

[tool.black]
line-length = 100
skip-string-normalization = true
target-version = ["py37"]

[tool.ruff]
target-version = "py37"
target-version = "py38"
line-length = 100

[tool.ruff.lint]
select = [
"A", "ANN", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
"A", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
"UP", "W", "YTT",
]
ignore = [
# Dynamically typed expressions (typing.Any) are disallowed in `key`
"ANN401",
# Missing type annotation for `self` in method
"ANN101",
# Missing type annotation for `cls` in classmethod
"ANN102",
# ANN202 Missing return type annotation for private function
"ANN202",
# Allow non-abstract empty methods in abstract base classes
"B027",
# Ignore McCabe complexity
Expand Down Expand Up @@ -231,7 +215,7 @@ unfixable = [
"RUF100",
]

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

[tool.repo-review]
ignore = ["PY007", "PP308", "GH102", "PC140", "MY101"]
2 changes: 1 addition & 1 deletion tests/config/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_basic(self):
self.assertEqual(app.config_file, "")

def test_app_name_set_via_constructor(self):
app = MyApp(name='set_via_constructor')
app = MyApp(name="set_via_constructor")
assert app.name == "set_via_constructor"

def test_mro_discovery(self):
Expand Down
32 changes: 16 additions & 16 deletions tests/config/test_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,21 @@ def run_completer(
def test_complete_simple_app(self, argcomplete_on):
app = ArgcompleteApp()
expected = [
'--help',
'--debug',
'--show-config',
'--show-config-json',
'--log-level',
'--Application.',
'--ArgcompleteApp.',
"--help",
"--debug",
"--show-config",
"--show-config-json",
"--log-level",
"--Application.",
"--ArgcompleteApp.",
]
assert set(self.run_completer(app, "app --")) == set(expected)

# completing class traits
assert set(self.run_completer(app, "app --App")) > {
'--Application.show_config',
'--Application.log_level',
'--Application.log_format',
"--Application.show_config",
"--Application.log_level",
"--Application.log_format",
}

def test_complete_custom_completers(self, argcomplete_on):
Expand Down Expand Up @@ -195,9 +195,9 @@ def test_complete_subcommands_subapp1(self, argcomplete_on):
app = MainApp()
try:
assert set(self.run_completer(app, "app subapp1 --Sub")) > {
'--SubApp1.show_config',
'--SubApp1.log_level',
'--SubApp1.log_format',
"--SubApp1.show_config",
"--SubApp1.log_level",
"--SubApp1.log_format",
}
finally:
SubApp1.clear_instance()
Expand All @@ -206,14 +206,14 @@ def test_complete_subcommands_subapp2(self, argcomplete_on):
app = MainApp()
try:
assert set(self.run_completer(app, "app subapp2 --")) > {
'--Application.',
'--SubApp2.',
"--Application.",
"--SubApp2.",
}
finally:
SubApp2.clear_instance()

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

0 comments on commit 4f0e68b

Please sign in to comment.