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

[red-knot] ... should be treated as a valid parameter default for any annotation in a stub file #14840

Closed
AlexWaygood opened this issue Dec 8, 2024 · 2 comments · Fixed by #14982
Assignees
Labels
bug Something isn't working help wanted Contributions especially welcome red-knot Multi-file analysis & type inference
Milestone

Comments

@AlexWaygood
Copy link
Member

The typing spec states that in stub files:

In locations where value expressions can appear, such as the right-hand side of assignment statements and function parameter defaults, type checkers should support the following expressions:

  • The ellipsis literal, ..., which can stand in for any value

Following #14802, we now have a huge number of false positives when running red-knot directly over stub files, due to the fact that we don't yet implement this special case, which is very commonly utilised in stubs. E.g. here's a small portion of the errors emitted when running red-knot over typeshed:

error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:118:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:158:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `str`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:159:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:197:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `str`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:198:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:237:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:239:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:240:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:258:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:259:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:260:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `socket`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:276:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:278:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:279:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:296:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:297:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:298:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `socket`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:313:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:315:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:316:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:332:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:333:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `int`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:334:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `socket`
error[invalid-parameter-default] /Users/alexw/dev/typeshed/stdlib/asyncio/base_events.pyi:414:13 Default value of type `EllipsisType | ellipsis` is not assignable to annotated parameter type `bool | None`
@AlexWaygood AlexWaygood added bug Something isn't working red-knot Multi-file analysis & type inference labels Dec 8, 2024
@carljm carljm added this to the Red Knot 2024 milestone Dec 10, 2024
@carljm carljm added the help wanted Contributions especially welcome label Dec 10, 2024
@Glyphack
Copy link
Contributor

I want to work on this, what command did you run to get the output? I tried passing typeshed pass to --current-directory but I get a panic.

@AlexWaygood
Copy link
Member Author

I want to work on this, what command did you run to get the output? I tried passing typeshed pass to --current-directory but I get a panic.

On Ruff's main branch, with a local clone of typeshed at ../typeshed (relative to my Ruff repository), I ran cargo run -p red_knot --curent-directory ../typeshed. I didn't get a panic, just a huge number of diagnostics. (Many of the diagnostics emitted are true positives, since typeshed has a very unconventional directory structure. I wouldn't expect red-knot to be able to resolve a lot of the imports in typeshed's third-party stubs, for example. But none of the ...-related errors are true positives.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions especially welcome red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants