Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekker1 committed Dec 6, 2023
1 parent e0ccc0d commit 6b61953
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 158 deletions.
289 changes: 146 additions & 143 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ python = "^3.8"
lark-parser = { version = "^0.12.0", optional = true }
# Docs extra (for readthedocs)
sphinx = { version = "^7.1", optional = true }
sphinx-rtd-theme = { version = "^1.0.0", optional = true }
sphinx-rtd-theme = { version = "^2.0", optional = true }

[tool.poetry.group.dev.dependencies]
black = "*"
Expand Down Expand Up @@ -62,7 +62,7 @@ types-dataclasses = "^0.6.5"
types-setuptools = ">=65.3,<70.0"
# Testing Framework
pytest = "^7.1"
ruff = ">=0.0.126,<0.1.7"
ruff = "0.1.5"

[tool.poetry.extras]
dzn = ["lark-parser"]
Expand Down Expand Up @@ -98,7 +98,7 @@ cache_dir = "/dev/null"
ignore_missing_imports = true

[tool.ruff]
ignore = ['E501']
ignore = ['E501', 'C901']
line-length = 80
select = ['B', 'C', 'E', 'F', 'W']
# TODO: Can we add 'I'?
2 changes: 2 additions & 0 deletions src/minizinc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
"MiniZinc was not found on the system. No default driver could be "
"initialised.",
RuntimeWarning,
stacklevel=1,
)
except ConfigurationError as err:
warnings.warn(
f"The MiniZinc version found on the system is incompatible with "
f"MiniZinc Python:\n{err}\n No default driver could be initialised.",
RuntimeWarning,
stacklevel=1,
)

__all__ = [
Expand Down
1 change: 1 addition & 0 deletions src/minizinc/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def check_solution(
if is_dataclass(solution):
solution = asdict(solution)

assert isinstance(solution, dict)
for k, v in solution.items():
if k not in ("objective", "__output_item"):
instance[k] = v
Expand Down
16 changes: 10 additions & 6 deletions src/minizinc/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ async def solutions(
warnings.warn(
"The usage of the `timeout` parameter is deprecated, please use the `time_limit` parameter instead.",
DeprecationWarning,
stacklevel=1,
)
time_limit = timeout

Expand Down Expand Up @@ -364,7 +365,7 @@ async def solutions(
for flag, value in kwargs.items():
if not flag.startswith("-"):
flag = "--" + flag
if type(value) is bool:
if isinstance(value, bool):
if value:
cmd.append(flag)
else:
Expand Down Expand Up @@ -584,11 +585,11 @@ def output(self):
return self._output_cache

@property
def has_output_item(self) -> Method:
def has_output_item(self) -> bool:
"""Query whether the instance constains an output item.
Returns:
Method: Method of the goal used by the Instance.
bool: whether the instance contains an output item.
"""
if self._has_output_item_cache is None:
self.analyse()
Expand Down Expand Up @@ -645,6 +646,7 @@ def analyse(self):
f"MiniZinc field '{k}' is a Python keyword. It has been "
f"renamed to 'mzn_{k}'",
SyntaxWarning,
stacklevel=1,
)
self._field_renames.append((k, "mzn_" + k))
fields.append(("mzn_" + k, v))
Expand All @@ -656,7 +658,7 @@ def analyse(self):
)

methods = {}
if interface.get("has_output_item", True):
if self._has_output_item_cache:
methods["__str__"] = (
lambda myself: myself.__repr__()
if myself._output_item == ""
Expand Down Expand Up @@ -714,6 +716,7 @@ def flat(
warnings.warn(
"The usage of the `timeout` parameter is deprecated, please use the `time_limit` parameter instead.",
DeprecationWarning,
stacklevel=1,
)
time_limit = timeout

Expand All @@ -735,8 +738,8 @@ def flat(

for flag, value in kwargs.items():
if not flag.startswith("-"):
flag = "--" + flag
if type(value) is bool:
flag = f"--{flag}"
if isinstance(value, bool):
if value:
cmd.append(flag)
else:
Expand Down Expand Up @@ -836,6 +839,7 @@ def _to_python_type(mzn_type: dict) -> Type:
warnings.warn(
f"Unable to determine minizinc type `{basetype}` assuming integer type",
FutureWarning,
stacklevel=1,
)
pytype = int

Expand Down
4 changes: 2 additions & 2 deletions src/minizinc/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def decode_json_stream(byte_stream: bytes, cls=None, **kw):
obj["type"] == "error" and obj["what"] == "warning"
):
# TODO: stack trace and location
warnings.warn(obj["message"], MiniZincWarning)
warnings.warn(obj["message"], MiniZincWarning, stacklevel=1)
elif obj["type"] == "error":
raise error_from_stream_obj(obj)
else:
Expand All @@ -101,7 +101,7 @@ async def decode_async_json_stream(stream: asyncio.StreamReader, cls=None, **kw)
obj["type"] == "error" and obj["what"] == "warning"
):
# TODO: stack trace and location
warnings.warn(obj["message"], MiniZincWarning)
warnings.warn(obj["message"], MiniZincWarning, stacklevel=1)
elif obj["type"] == "error":
raise error_from_stream_obj(obj)
else:
Expand Down
3 changes: 2 additions & 1 deletion src/minizinc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def _add_file(self, file: ParPath, parse_data: bool = False) -> None:
except LarkError:
warnings.warn(
f"Could not parse {file}. Parameters included within this file "
f"are not available in Python"
f"are not available in Python",
stacklevel=1,
)
with self._lock:
self._includes.append(file)
Expand Down
2 changes: 1 addition & 1 deletion src/minizinc/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def __getitem__(self, key):
else:
raise KeyError
except AttributeError:
raise KeyError
raise KeyError from None

def __len__(self):
"""Returns the number of solutions included in the Result object
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dzn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_dzn_set():
assert parse_dzn("x = {}") == {"x": set()}
assert parse_dzn("x = {1}") == {"x": {1}}
assert parse_dzn("x = {1,2,3}") == {"x": {1, 2, 3}}
assert parse_dzn("x = {1,1,2}") == {"x": {1, 1, 2}}
assert parse_dzn("x = {1,1,2}") == {"x": {1, 2}}
assert parse_dzn("x = {1.2,2.1}") == {"x": {1.2, 2.1}}

# Set Ranges
Expand Down
1 change: 0 additions & 1 deletion tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ class TestRecord(InstanceTestCase):
reason="requires MiniZinc 2.7 or higher",
)
def test_simple_record(self):
pytest.skip
self.instance.add_string(
"""
var record(1..3: a, bool: b, 1.0..3.0: c): x;
Expand Down

0 comments on commit 6b61953

Please sign in to comment.