fix: Fix add_component() type error with Mypy - #9344
Closed
denisw wants to merge 1 commit into
Closed
Conversation
When calling `pipeline.add_component()` with any component instance, Mypy complains: ``` error: Argument 2 to "add_component" of "PipelineBase" has incompatible type "X"; expected "Component" [arg-type] note: Protocol member Component.run expected settable variable, got read-only attribute ``` The issue is that `run` of the `Component` protocol is currently defined as a mutable attribute (`run: ...`). Use `@property` instead to only require a getter.
Collaborator
Pull Request Test Coverage Report for Build 14846645043Details
💛 - Coveralls |
Contributor
Author
|
Closing as this is already addressed by #9329. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
None, though some
# type: ignorecomments in the codebase demonstrate that the core team hit this issue. :)Proposed Changes:
When calling
pipeline.add_component()with any component instance, Mypy complains:The issue is that
runof theComponentprotocol is currently defined as a mutable attribute (run: ...). Use@propertyinstead to only require a getter.How did you test it?
I ran the type tests with
hatch run test:typesafter making the change.Notes for the reviewer
An additional improvement - and my original goal before I got side-tracked by this - would be to change the required return type of
run()fromDicttoMappingso that it becomes possible to define arun()return type as aTypedDict. I will create a separate follow-up PR for this, though.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.