From f1dba19d8bdd98c78af20b7efa03e965f9c0a54c Mon Sep 17 00:00:00 2001 From: Hussein Awala Date: Sat, 21 Oct 2023 23:06:42 +0200 Subject: [PATCH 1/2] Replace old %-formatted by f-strings and add flynt hook to auto-detect and fix them --- .pre-commit-config.yaml | 4 ++++ pyiceberg/io/pyarrow.py | 2 +- pyiceberg/schema.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4a2682cdf..8f2d6df01b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,3 +70,7 @@ repos: ] additional_dependencies: - tomli==2.0.1 + - repo: https://github.com/ikamensh/flynt + rev: 1.0.1 + hooks: + - id: flynt diff --git a/pyiceberg/io/pyarrow.py b/pyiceberg/io/pyarrow.py index a3d1869cf8..f3ef5ca5a0 100644 --- a/pyiceberg/io/pyarrow.py +++ b/pyiceberg/io/pyarrow.py @@ -633,7 +633,7 @@ def visit_pyarrow(obj: Union[pa.DataType, pa.Schema], visitor: PyArrowSchemaVisi Raises: NotImplementedError: If attempting to visit an unrecognized object type. """ - raise NotImplementedError("Cannot visit non-type: %s" % obj) + raise NotImplementedError(f"Cannot visit non-type: {obj}") @visit_pyarrow.register(pa.Schema) diff --git a/pyiceberg/schema.py b/pyiceberg/schema.py index 7fdd717858..b61e4678b9 100644 --- a/pyiceberg/schema.py +++ b/pyiceberg/schema.py @@ -794,7 +794,7 @@ def visit(obj: Union[Schema, IcebergType], visitor: SchemaVisitor[T]) -> T: Raises: NotImplementedError: If attempting to visit an unrecognized object type. """ - raise NotImplementedError("Cannot visit non-type: %s" % obj) + raise NotImplementedError(f"Cannot visit non-type: {obj}") @visit.register(Schema) @@ -862,7 +862,7 @@ def pre_order_visit(obj: Union[Schema, IcebergType], visitor: PreOrderSchemaVisi Raises: NotImplementedError: If attempting to visit an unrecognized object type. """ - raise NotImplementedError("Cannot visit non-type: %s" % obj) + raise NotImplementedError(f"Cannot visit non-type: {obj}") @pre_order_visit.register(Schema) From 782a5f6d8bd7f85b314c93d4aa9cc83371f1ea87 Mon Sep 17 00:00:00 2001 From: Hussein Awala Date: Sat, 21 Oct 2023 23:11:47 +0200 Subject: [PATCH 2/2] add --line-length arg to detect long lines --- .pre-commit-config.yaml | 4 ++++ tests/test_schema.py | 9 +++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8f2d6df01b..f1decf7772 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -74,3 +74,7 @@ repos: rev: 1.0.1 hooks: - id: flynt + args: + # --line-length is set to a high value to deal with very long lines + - --line-length + - '99999' diff --git a/tests/test_schema.py b/tests/test_schema.py index c12910a4b4..8e34423cf9 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -877,24 +877,21 @@ def test_identifier_fields_fails(table_schema_nested_with_struct_key_map: Schema with pytest.raises(ValueError) as exc_info: Schema(*table_schema_nested_with_struct_key_map.fields, schema_id=1, identifier_field_ids=[23]) assert ( - "Cannot add field zip as an identifier field: must not be nested in %s" - % table_schema_nested_with_struct_key_map.find_field("location") + f"Cannot add field zip as an identifier field: must not be nested in {table_schema_nested_with_struct_key_map.find_field('location')}" in str(exc_info.value) ) with pytest.raises(ValueError) as exc_info: Schema(*table_schema_nested_with_struct_key_map.fields, schema_id=1, identifier_field_ids=[26]) assert ( - "Cannot add field x as an identifier field: must not be nested in %s" - % table_schema_nested_with_struct_key_map.find_field("points") + f"Cannot add field x as an identifier field: must not be nested in {table_schema_nested_with_struct_key_map.find_field('points')}" in str(exc_info.value) ) with pytest.raises(ValueError) as exc_info: Schema(*table_schema_nested_with_struct_key_map.fields, schema_id=1, identifier_field_ids=[17]) assert ( - "Cannot add field age as an identifier field: must not be nested in an optional field %s" - % table_schema_nested_with_struct_key_map.find_field("person") + 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')}" in str(exc_info.value) )