Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ lint = [
"mypy~=2.1.0",
"pylint~=4.0.5",
"pylint-pytest==2.0.0a1",
"ruff~=0.3.4",
"ruff~=0.15.17",
"types-PyYAML~=6.0.12",
"types-requests~=2.33",
]
Expand Down
24 changes: 12 additions & 12 deletions src/databricks/labs/blueprint/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def _get_type_ref(cls, inst) -> type:
"""The `_get_type_ref` method is a private method that is used to determine the type of an object. This method
is called by the `save` method."""
type_ref = type(inst)
if type_ref == list:
if type_ref is list:
return cls._get_list_type_ref(inst)
return type_ref

Expand All @@ -509,9 +509,9 @@ def _marshal(self, type_ref: type, path: list[str], inst: Any) -> tuple[Any, boo
return inst.as_dict(), True
if dataclasses.is_dataclass(type_ref):
return self._marshal_dataclass(type_ref, path, inst)
if type_ref == list:
if type_ref is list:
return self._marshal_raw_list(path, inst)
if type_ref == dict:
if type_ref is dict:
return self._marshal_raw_dict(path, inst)
if isinstance(type_ref, enum.EnumMeta):
return self._marshal_enum(inst)
Expand All @@ -532,7 +532,7 @@ def _marshal_generic_types(self, type_ref: type, path: list[str], inst: Any) ->
if type_ref.__origin__ in (dict, list) or isinstance(type_ref, types.GenericAlias):
return self._marshal_generic(type_ref, path, inst)
return self._marshal_generic_alias(type_ref, inst)
raise SerdeError(f'{".".join(path)}: unknown: {inst}')
raise SerdeError(f"{'.'.join(path)}: unknown: {inst}")

def _marshal_union(self, type_ref: type, path: list[str], inst: Any) -> tuple[Any, bool]:
"""The `_marshal_union` method is a private method that is used to serialize an object of type `type_ref` to
Expand All @@ -543,7 +543,7 @@ def _marshal_union(self, type_ref: type, path: list[str], inst: Any) -> tuple[An
if ok:
return value, True
combo.append(self._explain_why(variant, [*path, f"(as {variant})"], inst))
raise SerdeError(f'{".".join(path)}: union: {" or ".join(combo)}')
raise SerdeError(f"{'.'.join(path)}: union: {' or '.join(combo)}")

def _marshal_generic(self, type_ref: type, path: list[str], inst: Any) -> tuple[Any, bool]:
"""The `_marshal_generic` method is a private method that is used to serialize an object of type `type_ref`
Expand Down Expand Up @@ -719,18 +719,18 @@ def _unmarshal_generic_types(cls, type_ref, path, inst):
_UnionGenericAlias,
)

if type_ref == list:
if type_ref is list:
msg = f"{'.'.join(path)}: raw list encountered; use list[type] instead: {inst}"
raise SerdeError(msg)
if type_ref == dict:
if type_ref is dict:
msg = f"{'.'.join(path)}: raw dict encountered; use dict[str,type] instead: {inst}"
raise SerdeError(msg)

if isinstance(type_ref, (types.UnionType, _UnionGenericAlias)):
return cls._unmarshal_union(inst, path, type_ref)
if isinstance(type_ref, (_GenericAlias, types.GenericAlias)):
return cls._unmarshal_generic(inst, path, type_ref)
raise SerdeError(f'{".".join(path)}: unknown: {type_ref}: {inst}')
raise SerdeError(f"{'.'.join(path)}: unknown: {type_ref}: {inst}")

@classmethod
def _unmarshal_dataclass(cls, inst, path, type_ref):
Expand Down Expand Up @@ -858,15 +858,15 @@ def _unmarshal_primitive(cls, inst: Any, path: list[str], type_ref: type) -> Any
# Some special cases:
# - str -> bool: only accept "true" or "false" (case-insensitive).
# - float -> int: refuse to truncate
if type_ref == bool:
if type_ref is bool:
if isinstance(inst, str):
if inst.lower() == "true":
return True
if inst.lower() == "false":
return False
msg = f"{'.'.join(path)}: Expected bool, got: {inst}"
raise SerdeError(msg)
if type_ref == int and isinstance(inst, float):
if type_ref is int and isinstance(inst, float):
msg = f"{'.'.join(path)}: Expected int, got float: {inst}"
raise SerdeError(msg)

Expand All @@ -885,7 +885,7 @@ def _explain_why(type_ref: type, path: list[str], raw: Any) -> str:
if raw is None:
raw = "value is missing"
type_name = getattr(type_ref, "__name__", str(type_ref))
return f'{".".join(path)}: not a {type_name}: {raw}'
return f"{'.'.join(path)}: not a {type_name}: {raw}"

@staticmethod
def _dump_json(as_dict: JsonValue, _: type) -> bytes:
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def _assert_upload(filename: Any, loc: dict[str, bytes], expected: bytes | None
if expected:
assert loc[name] == expected, f"{filename} content missmatch"
return
raise AssertionError(f'Cannot find {filename.pattern} among {", ".join(loc.keys())}')
raise AssertionError(f"Cannot find {filename.pattern} among {', '.join(loc.keys())}")
assert filename in loc, f"{filename} had no writes"
if expected:
assert loc[filename] == expected, f"{filename} content missmatch"
2 changes: 1 addition & 1 deletion src/databricks/labs/blueprint/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class ManyError(RuntimeError):
def __init__(self, errs: Sequence[BaseException]):
strs = sorted({f"{_.__class__.__name__}: {_!s}" for _ in errs})
msg = f'Detected {len(errs)} failures: {", ".join(strs)}'
msg = f"Detected {len(errs)} failures: {', '.join(strs)}"
super().__init__(msg)
self.errs = errs

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,13 @@ async def test_readlines_small_reads() -> None:
((b"1", b"12\n45\n78\n0", b"12\n"), ("112", "45", "78", "012")),
# A very long line, with some existing data in the buffer, and leaving some remainder.
(
(b"12", b"3456789012" b"3456789012" b"3456789012" b"34567890\n1234"),
(b"12", b"3456789012" + b"3456789012" + b"3456789012" + b"34567890\n1234"),
("1234567890+", "1234567890+", "1234567890+", "1234567890+", "", "1234!"),
),
# A \r\n newline split across reads.
((b"1234\r", b"\nabcd\n"), ("1234", "abcd")),
# A \r\n split exactly on the limit.
((b"123456789\r" b"\nabcd\n",), ("123456789+", "", "abcd")),
((b"123456789\r" + b"\nabcd\n",), ("123456789+", "", "abcd")),
),
)
async def test_readlines_line_exceeds_limit(data_chunks: Sequence[bytes], expected_messages: Sequence[str]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ def test_cpu_count_source_process_cpu_count() -> None:
):
assert Threads.available_cpu_count() == 13, "Should use os.process_cpu_count() if available"
assert mock_process_cpu_count.called, "os.process_cpu_count() should be called"
assert (
not mock_sched_getaffinity.called
), "os.sched_getaffinity() should not be called if os.process_cpu_count() is available"
assert not mock_sched_getaffinity.called, (
"os.sched_getaffinity() should not be called if os.process_cpu_count() is available"
)
assert not mock_cpu_count.called, "os.cpu_count() should not be called if os.process_cpu_count() is available"


Expand Down
41 changes: 21 additions & 20 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading