Skip to content

Commit 509ed22

Browse files
authored
Add types to file generated by __test__.py (#428)
I am adding types to user_args otherwise mypy complains when running `bazel test`. I am trying to automatically run `mypy` when building my bazel targets. I am using [rules_mypy](https://github.com/theoremlp/rules_mypy) for this. I am also using the `py_pytest_main` rule: ```python py_pytest_main( name = "__test__", deps = ["@pip//pytest"], ) py_test( name = "mytest", size = "small", srcs = [ "mytest.py", ":__test__", ], main = ":__test__.py", package_collisions = "warning", deps = [ ":__test__", ":mylib", ], ) ``` However, if I run `bazel test mytest`, mypy complains: `bazel-out/k8-fastbuild/bin/src/backend2/__test__.py:42: error: Need type annotation for "user_args" (hint: "user_args: list[<type>] = ...") [var-annotated]`. I haven't found a way to remove the `__test__` file from `mypy` analysis, and this is actually a simple fix, so I thought we could patch this in. --- ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: no - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: yes/no
1 parent b81f63c commit 509ed22

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

py/private/pytest.py.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if __name__ == "__main__":
3939
if test_filter is not None:
4040
args.append(f"-k={test_filter}")
4141

42-
user_args = [$$FLAGS$$]
42+
user_args: list[str] = [$$FLAGS$$]
4343
if len(user_args) > 0:
4444
args.extend(user_args)
4545

0 commit comments

Comments
 (0)