Skip to content

Commit

Permalink
chore: Require error codes on type: ignore pragmas (#190)
Browse files Browse the repository at this point in the history
This PR adds the mypy config introduced into our template in
fulcrumgenomics/python-template#28.

Error codes are now required on any `type: ignore` pragmas. This PR also
adds error codes to any existing `ignore`s without a code.
  • Loading branch information
msto authored Oct 17, 2024
1 parent 9bd0456 commit 8c3c152
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fgpyo/sam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def _pysam_open(
else:
file_type = file_type or SamFileType.from_path(path)
path = str(path)
elif not isinstance(path, _IOClasses): # type: ignore
elif not isinstance(path, _IOClasses): # type: ignore[unreachable]
open_type = "reading" if open_for_reading else "writing"
raise TypeError(f"Cannot open '{type(path)}' for {open_type}.")

Expand Down
4 changes: 2 additions & 2 deletions fgpyo/sam/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,12 @@ def to_path(
file_handle.close()
if self._sort_order == SamOrder.QueryName:
# Ignore type hints for now until we have wrappers to use here.
pysam.sort("-n", *samtools_sort_args) # type: ignore
pysam.sort("-n", *samtools_sort_args) # type: ignore[attr-defined]
elif self._sort_order == SamOrder.Coordinate:
# Ignore type hints for now until we have wrappers to use here.
if index:
samtools_sort_args.insert(0, "--write-index")
pysam.sort(*samtools_sort_args) # type: ignore
pysam.sort(*samtools_sort_args) # type: ignore[attr-defined]

return path

Expand Down
2 changes: 1 addition & 1 deletion fgpyo/vcf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def reader(path: VcfPath) -> Generator[VcfReader, None, None]:
with fgpyo.io.suppress_stderr():
# to avoid spamming log about index older than vcf, redirect stderr to /dev/null: only
# when first opening the file
_reader = VariantFile(path, mode="r") # type: ignore
_reader = VariantFile(path, mode="r") # type: ignore[arg-type]
# now stderr is back, so any later stderr messages will go through
yield _reader
_reader.close()
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true
enable_error_code = "ignore-without-code"
2 changes: 1 addition & 1 deletion tests/fgpyo/sam/test_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_sam_file_open_writing(
path=fp.file,
open_for_reading=False,
file_type=file_type,
**kwargs, # type: ignore
**kwargs, # type: ignore[arg-type]
) as sam_writer:
for r in expected_records:
sam_writer.write(r)
Expand Down
4 changes: 2 additions & 2 deletions tests/fgpyo/util/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ class NonDataClass:
x: int

with pytest.raises(TypeError):
get_fields_dict(NonDataClass) # type: ignore
get_fields_dict(NonDataClass) # type: ignore[arg-type]

with pytest.raises(TypeError):
get_fields(NonDataClass) # type: ignore
get_fields(NonDataClass) # type: ignore[arg-type]

with pytest.raises(TypeError):
attr_from(cls=NonDataClass, kwargs={"x": "1"}, parsers={int: int})
Expand Down

0 comments on commit 8c3c152

Please sign in to comment.