Skip to content
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

🔧 Add additional Ruff lints (and fix issues) #862

Merged
merged 10 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
glob 'bugbear' lints and use exception chaining
  • Loading branch information
daniel.eades committed Jan 26, 2024
commit 8ae301e0eb94cbb05f4f5064927a8a400ceedaa4
10 changes: 5 additions & 5 deletions myst_parser/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,14 @@ def run(self) -> list[nodes.Element]:
# tab_width = self.options.get("tab-width", self.document.settings.tab_width)
try:
file_content = path.read_text(encoding=encoding, errors=error_handler)
except FileNotFoundError:
except FileNotFoundError as error:
raise DirectiveError(
4, f'Directive "{self.name}": file not found: {str(path)!r}'
)
) from error
except Exception as error:
raise DirectiveError(
4, f'Directive "{self.name}": error reading file: {path}\n{error}.'
)
) from error

# get required section of text
startline = self.options.get("start-line", None)
Expand Down Expand Up @@ -412,10 +412,10 @@ def run(self) -> list[nodes.Element]:
if "number-lines" in self.options:
try:
startline = int(self.options["number-lines"] or 1)
except ValueError:
except ValueError as err:
raise DirectiveError(
3, ":number-lines: with non-integer start value"
)
) from err
endline = startline + len(file_content.splitlines())
if file_content.endswith("\n"):
file_content = file_content[:-1]
Expand Down
8 changes: 4 additions & 4 deletions myst_parser/parsers/docutils_.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def _validate_yaml(
"""
try:
output = yaml.safe_load(value)
except Exception:
raise ValueError("Invalid YAML string")
except Exception as err:
raise ValueError("Invalid YAML string") from err
if not isinstance(output, dict):
raise ValueError("Expecting a YAML dictionary")
return output
Expand All @@ -115,8 +115,8 @@ def _validate_url_schemes(
"""
try:
output = yaml.safe_load(value)
except Exception:
raise ValueError("Invalid YAML string")
except Exception as err:
raise ValueError("Invalid YAML string") from err
if isinstance(output, str):
output = {k: None for k in output.split(",")}
if not isinstance(output, dict):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ exclude = [
]

[tool.ruff]
extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "UP"]
extend-select = ["B", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "UP"]
extend-ignore = ["ISC001", "RUF005", "RUF012"]

[tool.mypy]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_renderers/test_fixtures_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ def settings_from_cmdline(cmdline: str | None) -> dict[str, Any]:
try:
pub.process_command_line(shlex.split(cmdline))
except Exception as err:
raise AssertionError(f"Failed to parse commandline: {cmdline}\n{err}")
raise AssertionError(f"Failed to parse commandline: {cmdline}\n{err}") from err
return vars(pub.settings)
2 changes: 1 addition & 1 deletion tests/test_renderers/test_fixtures_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def settings_from_json(string: str | None):
data = json.loads(string)
assert isinstance(data, dict), "settings must be a JSON object"
except Exception as err:
raise AssertionError(f"Failed to parse JSON settings: {string}\n{err}")
raise AssertionError(f"Failed to parse JSON settings: {string}\n{err}") from err
return data


Expand Down
2 changes: 1 addition & 1 deletion tests/test_renderers/test_myst_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_cmdline(file_params: ParamTestData):
except Exception as err:
raise AssertionError(
f"Failed to parse commandline: {file_params.description}\n{err}"
)
) from err
settings = vars(pub.settings)
report_stream = StringIO()
settings["output_encoding"] = "unicode"
Expand Down