Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor how we analyse classes (#460)
Currently we analyse `ClassDef` nodes in many different places across the tree in a somewhat scattershot and ad-hoc way. This means that there's a fair amount of duplication currently, and that it can be somewhat awkward to query information about the enclosing class definition when we're visiting a method. This PR thoroughly refactors the way we analyse classes: - It's now all done in one place, the `EnclosingClassContext` class. As well as reducing duplication, this also reduces potential for bugs: e.g. we currently don't detect a protocol as being unused if the protocol is generic (because that's an `ast.Subscript` node in the class's bases tuple, rather than an `ast.Name` or `ast.Attribute` node). - Get rid of the `_get_collections_abc_obj_id` function. It's not really necessary; the name is really unclear; it's an over-abstraction that obfuscates rather than clarifies. - Get rid of the `in_class` nesting counter on the `PyiVisitor` class. This works well to keep track of other contexts when visiting subnodes, but doesn't work well for class definitions: it's no more code to just check whether `self.enclosing_class_ctx is None` or not.
- Loading branch information