-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
improve type safety when using NodeMatcher #12034
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
Conversation
|
Are any of the affected callsites recursive methods? What I'm thinking: an additional frame/entry on the stack (for the intermediate method call) is usually likely to have negligible effect for a call-and-return, but within a deeply recursive method it could have a significant effect on memory usage. |
picnixz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me but can you confirm that self.document is of correct type actually ? (what is the revealed type?) because I remember that mypy was not happy sometimes because of the fact that self.document was not typed at all (and did not exist on SphinxTransform).
i'm making some changes to the type stubs upstream in typeshed that should help with this |
|
Thank you! |
From a relatively quick check of the code: no, none of the affected methods are recursive. |
Improve type safety by refactoring the
NodeMatcher.Mypy is unable to infer the return type of the
Node.find_allmethod whenNodeMatcheris used. By moving the helper method into theNodeMatcherclass and adding some generics it's possible for type checkers to correctly infer the return type of the iterator.I've noticed that a matcher rarely gets reused, so an alternative approach would be to get rid of the helper class entirely and turn it into a plain function.