diff --git a/libs/labelbox/pyproject.toml b/libs/labelbox/pyproject.toml index f4c24af59..e27aac527 100644 --- a/libs/labelbox/pyproject.toml +++ b/libs/labelbox/pyproject.toml @@ -74,6 +74,10 @@ dev-dependencies = [ [tool.ruff] line-length = 80 +[tool.ruff.lint] +ignore = ["F", "E722"] +exclude = ["**/__init__.py"] + [tool.rye.scripts] unit = "pytest tests/unit" # https://github.com/Labelbox/labelbox-python/blob/7c84fdffbc14fd1f69d2a6abdcc0087dc557fa4e/Makefile @@ -89,9 +93,10 @@ unit = "pytest tests/unit" # LABELBOX_TEST_BASE_URL="http://host.docker.internal:8080" \ integration = { cmd = "pytest tests/integration" } data = { cmd = "pytest tests/data" } +rye-lint = "rye lint" rye-fmt-check = "rye fmt --check" mypy-lint = "mypy src --pretty --show-error-codes --non-interactive --install-types" -lint = { chain = ["mypy-lint", "rye-fmt-check"] } +lint = { chain = ["rye-fmt-check", "mypy-lint", "rye-lint"] } test = { chain = ["lint", "unit", "integration"] } [tool.hatch.metadata] diff --git a/libs/labelbox/src/labelbox/client.py b/libs/labelbox/src/labelbox/client.py index b0b5a1407..441c12422 100644 --- a/libs/labelbox/src/labelbox/client.py +++ b/libs/labelbox/src/labelbox/client.py @@ -626,7 +626,7 @@ def _get_all(self, db_object_type, where, filter_deleted=True): An iterable of `db_object_type` instances. """ if filter_deleted: - not_deleted = db_object_type.deleted == False + not_deleted = db_object_type.deleted == False # noqa: E712 Needed for bit operator to combine comparisons where = not_deleted if where is None else where & not_deleted query_str, params = query.get_all(db_object_type, where) @@ -2297,11 +2297,11 @@ def delete_feature_schema_from_ontology( if response.status_code == requests.codes.ok: response_json = response.json() - if response_json["archived"] == True: + if response_json["archived"] is True: logger.info( "Feature schema was archived from the ontology because it had associated labels." ) - elif response_json["deleted"] == True: + elif response_json["deleted"] is True: logger.info( "Feature schema was successfully removed from the ontology" ) diff --git a/libs/labelbox/src/labelbox/data/annotation_types/data/raster.py b/libs/labelbox/src/labelbox/data/annotation_types/data/raster.py index ba4c6485f..fd76d9a66 100644 --- a/libs/labelbox/src/labelbox/data/annotation_types/data/raster.py +++ b/libs/labelbox/src/labelbox/data/annotation_types/data/raster.py @@ -172,7 +172,7 @@ def validate_args(self, values): uid = self.uid global_key = self.global_key if ( - uid == file_path == im_bytes == url == global_key == None + uid == file_path == im_bytes == url == global_key is None and arr is None ): raise ValueError( @@ -191,7 +191,9 @@ def validate_args(self, values): return self def __repr__(self) -> str: - symbol_or_none = lambda data: "..." if data is not None else None + def symbol_or_none(data): + return "..." if data is not None else None + return ( f"{self.__class__.__name__}(im_bytes={symbol_or_none(self.im_bytes)}," f"file_path={self.file_path}," diff --git a/libs/labelbox/src/labelbox/data/annotation_types/data/text.py b/libs/labelbox/src/labelbox/data/annotation_types/data/text.py index fe4c222d3..3926a0832 100644 --- a/libs/labelbox/src/labelbox/data/annotation_types/data/text.py +++ b/libs/labelbox/src/labelbox/data/annotation_types/data/text.py @@ -101,7 +101,7 @@ def validate_date(self, values): url = self.url uid = self.uid global_key = self.global_key - if uid == file_path == text == url == global_key == None: + if uid == file_path == text == url == global_key is None: raise ValueError( "One of `file_path`, `text`, `uid`, `global_key` or `url` required." ) diff --git a/libs/labelbox/src/labelbox/data/annotation_types/data/video.py b/libs/labelbox/src/labelbox/data/annotation_types/data/video.py index 581801036..0f40911d8 100644 --- a/libs/labelbox/src/labelbox/data/annotation_types/data/video.py +++ b/libs/labelbox/src/labelbox/data/annotation_types/data/video.py @@ -159,7 +159,7 @@ def validate_data(self): uid = self.uid global_key = self.global_key - if uid == file_path == frames == url == global_key == None: + if uid == file_path == frames == url == global_key is None: raise ValueError( "One of `file_path`, `frames`, `uid`, `global_key` or `url` required." ) diff --git a/libs/labelbox/src/labelbox/data/annotation_types/video.py b/libs/labelbox/src/labelbox/data/annotation_types/video.py index cfebd7a1f..5a93704c8 100644 --- a/libs/labelbox/src/labelbox/data/annotation_types/video.py +++ b/libs/labelbox/src/labelbox/data/annotation_types/video.py @@ -125,7 +125,7 @@ class MaskFrame(_CamelCaseMixin, BaseModel): def validate_args(self, values): im_bytes = self.im_bytes instance_uri = self.instance_uri - if im_bytes == instance_uri == None: + if im_bytes == instance_uri is None: raise ValueError("One of `instance_uri`, `im_bytes` required.") return self diff --git a/libs/labelbox/src/labelbox/data/metrics/confusion_matrix/calculation.py b/libs/labelbox/src/labelbox/data/metrics/confusion_matrix/calculation.py index 938e17f65..83410a540 100644 --- a/libs/labelbox/src/labelbox/data/metrics/confusion_matrix/calculation.py +++ b/libs/labelbox/src/labelbox/data/metrics/confusion_matrix/calculation.py @@ -130,7 +130,7 @@ def classification_confusion_matrix( prediction, ground_truth = predictions[0], ground_truths[0] - if type(prediction) != type(ground_truth): + if type(prediction) is not type(ground_truth): raise TypeError( "Classification features must be the same type to compute agreement. " f"Found `{type(prediction)}` and `{type(ground_truth)}`" diff --git a/libs/labelbox/src/labelbox/data/metrics/iou/calculation.py b/libs/labelbox/src/labelbox/data/metrics/iou/calculation.py index 2a376d3fe..d0237963c 100644 --- a/libs/labelbox/src/labelbox/data/metrics/iou/calculation.py +++ b/libs/labelbox/src/labelbox/data/metrics/iou/calculation.py @@ -209,7 +209,7 @@ def classification_miou( prediction, ground_truth = predictions[0], ground_truths[0] - if type(prediction) != type(ground_truth): + if type(prediction) is not type(ground_truth): raise TypeError( "Classification features must be the same type to compute agreement. " f"Found `{type(prediction)}` and `{type(ground_truth)}`" diff --git a/libs/labelbox/src/labelbox/orm/db_object.py b/libs/labelbox/src/labelbox/orm/db_object.py index b210a8a5b..7f42d7b1e 100644 --- a/libs/labelbox/src/labelbox/orm/db_object.py +++ b/libs/labelbox/src/labelbox/orm/db_object.py @@ -177,7 +177,7 @@ def _to_many(self, where=None, order_by=None): ) if rel.filter_deleted: - not_deleted = rel.destination_type.deleted == False + not_deleted = rel.destination_type.deleted == False # noqa: E712 Needed for bit operator to combine comparisons where = not_deleted if where is None else where & not_deleted query_string, params = query.relationship( diff --git a/libs/labelbox/src/labelbox/schema/data_row_metadata.py b/libs/labelbox/src/labelbox/schema/data_row_metadata.py index 288459a89..d6c50b975 100644 --- a/libs/labelbox/src/labelbox/schema/data_row_metadata.py +++ b/libs/labelbox/src/labelbox/schema/data_row_metadata.py @@ -803,13 +803,13 @@ def _convert_metadata_field(metadata_field): if isinstance(metadata_field, DataRowMetadataField): return metadata_field elif isinstance(metadata_field, dict): - if not "value" in metadata_field: + if "value" not in metadata_field: raise ValueError( f"Custom metadata field '{metadata_field}' must have a 'value' key" ) if ( - not "schema_id" in metadata_field - and not "name" in metadata_field + "schema_id" not in metadata_field + and "name" not in metadata_field ): raise ValueError( f"Custom metadata field '{metadata_field}' must have either 'schema_id' or 'name' key" @@ -954,9 +954,8 @@ def _validate_custom_schema_by_name( def _batch_items(iterable: List[Any], size: int) -> Generator[Any, None, None]: - l = len(iterable) - for ndx in range(0, l, size): - yield iterable[ndx : min(ndx + size, l)] + for ndx in range(0, len(iterable), size): + yield iterable[ndx : min(ndx + size, len(iterable))] def _batch_operations( diff --git a/libs/labelbox/src/labelbox/schema/export_params.py b/libs/labelbox/src/labelbox/schema/export_params.py index b15bc2828..d5024bd30 100644 --- a/libs/labelbox/src/labelbox/schema/export_params.py +++ b/libs/labelbox/src/labelbox/schema/export_params.py @@ -2,8 +2,6 @@ from typing import Optional, List -EXPORT_LIMIT = 30 - from labelbox.schema.media_type import MediaType if sys.version_info >= (3, 8): @@ -11,6 +9,8 @@ else: from typing_extensions import TypedDict +EXPORT_LIMIT = 30 + class DataRowParams(TypedDict): data_row_details: Optional[bool] diff --git a/libs/labelbox/src/labelbox/schema/internal/descriptor_file_creator.py b/libs/labelbox/src/labelbox/schema/internal/descriptor_file_creator.py index ce3ce4b35..9f2ea72a0 100644 --- a/libs/labelbox/src/labelbox/schema/internal/descriptor_file_creator.py +++ b/libs/labelbox/src/labelbox/schema/internal/descriptor_file_creator.py @@ -161,7 +161,7 @@ def check_message_keys(message): ] ) for key in message.keys(): - if not key in accepted_message_keys: + if key not in accepted_message_keys: raise KeyError( f"Invalid {key} key found! Accepted keys in messages list is {accepted_message_keys}" ) diff --git a/libs/labelbox/tests/data/annotation_types/test_collection.py b/libs/labelbox/tests/data/annotation_types/test_collection.py index 9deddc3c8..1c9cd669e 100644 --- a/libs/labelbox/tests/data/annotation_types/test_collection.py +++ b/libs/labelbox/tests/data/annotation_types/test_collection.py @@ -114,7 +114,7 @@ def test_adding_to_dataset(signer): assert label.data.url != uuid generated_label = next(generator) assert generated_label.data.url == uuid - assert generated_label.data.external_id != None + assert generated_label.data.external_id is not None assert generated_label.data.uid == dataset.uid assert label.data.url == uuid diff --git a/libs/labelbox/tests/data/export/streamable/test_export_embeddings_streamable.py b/libs/labelbox/tests/data/export/streamable/test_export_embeddings_streamable.py index 071acbb5b..25e58e2dc 100644 --- a/libs/labelbox/tests/data/export/streamable/test_export_embeddings_streamable.py +++ b/libs/labelbox/tests/data/export/streamable/test_export_embeddings_streamable.py @@ -86,6 +86,6 @@ def test_export_embeddings_custom( if emb["id"] == embedding.id: assert emb["name"] == embedding.name assert emb["dimensions"] == embedding.dims - assert emb["is_custom"] == True + assert emb["is_custom"] is True assert len(emb["values"]) == 1 assert emb["values"][0]["value"] == vector diff --git a/libs/labelbox/tests/integration/test_benchmark.py b/libs/labelbox/tests/integration/test_benchmark.py index c10542bda..661f83bd7 100644 --- a/libs/labelbox/tests/integration/test_benchmark.py +++ b/libs/labelbox/tests/integration/test_benchmark.py @@ -1,17 +1,17 @@ def test_benchmark(configured_project_with_label): project, _, data_row, label = configured_project_with_label assert set(project.benchmarks()) == set() - assert label.is_benchmark_reference == False + assert label.is_benchmark_reference is False benchmark = label.create_benchmark() assert set(project.benchmarks()) == {benchmark} assert benchmark.reference_label() == label # Refresh label data to check it's benchmark reference label = list(data_row.labels())[0] - assert label.is_benchmark_reference == True + assert label.is_benchmark_reference is True benchmark.delete() assert set(project.benchmarks()) == set() # Refresh label data to check it's benchmark reference label = list(data_row.labels())[0] - assert label.is_benchmark_reference == False + assert label.is_benchmark_reference is False diff --git a/libs/labelbox/tests/integration/test_data_rows.py b/libs/labelbox/tests/integration/test_data_rows.py index 7f69c2995..8ec6b20c3 100644 --- a/libs/labelbox/tests/integration/test_data_rows.py +++ b/libs/labelbox/tests/integration/test_data_rows.py @@ -120,7 +120,7 @@ def make_metadata_fields_dict(): def test_get_data_row_by_global_key(data_row_and_global_key, client, rand_gen): _, global_key = data_row_and_global_key data_row = client.get_data_row_by_global_key(global_key) - assert type(data_row) == DataRow + assert type(data_row) is DataRow assert data_row.global_key == global_key @@ -677,9 +677,10 @@ def test_data_row_update( pdf_url = "https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf" tileLayerUrl = "https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483-lb-textlayer.json" data_row.update(row_data={"pdfUrl": pdf_url, "tileLayerUrl": tileLayerUrl}) - custom_check = ( - lambda data_row: data_row.row_data and "pdfUrl" not in data_row.row_data - ) + + def custom_check(data_row): + return data_row.row_data and "pdfUrl" not in data_row.row_data + data_row = wait_for_data_row_processing( client, data_row, custom_check=custom_check ) @@ -1023,9 +1024,9 @@ def test_data_row_bulk_creation_with_same_global_keys( task.wait_till_done() assert task.status == "COMPLETE" - assert type(task.failed_data_rows) is list + assert isinstance(task.failed_data_rows, list) assert len(task.failed_data_rows) == 1 - assert type(task.created_data_rows) is list + assert isinstance(task.created_data_rows, list) assert len(task.created_data_rows) == 1 assert ( task.failed_data_rows[0]["message"] diff --git a/libs/labelbox/tests/integration/test_ephemeral.py b/libs/labelbox/tests/integration/test_ephemeral.py index a23572fdf..3c4fc62e4 100644 --- a/libs/labelbox/tests/integration/test_ephemeral.py +++ b/libs/labelbox/tests/integration/test_ephemeral.py @@ -7,7 +7,7 @@ reason="This test only runs in EPHEMERAL environment", ) def test_org_and_user_setup(client, ephmeral_client): - assert type(client) == ephmeral_client + assert type(client) is ephmeral_client assert client.admin_client assert client.api_key != client.admin_client.api_key @@ -22,4 +22,4 @@ def test_org_and_user_setup(client, ephmeral_client): reason="This test does not run in EPHEMERAL environment", ) def test_integration_client(client, integration_client): - assert type(client) == integration_client + assert type(client) is integration_client diff --git a/libs/labelbox/tests/integration/test_ontology.py b/libs/labelbox/tests/integration/test_ontology.py index 91ef74a39..bf70536d0 100644 --- a/libs/labelbox/tests/integration/test_ontology.py +++ b/libs/labelbox/tests/integration/test_ontology.py @@ -13,7 +13,7 @@ def test_feature_schema_is_not_archived(client, ontology): result = client.is_feature_schema_archived( ontology.uid, feature_schema_to_check["featureSchemaId"] ) - assert result == False + assert result is False def test_feature_schema_is_archived(client, configured_project_with_label): @@ -23,10 +23,10 @@ def test_feature_schema_is_archived(client, configured_project_with_label): result = client.delete_feature_schema_from_ontology( ontology.uid, feature_schema_id ) - assert result.archived == True and result.deleted == False + assert result.archived is True and result.deleted is False assert ( client.is_feature_schema_archived(ontology.uid, feature_schema_id) - == True + is True ) @@ -58,8 +58,8 @@ def test_delete_tool_feature_from_ontology(client, ontology): result = client.delete_feature_schema_from_ontology( ontology.uid, feature_schema_to_delete["featureSchemaId"] ) - assert result.deleted == True - assert result.archived == False + assert result.deleted is True + assert result.archived is False updatedOntology = client.get_ontology(ontology.uid) assert len(updatedOntology.normalized["tools"]) == 1 @@ -300,7 +300,7 @@ def test_unarchive_feature_schema_node(client, ontology): result = client.unarchive_feature_schema_node( ontology.uid, feature_schema_to_unarchive["featureSchemaId"] ) - assert result == None + assert result is None def test_unarchive_feature_schema_node_for_non_existing_feature_schema( diff --git a/libs/labelbox/tests/integration/test_toggle_mal.py b/libs/labelbox/tests/integration/test_toggle_mal.py index 41dfbe395..566c4210c 100644 --- a/libs/labelbox/tests/integration/test_toggle_mal.py +++ b/libs/labelbox/tests/integration/test_toggle_mal.py @@ -1,9 +1,9 @@ def test_enable_model_assisted_labeling(project): response = project.enable_model_assisted_labeling() - assert response == True + assert response is True response = project.enable_model_assisted_labeling(True) - assert response == True + assert response is True response = project.enable_model_assisted_labeling(False) - assert response == False + assert response is False diff --git a/libs/labelbox/tests/unit/test_unit_ontology.py b/libs/labelbox/tests/unit/test_unit_ontology.py index 0566ad623..4b4958beb 100644 --- a/libs/labelbox/tests/unit/test_unit_ontology.py +++ b/libs/labelbox/tests/unit/test_unit_ontology.py @@ -197,7 +197,7 @@ def test_add_ontology_tool() -> None: assert len(o.tools) == 2 for tool in o.tools: - assert type(tool) == Tool + assert type(tool) is Tool with pytest.raises(InconsistentOntologyException) as exc: o.add_tool(Tool(tool=Tool.Type.BBOX, name="bounding box")) @@ -217,7 +217,7 @@ def test_add_ontology_classification() -> None: assert len(o.classifications) == 2 for classification in o.classifications: - assert type(classification) == Classification + assert type(classification) is Classification with pytest.raises(InconsistentOntologyException) as exc: o.add_classification(