From 70b69a8b30569830df00e6c6ffb94e07d3864e20 Mon Sep 17 00:00:00 2001 From: kbaikov Date: Fri, 8 Aug 2025 08:48:37 +0200 Subject: [PATCH] Fix mypy strict equality --- mypy.ini | 2 ++ pygit2/options.py | 12 ++++++------ test/test_blob.py | 10 +++++----- test/test_commit.py | 4 ++-- test/test_config.py | 22 ++++++++++++++++------ test/test_tree.py | 2 +- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/mypy.ini b/mypy.ini index ea5a4ae1..95352700 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,6 +7,8 @@ no_implicit_reexport = True disallow_subclassing_any = True disallow_untyped_decorators = True +strict_equality = True + [mypy-test.*] disallow_untyped_defs = True disallow_untyped_calls = True diff --git a/pygit2/options.py b/pygit2/options.py index ad96253b..f2c1afc2 100644 --- a/pygit2/options.py +++ b/pygit2/options.py @@ -347,7 +347,7 @@ def option(option_type: Option, arg1: Any = NOT_PASSED, arg2: Any = NOT_PASSED) check_error(err) try: - if buf.ptr != ffi.NULL: + if buf.ptr != ffi.NULL: # type: ignore[comparison-overlap] result = to_str(ffi.string(buf.ptr)) else: result = None @@ -475,7 +475,7 @@ def option(option_type: Option, arg1: Any = NOT_PASSED, arg2: Any = NOT_PASSED) check_error(err) try: - if buf.ptr != ffi.NULL: + if buf.ptr != ffi.NULL: # type: ignore[comparison-overlap] result = to_str(ffi.string(buf.ptr)) else: result = None @@ -507,7 +507,7 @@ def option(option_type: Option, arg1: Any = NOT_PASSED, arg2: Any = NOT_PASSED) check_error(err) try: - if buf.ptr != ffi.NULL: + if buf.ptr != ffi.NULL: # type: ignore[comparison-overlap] result = to_str(ffi.string(buf.ptr)) else: result = None @@ -643,7 +643,7 @@ def option(option_type: Option, arg1: Any = NOT_PASSED, arg2: Any = NOT_PASSED) # Cast to the non-NULL type for type checking strings = cast('ArrayC[char_pointer]', strarray.strings) for i in range(strarray.count): - if strings[i] != ffi.NULL: + if strings[i] != ffi.NULL: # type: ignore[comparison-overlap] result.append(to_str(ffi.string(strings[i]))) finally: # Must dispose of the strarray to free the memory @@ -687,7 +687,7 @@ def option(option_type: Option, arg1: Any = NOT_PASSED, arg2: Any = NOT_PASSED) check_error(err) try: - if buf.ptr != ffi.NULL: + if buf.ptr != ffi.NULL: # type: ignore[comparison-overlap] result = to_str(ffi.string(buf.ptr)) else: result = None @@ -767,7 +767,7 @@ def option(option_type: Option, arg1: Any = NOT_PASSED, arg2: Any = NOT_PASSED) check_error(err) try: - if buf.ptr != ffi.NULL: + if buf.ptr != ffi.NULL: # type: ignore[comparison-overlap] result = to_str(ffi.string(buf.ptr)) else: result = None diff --git a/test/test_blob.py b/test/test_blob.py index dcce71f4..cae096b9 100644 --- a/test/test_blob.py +++ b/test/test_blob.py @@ -87,7 +87,7 @@ def test_read_blob(testrepo: Repository) -> None: assert blob.id == BLOB_SHA assert isinstance(blob, pygit2.Blob) assert not blob.is_binary - assert ObjectType.BLOB == blob.type + assert int(ObjectType.BLOB) == blob.type assert BLOB_CONTENT == blob.data assert len(BLOB_CONTENT) == blob.size assert BLOB_CONTENT == blob.read_raw() @@ -98,7 +98,7 @@ def test_create_blob(testrepo: Repository) -> None: blob = testrepo[blob_oid] assert isinstance(blob, pygit2.Blob) - assert ObjectType.BLOB == blob.type + assert int(ObjectType.BLOB) == blob.type assert blob_oid == blob.id assert utils.gen_blob_sha1(BLOB_NEW_CONTENT) == blob_oid @@ -122,7 +122,7 @@ def test_create_blob_fromworkdir(testrepo: Repository) -> None: blob = testrepo[blob_oid] assert isinstance(blob, pygit2.Blob) - assert ObjectType.BLOB == blob.type + assert int(ObjectType.BLOB) == blob.type assert blob_oid == blob.id assert utils.gen_blob_sha1(BLOB_FILE_CONTENT) == blob_oid @@ -149,7 +149,7 @@ def test_create_blob_fromdisk(testrepo: Repository) -> None: blob = testrepo[blob_oid] assert isinstance(blob, pygit2.Blob) - assert ObjectType.BLOB == blob.type + assert int(ObjectType.BLOB) == blob.type def test_create_blob_fromiobase(testrepo: Repository) -> None: @@ -161,7 +161,7 @@ def test_create_blob_fromiobase(testrepo: Repository) -> None: blob = testrepo[blob_oid] assert isinstance(blob, pygit2.Blob) - assert ObjectType.BLOB == blob.type + assert int(ObjectType.BLOB) == blob.type assert blob_oid == blob.id assert BLOB_SHA == blob_oid diff --git a/test/test_commit.py b/test/test_commit.py index 21434026..7a4677a4 100644 --- a/test/test_commit.py +++ b/test/test_commit.py @@ -278,7 +278,7 @@ def test_amend_commit_argument_types(barerepo: Repository) -> None: # Pass an Oid for the commit amended_oid = repo.amend_commit(alt_commit1, None, message='Hello') amended_commit = repo[amended_oid] - assert ObjectType.COMMIT == amended_commit.type + assert int(ObjectType.COMMIT) == amended_commit.type assert amended_oid != COMMIT_SHA_TO_AMEND # Pass a str for the commit @@ -294,6 +294,6 @@ def test_amend_commit_argument_types(barerepo: Repository) -> None: # (Warning: the tip of the branch will be altered after this test!) amended_oid = repo.amend_commit(alt_commit2, alt_refname, message='Hello') amended_commit = repo[amended_oid] - assert ObjectType.COMMIT == amended_commit.type + assert int(ObjectType.COMMIT) == amended_commit.type assert amended_oid != COMMIT_SHA_TO_AMEND assert repo.head.target == amended_oid diff --git a/test/test_config.py b/test/test_config.py index 247d55c5..abe1cbe9 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -156,20 +156,30 @@ def test_multivar() -> None: config.add_file(CONFIG_FILENAME, 6) assert 'this.that' in config - assert ['foobar', 'foobeer'] == list(config.get_multivar('this.that')) - assert ['foobar'] == list(config.get_multivar('this.that', 'bar')) - assert ['foobar', 'foobeer'] == list(config.get_multivar('this.that', 'foo.*')) + assert ['foobar', 'foobeer'] == list( + str(config_entry) for config_entry in config.get_multivar('this.that') + ) + assert ['foobar'] == list( + str(config_entry) for config_entry in config.get_multivar('this.that', 'bar') + ) + assert ['foobar', 'foobeer'] == list( + str(config_entry) for config_entry in config.get_multivar('this.that', 'foo.*') + ) config.set_multivar('this.that', '^.*beer', 'fool') - assert ['fool'] == list(config.get_multivar('this.that', 'fool')) + assert ['fool'] == list( + str(config_entry) for config_entry in config.get_multivar('this.that', 'fool') + ) config.set_multivar('this.that', 'foo.*', 'foo-123456') assert ['foo-123456', 'foo-123456'] == list( - config.get_multivar('this.that', 'foo.*') + str(config_entry) for config_entry in config.get_multivar('this.that', 'foo.*') ) config.delete_multivar('this.that', 'bar') - assert ['foo-123456', 'foo-123456'] == list(config.get_multivar('this.that', '')) + assert ['foo-123456', 'foo-123456'] == list( + str(config_entry) for config_entry in config.get_multivar('this.that', '') + ) config.delete_multivar('this.that', 'foo-[0-9]+') assert [] == list(config.get_multivar('this.that', '')) diff --git a/test/test_tree.py b/test/test_tree.py index 556c3751..d567f6d4 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -99,7 +99,7 @@ def test_sorting(barerepo: Repository) -> None: tree_a = barerepo['18e2d2e9db075f9eb43bcb2daa65a2867d29a15e'] assert isinstance(tree_a, Tree) assert list(tree_a) == sorted(reversed(list(tree_a)), key=pygit2.tree_entry_key) - assert list(tree_a) != reversed(list(tree_a)) + assert list(tree_a) != list(reversed(list(tree_a))) def test_read_subtree(barerepo: Repository) -> None: