diff --git a/src/rapids_pre_commit_hooks/alpha_spec.py b/src/rapids_pre_commit_hooks/alpha_spec.py index ae4fe2a..c48d474 100644 --- a/src/rapids_pre_commit_hooks/alpha_spec.py +++ b/src/rapids_pre_commit_hooks/alpha_spec.py @@ -275,7 +275,7 @@ def compose_document(self) -> yaml.Node: self.get_event() # Compose the root node. - node = self.compose_node(None, None) # type: ignore + node = self.compose_node(None, None) # type: ignore[arg-type] # Drop the DOCUMENT-END event. self.get_event() diff --git a/src/rapids_pre_commit_hooks/pyproject_license.py b/src/rapids_pre_commit_hooks/pyproject_license.py index d8622cf..602816a 100644 --- a/src/rapids_pre_commit_hooks/pyproject_license.py +++ b/src/rapids_pre_commit_hooks/pyproject_license.py @@ -44,7 +44,7 @@ def find_value_location( # look for that in the new document. node = copied_document while len(key) > (0 if append else 1): - node = node[key[0]] # type: ignore + node = node[key[0]] # type: ignore[assignment] key = key[1:] if append: node.add(str(placeholder), placeholder_toml) @@ -65,8 +65,8 @@ def check_pyproject_license(linter: Linter, args: argparse.Namespace) -> None: try: add_project_table = True project_table = document["project"] - add_project_table = project_table.is_super_table() # type: ignore - license_value = project_table["license"]["text"] # type: ignore + add_project_table = project_table.is_super_table() # type: ignore[union-attr] + license_value = project_table["license"]["text"] # type: ignore[index] except tomlkit.exceptions.NonExistentKey: if add_project_table: loc = (len(linter.content), len(linter.content)) diff --git a/test/rapids_pre_commit_hooks/test_copyright.py b/test/rapids_pre_commit_hooks/test_copyright.py index be095b0..ea920f1 100644 --- a/test/rapids_pre_commit_hooks/test_copyright.py +++ b/test/rapids_pre_commit_hooks/test_copyright.py @@ -318,7 +318,7 @@ def mock_target_branch(branch: Any): remote_1_branch_1 = remote_repo_1.create_head( "branch-1-renamed", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_1 # type: ignore + remote_repo_1.head.reference = remote_1_branch_1 # type: ignore[misc] remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file1.txt", "File 1 modified") remote_repo_1.index.add(["file1.txt"]) @@ -330,7 +330,7 @@ def mock_target_branch(branch: Any): remote_1_branch_2 = remote_repo_1.create_head( "branch-2", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_2 # type: ignore + remote_repo_1.head.reference = remote_1_branch_2 # type: ignore[misc] remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file2.txt", "File 2 modified") remote_repo_1.index.add(["file2.txt"]) @@ -339,7 +339,7 @@ def mock_target_branch(branch: Any): remote_1_branch_3 = remote_repo_1.create_head( "branch-3", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_3 # type: ignore + remote_repo_1.head.reference = remote_1_branch_3 # type: ignore[misc] remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file3.txt", "File 3 modified") remote_repo_1.index.add(["file3.txt"]) @@ -351,7 +351,7 @@ def mock_target_branch(branch: Any): remote_1_branch_4 = remote_repo_1.create_head( "branch-4", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_4 # type: ignore + remote_repo_1.head.reference = remote_1_branch_4 # type: ignore[misc] remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file4.txt", "File 4 modified") remote_repo_1.index.add(["file4.txt"]) @@ -363,7 +363,7 @@ def mock_target_branch(branch: Any): remote_1_branch_7 = remote_repo_1.create_head( "branch-7", remote_1_master.commit ) - remote_repo_1.head.reference = remote_1_branch_7 # type: ignore + remote_repo_1.head.reference = remote_1_branch_7 # type: ignore[misc] remote_repo_1.head.reset(index=True, working_tree=True) write_file(remote_repo_1, "file7.txt", "File 7 modified") remote_repo_1.index.add(["file7.txt"]) @@ -379,7 +379,7 @@ def mock_target_branch(branch: Any): remote_2_branch_3 = remote_repo_2.create_head( "branch-3", remote_2_master.commit ) - remote_repo_2.head.reference = remote_2_branch_3 # type: ignore + remote_repo_2.head.reference = remote_2_branch_3 # type: ignore[misc] remote_repo_2.head.reset(index=True, working_tree=True) write_file(remote_repo_2, "file3.txt", "File 3 modified") remote_repo_2.index.add(["file3.txt"]) @@ -391,7 +391,7 @@ def mock_target_branch(branch: Any): remote_2_branch_4 = remote_repo_2.create_head( "branch-4", remote_2_master.commit ) - remote_repo_2.head.reference = remote_2_branch_4 # type: ignore + remote_repo_2.head.reference = remote_2_branch_4 # type: ignore[misc] remote_repo_2.head.reset(index=True, working_tree=True) write_file(remote_repo_2, "file4.txt", "File 4 modified") remote_repo_2.index.add(["file4.txt"]) @@ -403,7 +403,7 @@ def mock_target_branch(branch: Any): remote_2_branch_5 = remote_repo_2.create_head( "branch-5", remote_2_master.commit ) - remote_repo_2.head.reference = remote_2_branch_5 # type: ignore + remote_repo_2.head.reference = remote_2_branch_5 # type: ignore[misc] remote_repo_2.head.reset(index=True, working_tree=True) write_file(remote_repo_2, "file5.txt", "File 5 modified") remote_repo_2.index.add(["file5.txt"]) @@ -433,7 +433,7 @@ def mock_target_branch(branch: Any): with branch_1.config_writer() as w: w.set_value("remote", "unconventional/remote/name/1") w.set_value("merge", "branch-1-renamed") - git_repo.head.reference = branch_1 # type: ignore + git_repo.head.reference = branch_1 # type: ignore[misc] git_repo.head.reset(index=True, working_tree=True) git_repo.index.remove("file1.txt", working_tree=True) git_repo.index.commit( @@ -442,7 +442,7 @@ def mock_target_branch(branch: Any): ) branch_6 = git_repo.create_head("branch-6", remote_1.refs["master"]) - git_repo.head.reference = branch_6 # type: ignore + git_repo.head.reference = branch_6 # type: ignore[misc] git_repo.head.reset(index=True, working_tree=True) git_repo.index.remove(["file6.txt"], working_tree=True) git_repo.index.commit("Remove file6.txt") @@ -451,7 +451,7 @@ def mock_target_branch(branch: Any): with branch_7.config_writer() as w: w.set_value("remote", "unconventional/remote/name/1") w.set_value("merge", "branch-7") - git_repo.head.reference = branch_7 # type: ignore + git_repo.head.reference = branch_7 # type: ignore[misc] git_repo.head.reset(index=True, working_tree=True) git_repo.index.remove(["file7.txt"], working_tree=True) git_repo.index.commit( @@ -459,7 +459,7 @@ def mock_target_branch(branch: Any): commit_date=datetime.datetime(2024, 2, 1, tzinfo=datetime.timezone.utc), ) - git_repo.head.reference = main # type: ignore + git_repo.head.reference = main # type: ignore[misc] git_repo.head.reset(index=True, working_tree=True) with mock_target_branch("branch-1"): @@ -614,7 +614,7 @@ def file_contents(verbed: str) -> str: git_repo.index.commit("Remove modified.txt") pr_branch = git_repo.create_head("pr", "HEAD~") - git_repo.head.reference = pr_branch # type: ignore + git_repo.head.reference = pr_branch # type: ignore[misc] git_repo.head.reset(index=True, working_tree=True) write_file("copied_2.txt", file_contents("copied")) @@ -662,7 +662,7 @@ def file_contents(verbed: str) -> str: target_branch = git_repo.heads["master"] merge_base = git_repo.merge_base(target_branch, "HEAD")[0] old_files = { - blob.path: blob # type: ignore + blob.path: blob # type: ignore[union-attr] for blob in merge_base.tree.traverse(lambda b, _: isinstance(b, git.Blob)) } @@ -698,17 +698,23 @@ def file_contents(verbed: str) -> str: if old: with open(fn(new), "rb") as f: new_contents = f.read() - old_contents = old_files[old].data_stream.read() # type: ignore + old_contents = old_files[old].data_stream.read() # type: ignore[union-attr] assert new_contents != old_contents - assert changed_files[new].data_stream.read() == old_contents # type: ignore + assert ( + changed_files[new].data_stream.read() # type: ignore[union-attr] + == old_contents + ) for new, old in superfluous.items(): if old: with open(fn(new), "rb") as f: new_contents = f.read() - old_contents = old_files[old].data_stream.read() # type: ignore + old_contents = old_files[old].data_stream.read() # type: ignore[union-attr] assert new_contents == old_contents - assert changed_files[new].data_stream.read() == old_contents # type: ignore + assert ( + changed_files[new].data_stream.read() # type: ignore[union-attr] + == old_contents + ) def test_get_changed_files_multiple_merge_bases(git_repo: git.Repo) -> None: @@ -727,7 +733,7 @@ def write_file(filename: str, contents: str): git_repo.index.commit("Initial commit") branch_1 = git_repo.create_head("branch-1", "master") - git_repo.head.reference = branch_1 # type: ignore + git_repo.head.reference = branch_1 # type: ignore[misc] git_repo.index.reset(index=True, working_tree=True) write_file("file1.txt", "File 1 modified\n") git_repo.index.add("file1.txt") @@ -737,7 +743,7 @@ def write_file(filename: str, contents: str): ) branch_2 = git_repo.create_head("branch-2", "master") - git_repo.head.reference = branch_2 # type: ignore + git_repo.head.reference = branch_2 # type: ignore[misc] git_repo.index.reset(index=True, working_tree=True) write_file("file2.txt", "File 2 modified\n") git_repo.index.add("file2.txt") @@ -747,7 +753,7 @@ def write_file(filename: str, contents: str): ) branch_1_2 = git_repo.create_head("branch-1-2", "master") - git_repo.head.reference = branch_1_2 # type: ignore + git_repo.head.reference = branch_1_2 # type: ignore[misc] git_repo.index.reset(index=True, working_tree=True) write_file("file1.txt", "File 1 modified\n") write_file("file2.txt", "File 2 modified\n") @@ -759,7 +765,7 @@ def write_file(filename: str, contents: str): ) branch_3 = git_repo.create_head("branch-3", "master") - git_repo.head.reference = branch_3 # type: ignore + git_repo.head.reference = branch_3 # type: ignore[misc] git_repo.index.reset(index=True, working_tree=True) write_file("file1.txt", "File 1 modified\n") write_file("file2.txt", "File 2 modified\n") @@ -873,21 +879,21 @@ def file_contents_modified(num: int) -> str: git_repo.index.commit("Initial commit") branch_1 = git_repo.create_head("branch-1", "master") - git_repo.head.reference = branch_1 # type: ignore + git_repo.head.reference = branch_1 # type: ignore[misc] git_repo.head.reset(index=True, working_tree=True) write_file("file1.txt", file_contents_modified(1)) git_repo.index.add(["file1.txt"]) git_repo.index.commit("Update file1.txt") branch_2 = git_repo.create_head("branch-2", "master") - git_repo.head.reference = branch_2 # type: ignore + git_repo.head.reference = branch_2 # type: ignore[misc] git_repo.head.reset(index=True, working_tree=True) write_file("file2.txt", file_contents_modified(2)) git_repo.index.add(["file2.txt"]) git_repo.index.commit("Update file2.txt") pr = git_repo.create_head("pr", "branch-1") - git_repo.head.reference = pr # type: ignore + git_repo.head.reference = pr # type: ignore[misc] git_repo.head.reset(index=True, working_tree=True) write_file("file3.txt", file_contents_modified(3)) git_repo.index.add(["file3.txt"]) diff --git a/test/test_pre_commit.py b/test/test_pre_commit.py index 2fa450f..f58dddc 100644 --- a/test/test_pre_commit.py +++ b/test/test_pre_commit.py @@ -86,7 +86,7 @@ def list_files(top: str) -> Generator[str, None, None]: branch_dir = os.path.join(example_dir, "branch") if os.path.exists(branch_dir): - git_repo.head.reference = git_repo.create_head( # type: ignore + git_repo.head.reference = git_repo.create_head( # type: ignore[misc] "branch", git_repo.head.commit ) git_repo.index.remove(list(list_files(master_dir)), working_tree=True)