Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit61273aa

Browse files
committed
Annotate basic deprecation tests; have mypy scan it
- Add type hints to test/deprecation/basic.py. As its module docstring (already) notes, that test module does not contain code where it is specifically important that it be type checked to verify important properties of the code under test. However, other test.deprecation.* modules will, and it is much more convenient to be able to scan the whole directory than the directory except for one file. (Less importantly, for the deprecation tests to be easily readable as a coherent whole, it makes sense that all, not just most, would have annotations.)- Configure mypy in pyproject.toml so it can be run without arguments (mypy errors when run that way unless configured), where the effect is to scan the git/ directory, as was commonly done before, as well as the test/deprecation/ directory.- Change the CI test workflow, as well as tox.ini, to run mypy with no arguments instead of passing `-p git`, so that it will scan both the git package as it had before and the test.deprecation package (due to the new pyproject.toml configuration).- Change the readme to recommend running it that way, too.
1 parentb8ce990 commit61273aa

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

‎.github/workflows/pythonpackage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888

8989
-name:Check types with mypy
9090
run:|
91-
mypy --python-version=${{ matrix.python-version }} -p git
91+
mypy --python-version=${{ matrix.python-version }}
9292
env:
9393
MYPY_FORCE_COLOR:"1"
9494
TERM:"xterm-256color"# For color: https://github.com/python/mypy/issues/13817

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ This includes the linting and autoformatting done by Ruff, as well as some other
167167
To typecheck, run:
168168

169169
```sh
170-
mypy -p git
170+
mypy
171171
```
172172

173173
####CI (and tox)

‎pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ testpaths = "test" # Space separated list of paths from root e.g test tests doc
2121

2222
[tool.mypy]
2323
python_version ="3.8"
24+
files = ["git/","test/deprecation/"]
2425
disallow_untyped_defs =true
2526
no_implicit_optional =true
2627
warn_redundant_casts =true

‎test/deprecation/test_basic.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,21 @@
2525
fromgit.repoimportRepo
2626
fromgit.utilimportIterableas_Iterable,IterableObj
2727

28+
# typing -----------------------------------------------------------------
29+
30+
fromtypingimportGenerator,TYPE_CHECKING
31+
32+
ifTYPE_CHECKING:
33+
frompathlibimportPath
34+
35+
fromgit.diffimportDiff
36+
fromgit.objects.commitimportCommit
37+
38+
# ------------------------------------------------------------------------
39+
2840

2941
@contextlib.contextmanager
30-
def_assert_no_deprecation_warning():
42+
def_assert_no_deprecation_warning()->Generator[None,None,None]:
3143
"""Context manager to assert that code does not issue any deprecation warnings."""
3244
withwarnings.catch_warnings():
3345
# FIXME: Refine this to filter for deprecation warnings from GitPython.
@@ -36,7 +48,7 @@ def _assert_no_deprecation_warning():
3648

3749

3850
@pytest.fixture
39-
defcommit(tmp_path):
51+
defcommit(tmp_path:"Path")->Generator["Commit",None,None]:
4052
"""Fixture to supply a one-commit repo's commit, enough for deprecation tests."""
4153
(tmp_path/"a.txt").write_text("hello\n",encoding="utf-8")
4254
repo=Repo.init(tmp_path)
@@ -46,75 +58,75 @@ def commit(tmp_path):
4658

4759

4860
@pytest.fixture
49-
defdiff(commit):
61+
defdiff(commit:"Commit")->Generator["Diff",None,None]:
5062
"""Fixture to supply a single-file diff."""
5163
(diff,)=commit.diff(NULL_TREE)# Exactly one file in the diff.
5264
yielddiff
5365

5466

55-
deftest_diff_renamed_warns(diff):
67+
deftest_diff_renamed_warns(diff:"Diff")->None:
5668
"""The deprecated Diff.renamed property issues a deprecation warning."""
5769
withpytest.deprecated_call():
5870
diff.renamed
5971

6072

61-
deftest_diff_renamed_file_does_not_warn(diff):
73+
deftest_diff_renamed_file_does_not_warn(diff:"Diff")->None:
6274
"""The preferred Diff.renamed_file property issues no deprecation warning."""
6375
with_assert_no_deprecation_warning():
6476
diff.renamed_file
6577

6678

67-
deftest_commit_trailers_warns(commit):
79+
deftest_commit_trailers_warns(commit:"Commit")->None:
6880
"""The deprecated Commit.trailers property issues a deprecation warning."""
6981
withpytest.deprecated_call():
7082
commit.trailers
7183

7284

73-
deftest_commit_trailers_list_does_not_warn(commit):
85+
deftest_commit_trailers_list_does_not_warn(commit:"Commit")->None:
7486
"""The nondeprecated Commit.trailers_list property issues no deprecation warning."""
7587
with_assert_no_deprecation_warning():
7688
commit.trailers_list
7789

7890

79-
deftest_commit_trailers_dict_does_not_warn(commit):
91+
deftest_commit_trailers_dict_does_not_warn(commit:"Commit")->None:
8092
"""The nondeprecated Commit.trailers_dict property issues no deprecation warning."""
8193
with_assert_no_deprecation_warning():
8294
commit.trailers_dict
8395

8496

85-
deftest_traverse_list_traverse_in_base_class_warns(commit):
97+
deftest_traverse_list_traverse_in_base_class_warns(commit:"Commit")->None:
8698
"""Traversable.list_traverse's base implementation issues a deprecation warning."""
8799
withpytest.deprecated_call():
88100
Traversable.list_traverse(commit)
89101

90102

91-
deftest_traversable_list_traverse_override_does_not_warn(commit):
103+
deftest_traversable_list_traverse_override_does_not_warn(commit:"Commit")->None:
92104
"""Calling list_traverse on concrete subclasses is not deprecated, does not warn."""
93105
with_assert_no_deprecation_warning():
94106
commit.list_traverse()
95107

96108

97-
deftest_traverse_traverse_in_base_class_warns(commit):
109+
deftest_traverse_traverse_in_base_class_warns(commit:"Commit")->None:
98110
"""Traversable.traverse's base implementation issues a deprecation warning."""
99111
withpytest.deprecated_call():
100112
Traversable.traverse(commit)
101113

102114

103-
deftest_traverse_traverse_override_does_not_warn(commit):
115+
deftest_traverse_traverse_override_does_not_warn(commit:"Commit")->None:
104116
"""Calling traverse on concrete subclasses is not deprecated, does not warn."""
105117
with_assert_no_deprecation_warning():
106118
commit.traverse()
107119

108120

109-
deftest_iterable_inheriting_warns():
121+
deftest_iterable_inheriting_warns()->None:
110122
"""Subclassing the deprecated git.util.Iterable issues a deprecation warning."""
111123
withpytest.deprecated_call():
112124

113125
classDerived(_Iterable):
114126
pass
115127

116128

117-
deftest_iterable_obj_inheriting_does_not_warn():
129+
deftest_iterable_obj_inheriting_does_not_warn()->None:
118130
"""Subclassing git.util.IterableObj is not deprecated, does not warn."""
119131
with_assert_no_deprecation_warning():
120132

‎tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ description = Typecheck with mypy
3030
base_python = py{39,310,311,312,38,37}
3131
set_env =
3232
MYPY_FORCE_COLOR = 1
33-
commands = mypy -p git
33+
commands = mypy
3434
ignore_outcome = true
3535

3636
[testenv:html]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp