Skip to content

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Apr 23, 2025

Summary

Follow-up on the discussion here. Generally trust undeclared symbols in stubs, not just at the module level.

Test Plan

New Markdown test.

@sharkdp sharkdp added the ty Multi-file analysis & type inference label Apr 23, 2025
@sharkdp sharkdp changed the title [red-knot] Trust *all* symbols in stub files [red-knot] Trust all symbols in stub files Apr 23, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 23, 2025

mypy_primer results

No ecosystem changes detected ✅

@AlexWaygood
Copy link
Member

Oh, I suppose a lot of class-level assignments in typeshed are in the context of enum classes (e.g. https://github.com/python/typeshed/blob/ae57d69c9354147bcf7086d6db47af8f8c82bf7b/stdlib/re.pyi#L201-L221 ), and we infer all attributes on enums as Todo anyway...

@sharkdp
Copy link
Contributor Author

sharkdp commented Apr 23, 2025

I found one example that we do infer differently on this branch! I'm sure it's widely used:

from pdb import Pdb

reveal_type(Pdb.do_b)  # Previously: Unknown | def do_break(self, arg: str, temporary: bool = EllipsisType) -> bool | None
                       # Now:        def do_break(…) -> …

@AlexWaygood
Copy link
Member

This does still feel more consistent to me, so I do support it still!

@sharkdp sharkdp force-pushed the david/trust-undeclared-symbols-in-stubs-pt2 branch from 6f727ff to c00dad7 Compare April 23, 2025 17:57
@sharkdp sharkdp marked this pull request as ready for review April 23, 2025 17:57
Copy link
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.

I think this makes sense as well. Sorry I didn't get through my notifications fast enough to comment on the previous PR sooner!

The core "gradual guarantee" idea that we should not emit false positives on working untyped code, when the user hasn't declared their intentions through type annotations, just doesn't apply to stub files in the same way, since they are inherently somebody explicitly providing type information.

@sharkdp sharkdp merged commit e170fe4 into main Apr 23, 2025
34 checks passed
@sharkdp sharkdp deleted the david/trust-undeclared-symbols-in-stubs-pt2 branch April 23, 2025 18:07
dcreager added a commit that referenced this pull request Apr 23, 2025
* main:
  [red-knot] Handle generic constructors of generic classes (#17552)
  [red-knot] Assignability of class instances to Callable (#17590)
  [red-knot] Trust all symbols in stub files (#17588)
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.

4 participants