Skip to content

Commit 4616d03

Browse files
Replace old %-formatted by f-strings (#93)
* Replace old %-formatted by f-strings and add flynt hook to auto-detect and fix them * add --line-length arg to detect long lines
1 parent 7ed9bbc commit 4616d03

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ repos:
7070
]
7171
additional_dependencies:
7272
- tomli==2.0.1
73+
- repo: https://github.com/ikamensh/flynt
74+
rev: 1.0.1
75+
hooks:
76+
- id: flynt
77+
args:
78+
# --line-length is set to a high value to deal with very long lines
79+
- --line-length
80+
- '99999'

pyiceberg/io/pyarrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def visit_pyarrow(obj: Union[pa.DataType, pa.Schema], visitor: PyArrowSchemaVisi
633633
Raises:
634634
NotImplementedError: If attempting to visit an unrecognized object type.
635635
"""
636-
raise NotImplementedError("Cannot visit non-type: %s" % obj)
636+
raise NotImplementedError(f"Cannot visit non-type: {obj}")
637637

638638

639639
@visit_pyarrow.register(pa.Schema)

pyiceberg/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def visit(obj: Union[Schema, IcebergType], visitor: SchemaVisitor[T]) -> T:
794794
Raises:
795795
NotImplementedError: If attempting to visit an unrecognized object type.
796796
"""
797-
raise NotImplementedError("Cannot visit non-type: %s" % obj)
797+
raise NotImplementedError(f"Cannot visit non-type: {obj}")
798798

799799

800800
@visit.register(Schema)
@@ -862,7 +862,7 @@ def pre_order_visit(obj: Union[Schema, IcebergType], visitor: PreOrderSchemaVisi
862862
Raises:
863863
NotImplementedError: If attempting to visit an unrecognized object type.
864864
"""
865-
raise NotImplementedError("Cannot visit non-type: %s" % obj)
865+
raise NotImplementedError(f"Cannot visit non-type: {obj}")
866866

867867

868868
@pre_order_visit.register(Schema)

tests/test_schema.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,24 +877,21 @@ def test_identifier_fields_fails(table_schema_nested_with_struct_key_map: Schema
877877
with pytest.raises(ValueError) as exc_info:
878878
Schema(*table_schema_nested_with_struct_key_map.fields, schema_id=1, identifier_field_ids=[23])
879879
assert (
880-
"Cannot add field zip as an identifier field: must not be nested in %s"
881-
% table_schema_nested_with_struct_key_map.find_field("location")
880+
f"Cannot add field zip as an identifier field: must not be nested in {table_schema_nested_with_struct_key_map.find_field('location')}"
882881
in str(exc_info.value)
883882
)
884883

885884
with pytest.raises(ValueError) as exc_info:
886885
Schema(*table_schema_nested_with_struct_key_map.fields, schema_id=1, identifier_field_ids=[26])
887886
assert (
888-
"Cannot add field x as an identifier field: must not be nested in %s"
889-
% table_schema_nested_with_struct_key_map.find_field("points")
887+
f"Cannot add field x as an identifier field: must not be nested in {table_schema_nested_with_struct_key_map.find_field('points')}"
890888
in str(exc_info.value)
891889
)
892890

893891
with pytest.raises(ValueError) as exc_info:
894892
Schema(*table_schema_nested_with_struct_key_map.fields, schema_id=1, identifier_field_ids=[17])
895893
assert (
896-
"Cannot add field age as an identifier field: must not be nested in an optional field %s"
897-
% table_schema_nested_with_struct_key_map.find_field("person")
894+
f"Cannot add field age as an identifier field: must not be nested in an optional field {table_schema_nested_with_struct_key_map.find_field('person')}"
898895
in str(exc_info.value)
899896
)
900897

0 commit comments

Comments
 (0)