Skip to content

Commit b81b71b

Browse files
committed
Improve null checking logic
1 parent 099cd8d commit b81b71b

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

harp/schema.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ def read_schema(
2222
if not "WhoAmI" in schema.registers and include_common_registers:
2323
common = _read_common_registers()
2424
schema.registers = dict(common.registers, **schema.registers)
25-
if schema.bitMasks is not None and common.bitMasks is not None:
26-
schema.bitMasks = dict(common.bitMasks, **schema.bitMasks)
27-
if schema.groupMasks is not None and common.groupMasks is not None:
28-
schema.groupMasks = dict(common.groupMasks, **schema.groupMasks)
25+
if common.bitMasks:
26+
schema.bitMasks = (
27+
common.bitMasks
28+
if schema.bitMasks is None
29+
else dict(common.bitMasks, **schema.bitMasks)
30+
)
31+
if common.groupMasks:
32+
schema.groupMasks = (
33+
common.groupMasks
34+
if schema.groupMasks is None
35+
else dict(common.groupMasks, **schema.groupMasks)
36+
)
2937
return schema

tests/test_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __post_init__(self):
5555

5656
@mark.parametrize("dataFile", testdata)
5757
def test_read(dataFile: DataFileParam):
58-
context = pytest.raises if dataFile.expected_error is not None else nullcontext
58+
context = pytest.raises if dataFile.expected_error else nullcontext
5959
with context(dataFile.expected_error): # type: ignore
6060
data = read(
6161
dataFile.path,
@@ -68,7 +68,7 @@ def test_read(dataFile: DataFileParam):
6868
if dataFile.keep_type:
6969
assert "type" in data.columns and data["type"].dtype == "category"
7070

71-
if dataFile.expected_cols is not None:
71+
if dataFile.expected_cols:
7272
for col in dataFile.expected_cols:
7373
assert col in data.columns
7474

0 commit comments

Comments
 (0)