-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[red-knot] @override lint rule #11282
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
|
MichaReiser
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.
Nice that you managed to get this rule working for today!
I think this PR shows a few issues that we need to address:
SemanticLintContextprobably must be generic overDbto prevent that we need to leak the internal storage layout on theDatabaseAPI. We should solve this as part of this PR.- Our Database is somewhat awkward because it requires setting the right
HasJarandSemanticDbtype bounds. I think salsa doesn't have this problem because it can fallback to theHasJarDyntrait to resolve an ingredient. We need a better solution for that, but that's out of scope for this PR - My ultimate goal was to prevent that lint rules get access to
dband instead force them to go through the context. I can see now how this is challenging with e.g.FunctionTypeId::nametaking adbas argument. I still think that not giving lint rules access to thedbis desired, but I'm not aware of a good solution right now. - This is related to not giving access to
dbto the semantic lint rules. I think that it's very easy today to mix local ids from different files. Ideally, lint rules would only ever get local ids for the current file or otherwise global ids.
|
Thanks for the review!
Why does using a trait object db require us to leak the internal storage layout on the database API? I think it led to that in this PR just because I was cutting corners to get things working, but I don't think it requires it. Instead it requires that all data access we need available to lint rules must be implemented as queries on the Db trait interface. These queries don't need to leak implementation details, but it will mean there will be a lot of them. In some ways it seems like making everything generic over Db has more risk of leaking internals, because it means that the full (I don't have strong opinions here, I'm still working out the pros and cons of different patterns and trying to understand the reasoning for different options.)
Yes, I think this will be pretty challenging with the interning-based storage approach, because pretty much anything you might want to do requires a db.
Yeah, I agree we should try to avoid this footgun, though it's not clear to me how to actually make it impossible. (Even a global ID will contain local IDs, and making those inaccessible will make those global IDs quite difficult or impossible to use in the code that actually needs to break them apart to do the queries. Maybe we can address this with crate visibility boundaries, if in future we break lint rules into a separate crate from the db.) |
|
Addressed most review comments. Would like to discuss this more, as the right path isn't clear to me:
|
Co-authored-by: Micha Reiser <[email protected]>
Summary
Lots of TODOs and things to clean up here, but it demonstrates the working lint rule.
Test Plan
(We provide our own
typing.pysince we don't have typeshed vendored or type stub support yet.)If we add
def method(self): passto classBinbase.pyand run red_knot again, there is no lint error.