Content-Length: 433704 | pFad | http://github.com/astral-sh/ruff/pull/16765

71 Add invalid type expressions. by MatthewMckee4 · Pull Request #16765 · astral-sh/ruff · GitHub
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

Add invalid type expressions. #16765

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

MatthewMckee4
Copy link

Expand InvalidTypeExpression enum to include number, bytes and boolean in type expression

Summary

Fixes #16532

Test Plan

Still need to look into where tests should be put for this improvement

Expand `InvalidTypeExpression` enum to include number, bytes and boolean in type expression
@MatthewMckee4
Copy link
Author

I may be wrong, but it seems that byte literals are already handled here:

ast::Expr::BytesLiteral(bytes) => {
self.context.report_lint(
&BYTE_STRING_TYPE_ANNOTATION,
bytes,
format_args!("Type expressions cannot use bytes literal"),
);
TypeAndQualifiers::unknown()
}
.

And tested here:

# error: [byte-string-type-annotation] "Type expressions cannot use bytes literal"
i: "b'int'",

@AlexWaygood AlexWaygood added the red-knot Multi-file analysis & type inference label Mar 15, 2025
@MatthewMckee4
Copy link
Author

There's now a test failing at

I think this is expected though, as the generics are not implemented for SpecialForm i think?

@MatthewMckee4 MatthewMckee4 marked this pull request as ready for review March 16, 2025 12:41
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! I think you're mostly on the right track, but there's a few issues here to sort out

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Looks close!

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

looks great, thank you!

MatthewMckee4 and others added 2 commits March 16, 2025 22:22
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@AlexWaygood
Copy link
Member

I'll wait until our CI's back up and running before merging this (everything's disabled at the moment due to #16768, we should get it up again tomorrow)

@MatthewMckee4
Copy link
Author

Sounds good, thank you for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[red-knot] Raise "invalid type expression" error for literal types
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/astral-sh/ruff/pull/16765

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy