Skip to content

[red-knot] Fix type inference for except* definitions#13320

Merged
AlexWaygood merged 2 commits intomainfrom
alex/async-except
Sep 11, 2024
Merged

[red-knot] Fix type inference for except* definitions#13320
AlexWaygood merged 2 commits intomainfrom
alex/async-except

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

Once again, async Python requires different inference rules to sync Python!

A new DefinitionNodeRef::ExceptStarHandler variant is introduced, so that we can differentiate between except-handler definitions in StmtTry { is_star: true } nodes and those in StmtTry { is_star: false } nodes. The logic for adding these definitions is also moved in builder.rs so that we can know whether the try block is catching exceptions or exception groups. (We'll need to move the logic there anyway when adding control flow for these definitions.)

Lots of TODOs here, but I think inferring Instance(BaseExceptionGroup) is better than just inferring Unknown for these definitions.

The PR is stacked on top of #13319

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Sep 10, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 10, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Base automatically changed from alex/redknot-to-instance to main September 10, 2024 22:41
Copy link
Copy Markdown
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@AlexWaygood AlexWaygood merged commit 4dc2c25 into main Sep 11, 2024
@AlexWaygood AlexWaygood deleted the alex/async-except branch September 11, 2024 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants