Skip to content

Commit

Permalink
[feat] Disable pyright checking field Pydantic field aliases (#102)
Browse files Browse the repository at this point in the history
Why
===

If we ignore the alias field, we can use pyright to typecheck python
generated clients.

What changed
============

Reflow the field assignment to permit ignoring type aliases like
`alias="$kind"`

Test plan
=========

Manually ran against production services, typechecked OK
  • Loading branch information
blast-hardcheese authored Oct 25, 2024
1 parent 988c540 commit 1c06a0b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions replit_river/codegen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,26 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
if name not in type.required:
value = ""
if base_model != "TypedDict":
value = f" = Field(default=None, alias='{name}')"
value = dedent(
f"""\
= Field(
default=None,
alias='{name}', # type: ignore
)
"""
)
current_chunks.append(f" kind: Optional[{type_name}]{value}")
else:
value = ""
if base_model != "TypedDict":
value = f" = Field({field_value}, alias='{name}')"
value = dedent(
f"""\
= Field(
{field_value},
alias='{name}', # type: ignore
)
"""
)
current_chunks.append(f" kind: {type_name}{value}")
else:
if name not in type.required:
Expand Down

0 comments on commit 1c06a0b

Please sign in to comment.