mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-04 16:57:32 +08:00
Add more ruff rules (#8767)
* Add more ruff rules * Add more ruff rules * pre-commit: Update ruff v0.0.269 -> v0.0.270 * Apply suggestions from code review * Fix doctest * Fix doctest (ignore whitespace) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -77,15 +77,17 @@ def length_conversion(value: float, from_type: str, to_type: str) -> float:
|
||||
to_sanitized = UNIT_SYMBOL.get(to_sanitized, to_sanitized)
|
||||
|
||||
if from_sanitized not in METRIC_CONVERSION:
|
||||
raise ValueError(
|
||||
msg = (
|
||||
f"Invalid 'from_type' value: {from_type!r}.\n"
|
||||
f"Conversion abbreviations are: {', '.join(METRIC_CONVERSION)}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
if to_sanitized not in METRIC_CONVERSION:
|
||||
raise ValueError(
|
||||
msg = (
|
||||
f"Invalid 'to_type' value: {to_type!r}.\n"
|
||||
f"Conversion abbreviations are: {', '.join(METRIC_CONVERSION)}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
from_exponent = METRIC_CONVERSION[from_sanitized]
|
||||
to_exponent = METRIC_CONVERSION[to_sanitized]
|
||||
exponent = 1
|
||||
|
@ -104,15 +104,17 @@ def length_conversion(value: float, from_type: str, to_type: str) -> float:
|
||||
new_to = to_type.lower().rstrip("s")
|
||||
new_to = TYPE_CONVERSION.get(new_to, new_to)
|
||||
if new_from not in METRIC_CONVERSION:
|
||||
raise ValueError(
|
||||
msg = (
|
||||
f"Invalid 'from_type' value: {from_type!r}.\n"
|
||||
f"Conversion abbreviations are: {', '.join(METRIC_CONVERSION)}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
if new_to not in METRIC_CONVERSION:
|
||||
raise ValueError(
|
||||
msg = (
|
||||
f"Invalid 'to_type' value: {to_type!r}.\n"
|
||||
f"Conversion abbreviations are: {', '.join(METRIC_CONVERSION)}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
return value * METRIC_CONVERSION[new_from].from_ * METRIC_CONVERSION[new_to].to
|
||||
|
||||
|
||||
|
@ -57,10 +57,11 @@ def convert_speed(speed: float, unit_from: str, unit_to: str) -> float:
|
||||
115.078
|
||||
"""
|
||||
if unit_to not in speed_chart or unit_from not in speed_chart_inverse:
|
||||
raise ValueError(
|
||||
msg = (
|
||||
f"Incorrect 'from_type' or 'to_type' value: {unit_from!r}, {unit_to!r}\n"
|
||||
f"Valid values are: {', '.join(speed_chart_inverse)}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
return round(speed * speed_chart[unit_from] * speed_chart_inverse[unit_to], 3)
|
||||
|
||||
|
||||
|
@ -299,10 +299,11 @@ def weight_conversion(from_type: str, to_type: str, value: float) -> float:
|
||||
1.999999998903455
|
||||
"""
|
||||
if to_type not in KILOGRAM_CHART or from_type not in WEIGHT_TYPE_CHART:
|
||||
raise ValueError(
|
||||
msg = (
|
||||
f"Invalid 'from_type' or 'to_type' value: {from_type!r}, {to_type!r}\n"
|
||||
f"Supported values are: {', '.join(WEIGHT_TYPE_CHART)}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
return value * KILOGRAM_CHART[to_type] * WEIGHT_TYPE_CHART[from_type]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user