Skip to content

Commit 1fe9697

Browse files
authored
chore: remove non-test asserts (apache#2082)
Baby PR to remove `assert` statements out of any non-test code.
1 parent 38ebb19 commit 1fe9697

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

pyiceberg/catalog/dynamodb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,9 @@ def _convert_dynamo_item_to_regular_dict(dynamo_json: Dict[str, Any]) -> Dict[st
836836
raise ValueError("Only S and N data types are supported.")
837837

838838
values = list(val_dict.values())
839-
assert len(values) == 1
839+
if len(values) != 1:
840+
raise ValueError(f"Expecting only 1 value: {values}")
841+
840842
column_value = values[0]
841843
regular_json[column_name] = column_value
842844

pyiceberg/catalog/glue.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ def _construct_table_input(
252252
def _construct_rename_table_input(to_table_name: str, glue_table: "TableTypeDef") -> "TableInputTypeDef":
253253
rename_table_input: "TableInputTypeDef" = {"Name": to_table_name}
254254
# use the same Glue info to create the new table, pointing to the old metadata
255-
assert glue_table["TableType"]
255+
if not glue_table["TableType"]:
256+
raise ValueError("Glue table type is missing, cannot rename table")
257+
256258
rename_table_input["TableType"] = glue_table["TableType"]
257259
if "Owner" in glue_table:
258260
rename_table_input["Owner"] = glue_table["Owner"]
@@ -347,9 +349,14 @@ def __init__(self, name: str, client: Optional["GlueClient"] = None, **propertie
347349
def _convert_glue_to_iceberg(self, glue_table: "TableTypeDef") -> Table:
348350
properties: Properties = glue_table["Parameters"]
349351

350-
assert glue_table["DatabaseName"]
351-
assert glue_table["Parameters"]
352-
database_name = glue_table["DatabaseName"]
352+
database_name = glue_table.get("DatabaseName", None)
353+
if database_name is None:
354+
raise ValueError("Glue table is missing DatabaseName property")
355+
356+
parameters = glue_table.get("Parameters", None)
357+
if parameters is None:
358+
raise ValueError("Glue table is missing Parameters property")
359+
353360
table_name = glue_table["Name"]
354361

355362
if TABLE_TYPE not in properties:

pyiceberg/cli/console.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ def get_namespace(ctx: Context, identifier: str, property_name: str) -> None:
300300
identifier_tuple = Catalog.identifier_to_tuple(identifier)
301301

302302
namespace_properties = catalog.load_namespace_properties(identifier_tuple)
303-
assert namespace_properties
304303

305304
if property_name:
306305
if property_value := namespace_properties.get(property_name):
@@ -322,7 +321,6 @@ def get_table(ctx: Context, identifier: str, property_name: str) -> None:
322321
identifier_tuple = Catalog.identifier_to_tuple(identifier)
323322

324323
metadata = catalog.load_table(identifier_tuple).metadata
325-
assert metadata
326324

327325
if property_name:
328326
if property_value := metadata.properties.get(property_name):

pyiceberg/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,8 @@ def make_compatible_name(name: str) -> str:
13621362

13631363

13641364
def _valid_avro_name(name: str) -> bool:
1365-
length = len(name)
1366-
assert length > 0, ValueError("Can not validate empty avro name")
1365+
if not len(name):
1366+
raise ValueError("Can not validate empty avro name")
13671367
first = name[0]
13681368
if not (first.isalpha() or first == "_"):
13691369
return False

pyiceberg/utils/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def get_catalog_config(self, catalog_name: str) -> Optional[RecursiveDict]:
154154
raise ValueError(f"Catalog configurations needs to be an object: {catalog_name}")
155155
if catalog_name_lower in catalogs:
156156
catalog_conf = catalogs[catalog_name_lower]
157-
assert isinstance(catalog_conf, dict), f"Configuration path catalogs.{catalog_name_lower} needs to be an object"
157+
if not isinstance(catalog_conf, dict):
158+
raise ValueError(f"Configuration path catalogs.{catalog_name_lower} needs to be an object")
158159
return catalog_conf
159160
return None
160161

0 commit comments

Comments
 (0)