Skip to content

Fix mypy strict equality #1404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions pygit2/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
22 changes: 16 additions & 6 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''))
Expand Down
2 changes: 1 addition & 1 deletion test/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading