Skip to content

Commit

Permalink
AI-inspired improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tovrstra committed Jun 23, 2024
1 parent a354980 commit 8a8c507
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ When you encounter a file format error while reading the file, raise a ``LoadErr
def load_one(lit: LineIterator) -> dict:
...
if something_wrong:
raise LoadError("Describe the problem in a sentence.", lit)
raise LoadError("Describe the problem that made it impossible to load the file.", lit)
The error that appears in the terminal will automatically include the file name and line number.
If your code has already read the full file and encounters an error when processing the data,
Expand All @@ -183,7 +183,7 @@ In this case, you should warn the user that the file contains (fixable) errors:
def load_one(lit: LineIterator) -> dict:
...
if something_fixed:
warn(LoadWarning("Describe the problem in a sentence.", lit), stacklevel=2)
warn(LoadWarning("Describe the issue that was fixed while loading.", lit), stacklevel=2)
Always use ``stacklevel=2`` when raising warnings.

Expand Down
2 changes: 1 addition & 1 deletion iodata/test/test_iodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_typecheck_raises():


def test_unknown_format():
with pytest.raises(FileFormatError):
with pytest.raises(FileFormatError, match="Cannot find file format with feature"):
load_one("foo.unknown_file_extension")


Expand Down
2 changes: 1 addition & 1 deletion iodata/test/test_mol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_load_dump_wrong_bond_num(tmpdir):
def test_load_water_bonds_warning():
with (
as_file(files("iodata.test.data").joinpath("water.mol2")) as fn_mol,
pytest.warns(LoadWarning),
pytest.warns(LoadWarning, match="Cannot interpret bond type"),
):
mol = load_one(fn_mol)
assert_equal(mol.bonds, [[0, 1, bond2num["un"]], [0, 2, bond2num["un"]]])
4 changes: 2 additions & 2 deletions iodata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ def __init__(
file: Optional[Union[str, Path, LineIterator, TextIO]] = None,
lineno: Optional[int] = None,
):
self.filename, self.lineno = _interpret_file_lineno(file, lineno)
super().__init__(_format_file_message(message, self.filename, self.lineno))
filename, lineno = _interpret_file_lineno(file, lineno)
super().__init__(_format_file_message(message, filename, lineno))


class LoadWarning(BaseFileWarning):
Expand Down

0 comments on commit 8a8c507

Please sign in to comment.