From 3a23d9eae31dcf83e00a9796db870fb9bc3d4478 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Tue, 5 Mar 2024 13:50:55 -0500 Subject: [PATCH] add pyright as part of pre-commit (but disable it for now due to failing type check) --- backend/.pre-commit-config.yaml | 7 +++++++ backend/image_generation.py | 18 +++++++++--------- backend/poetry.lock | 8 ++++---- backend/pyproject.toml | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/backend/.pre-commit-config.yaml b/backend/.pre-commit-config.yaml index 9a495ad..b54da93 100644 --- a/backend/.pre-commit-config.yaml +++ b/backend/.pre-commit-config.yaml @@ -16,3 +16,10 @@ repos: pass_filenames: false always_run: true files: ^backend/ + # - id: poetry-pyright + # name: Run pyright with Poetry + # entry: poetry run --directory backend pyright + # language: system + # pass_filenames: false + # always_run: true + # files: ^backend/ diff --git a/backend/image_generation.py b/backend/image_generation.py index d3e71b1..b93792c 100644 --- a/backend/image_generation.py +++ b/backend/image_generation.py @@ -15,7 +15,7 @@ async def process_tasks(prompts: List[str], api_key: str, base_url: str): print(f"An exception occurred: {result}") processed_results.append(None) else: - processed_results.append(result) + processed_results.append(result) # type: ignore return processed_results @@ -30,7 +30,7 @@ async def generate_image(prompt: str, api_key: str, base_url: str): "size": "1024x1024", "prompt": prompt, } - res = await client.images.generate(**image_params) + res = await client.images.generate(**image_params) # type: ignore await client.close() return res.data[0].url @@ -77,26 +77,26 @@ async def generate_images( img["src"].startswith("https://placehold.co") and image_cache.get(img.get("alt")) is None ): - alts.append(img.get("alt", None)) + alts.append(img.get("alt", None)) # type: ignore # Exclude images with no alt text - alts = [alt for alt in alts if alt is not None] + alts = [alt for alt in alts if alt is not None] # type: ignore # Remove duplicates - prompts = list(set(alts)) + prompts = list(set(alts)) # type: ignore # Return early if there are no images to replace - if len(prompts) == 0: + if len(prompts) == 0: # type: ignore return code # Generate images - results = await process_tasks(prompts, api_key, base_url) + results = await process_tasks(prompts, api_key, base_url) # type: ignore # Create a dict mapping alt text to image URL - mapped_image_urls = dict(zip(prompts, results)) + mapped_image_urls = dict(zip(prompts, results)) # type: ignore # Merge with image_cache - mapped_image_urls = {**mapped_image_urls, **image_cache} + mapped_image_urls = {**mapped_image_urls, **image_cache} # type: ignore # Replace old image URLs with the generated URLs for img in images: diff --git a/backend/poetry.lock b/backend/poetry.lock index 53e5215..663f7a2 100644 --- a/backend/poetry.lock +++ b/backend/poetry.lock @@ -592,13 +592,13 @@ email = ["email-validator (>=1.0.3)"] [[package]] name = "pyright" -version = "1.1.345" +version = "1.1.352" description = "Command line wrapper for pyright" optional = false python-versions = ">=3.7" files = [ - {file = "pyright-1.1.345-py3-none-any.whl", hash = "sha256:00891361baf58698aa660d9374823d65782823ceb4a65515ff5dd159b0d4d2b1"}, - {file = "pyright-1.1.345.tar.gz", hash = "sha256:bb8c80671cdaeb913142b49642a741959f3fcd728c99814631c2bde3a7864938"}, + {file = "pyright-1.1.352-py3-none-any.whl", hash = "sha256:0040cf173c6a60704e553bfd129dfe54de59cc76d0b2b80f77cfab4f50701d64"}, + {file = "pyright-1.1.352.tar.gz", hash = "sha256:a621c0dfbcf1291b3610641a07380fefaa1d0e182890a1b2a7f13b446e8109a9"}, ] [package.dependencies] @@ -1088,4 +1088,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "6fa98703309c862dd33d9d9ce210b71bfcb37e7d7ff030198d9044d83c249060" +content-hash = "17d8bb6d9e4a392f2512e4265df564708d59c1d83b26146f23e2595b6764c711" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 8c64b3f..14009f6 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -19,7 +19,7 @@ anthropic = "^0.18.0" [tool.poetry.group.dev.dependencies] pytest = "^7.4.3" -pyright = "^1.1.345" +pyright = "^1.1.352" [build-system] requires = ["poetry-core"]