add pyright as part of pre-commit (but disable it for now due to failing type check)

This commit is contained in:
Abi Raja 2024-03-05 13:50:55 -05:00
parent a7e51f6f1a
commit 3a23d9eae3
4 changed files with 21 additions and 14 deletions

View File

@ -16,3 +16,10 @@ repos:
pass_filenames: false pass_filenames: false
always_run: true always_run: true
files: ^backend/ 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/

View File

@ -15,7 +15,7 @@ async def process_tasks(prompts: List[str], api_key: str, base_url: str):
print(f"An exception occurred: {result}") print(f"An exception occurred: {result}")
processed_results.append(None) processed_results.append(None)
else: else:
processed_results.append(result) processed_results.append(result) # type: ignore
return processed_results return processed_results
@ -30,7 +30,7 @@ async def generate_image(prompt: str, api_key: str, base_url: str):
"size": "1024x1024", "size": "1024x1024",
"prompt": prompt, "prompt": prompt,
} }
res = await client.images.generate(**image_params) res = await client.images.generate(**image_params) # type: ignore
await client.close() await client.close()
return res.data[0].url return res.data[0].url
@ -77,26 +77,26 @@ async def generate_images(
img["src"].startswith("https://placehold.co") img["src"].startswith("https://placehold.co")
and image_cache.get(img.get("alt")) is None 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 # 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 # Remove duplicates
prompts = list(set(alts)) prompts = list(set(alts)) # type: ignore
# Return early if there are no images to replace # Return early if there are no images to replace
if len(prompts) == 0: if len(prompts) == 0: # type: ignore
return code return code
# Generate images # 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 # 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 # 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 # Replace old image URLs with the generated URLs
for img in images: for img in images:

8
backend/poetry.lock generated
View File

@ -592,13 +592,13 @@ email = ["email-validator (>=1.0.3)"]
[[package]] [[package]]
name = "pyright" name = "pyright"
version = "1.1.345" version = "1.1.352"
description = "Command line wrapper for pyright" description = "Command line wrapper for pyright"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "pyright-1.1.345-py3-none-any.whl", hash = "sha256:00891361baf58698aa660d9374823d65782823ceb4a65515ff5dd159b0d4d2b1"}, {file = "pyright-1.1.352-py3-none-any.whl", hash = "sha256:0040cf173c6a60704e553bfd129dfe54de59cc76d0b2b80f77cfab4f50701d64"},
{file = "pyright-1.1.345.tar.gz", hash = "sha256:bb8c80671cdaeb913142b49642a741959f3fcd728c99814631c2bde3a7864938"}, {file = "pyright-1.1.352.tar.gz", hash = "sha256:a621c0dfbcf1291b3610641a07380fefaa1d0e182890a1b2a7f13b446e8109a9"},
] ]
[package.dependencies] [package.dependencies]
@ -1088,4 +1088,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "6fa98703309c862dd33d9d9ce210b71bfcb37e7d7ff030198d9044d83c249060" content-hash = "17d8bb6d9e4a392f2512e4265df564708d59c1d83b26146f23e2595b6764c711"

View File

@ -19,7 +19,7 @@ anthropic = "^0.18.0"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
pytest = "^7.4.3" pytest = "^7.4.3"
pyright = "^1.1.345" pyright = "^1.1.352"
[build-system] [build-system]
requires = ["poetry-core"] requires = ["poetry-core"]