Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sqlalchemy type ignores in the backend. #601

Merged
merged 14 commits into from
Jun 7, 2024

Conversation

czaloom
Copy link
Collaborator

@czaloom czaloom commented Jun 7, 2024

Problem Description

The Query object is a major source of type ignores in the backend.

Feature Description

Condense the Query generator object into two strongly typed functions:

  • generate_select
  • generate_query

Additional Context

Before

q = Query(
    models.Label.key,
    models.Label.value,
    models.Prediction.score,
).predictions(as_subquery=False)
q = q.where(models.Prediction.annotation_id == annotation.id)  # type: ignore - SQLAlchemy type issue
labels = [
    schemas.Label(
        key=scored_label[0],
        value=scored_label[1],
        score=scored_label[2],
    )
    for scored_label in db.query(q.subquery()).all()
]

After

query = (
    generate_query(            
        models.Label.key,
        models.Label.value,
        models.Prediction.score,
        db=db,
        label_source=models.Predication,
    )
    .where(models.Prediction.annotation_id == annotation.id)
)
labels = [
    schemas.Label(
        key=scored_label[0],
        value=scored_label[1],
        score=scored_label[2],
    )
    for scored_label in query.all()
]

@czaloom czaloom linked an issue Jun 7, 2024 that may be closed by this pull request
3 tasks
@czaloom czaloom changed the title Remove backend type ignores. Remove sqlalchemy type ignores in the backend. Jun 7, 2024
@czaloom czaloom marked this pull request as ready for review June 7, 2024 18:21
@czaloom czaloom requested review from ntlind and ekorman as code owners June 7, 2024 18:21
@czaloom czaloom merged commit 54c1040 into main Jun 7, 2024
11 checks passed
@czaloom czaloom deleted the czaloom-improve-query-typing branch June 7, 2024 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Type Ignores + Clean query syntax
2 participants