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

Slots added to many classes, but not their bases #574

Closed
ariebovenberg opened this issue Jan 3, 2022 · 3 comments · Fixed by #615
Closed

Slots added to many classes, but not their bases #574

ariebovenberg opened this issue Jan 3, 2022 · 3 comments · Fixed by #615
Labels
enhancement New feature or request

Comments

@ariebovenberg
Copy link
Contributor

ariebovenberg commented Jan 3, 2022

👋 Hi there!

I found you use add_slots to add slots to a lot of classes (e.g. libcst._nodes.expression.Annotation). However, it seems __slots__ is not present in many of their base classes (e.g. libcst._nodes.base.CSTNode), meaning the benefits are reduced.

Unless I'm missing something, we should be able to fix this for a free performance boost!

If you agree, I'd be happy to submit a PR

edit: a full list of slotless bases:

       - libcst._nodes.base.BaseLeaf
       - libcst._nodes.base.BaseValueToken
       - libcst._nodes.base.CSTNode
       - libcst._nodes.expression.BaseAssignTargetExpression
       - libcst._nodes.expression.BaseComp
       - libcst._nodes.expression.BaseDelTargetExpression
       - libcst._nodes.expression.BaseDict
       - libcst._nodes.expression.BaseDictElement
       - libcst._nodes.expression.BaseElement
       - libcst._nodes.expression.BaseExpression
       - libcst._nodes.expression.BaseFormattedStringContent
       - libcst._nodes.expression.BaseList
       - libcst._nodes.expression.BaseNumber
       - libcst._nodes.expression.BaseSet
       - libcst._nodes.expression.BaseSimpleComp
       - libcst._nodes.expression.BaseSlice
       - libcst._nodes.expression.BaseString
       - libcst._nodes.expression._BaseElementImpl
       - libcst._nodes.expression._BaseExpressionWithArgs
       - libcst._nodes.expression._BaseParenthesizedNode
       - libcst._nodes.expression._BasePrefixedString
       - libcst._nodes.expression._BaseSetOrDict
       - libcst._nodes.op.BaseAugOp
       - libcst._nodes.op.BaseBinaryOp
       - libcst._nodes.op.BaseBooleanOp
       - libcst._nodes.op.BaseCompOp
       - libcst._nodes.op.BaseUnaryOp
       - libcst._nodes.op._BaseOneTokenOp
       - libcst._nodes.op._BaseTwoTokenOp
       - libcst._nodes.statement.BaseCompoundStatement
       - libcst._nodes.statement.BaseSmallStatement
       - libcst._nodes.statement.BaseStatement
       - libcst._nodes.statement.BaseSuite
       - libcst._nodes.statement._BaseSimpleStatement
       - libcst._nodes.whitespace.BaseParenthesizableWhitespace
       - libcst._parser.types.config.BaseWhitespaceParserConfig
@zsol
Copy link
Member

zsol commented Jan 5, 2022

Thanks for checking! Yes, I'd be happy to review a PR :) I wonder if we could build a linter to run automatically as part of CI for this. Maybe something using https://github.com/instagram/fixit ?

@zsol zsol added the enhancement New feature or request label Jan 5, 2022
@ariebovenberg
Copy link
Contributor Author

Hi! Well, I found these errors because that's exactly what I'm building myself, haha. Found some mistakes in the stdlib even 👀

I'm assuming fixit is a static analysis tool? I've found it's quite challenging to trace inheritance with all the import shenanigans many libraries use. So in the end it's a runtime checker.

@zsol
Copy link
Member

zsol commented Jan 6, 2022

I'm assuming fixit is a static analysis tool? I've found it's quite challenging to trace inheritance with all the import shenanigans many libraries use. So in the end it's a runtime checker.

Hmm, fair enough. If you make a pre-commit hook, I'm happy to include that in our dev/CI process after we've fixed all the offending classes listed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants