Vector - Support Single-Pass Iterables#275
Merged
hunter-ni merged 4 commits intoJun 2, 2026
Merged
Conversation
…an only be iterated once. Signed-off-by: Hunter Kennon hunter.kennon@emerson.com
Contributor
Test Results 50 files + 1 50 suites +1 19m 51s ⏱️ +45s Results for commit c6b51ad. ± Comparison against base commit 602a649. This pull request removes 2 and adds 19 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
hunter-ni
commented
May 28, 2026
There was a problem hiding this comment.
Pull request overview
This PR updates Vector to correctly handle single-pass iterables, such as generators, during construction and slice assignment.
Changes:
- Materializes constructor input before validation to avoid exhausting generators.
- Materializes non-
Sequenceslice assignment inputs before validation/assignment. - Adds unit tests for generator inputs in
__init__and__setitem__.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/nitypes/vector.py |
Updates Vector initialization and slice assignment to support single-pass iterables. |
tests/unit/vector/test_vector.py |
Adds generator-based tests and renames a couple of existing test cases for consistency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Hunter Kennon hunter.kennon@emerson.com
… order of set elements in string representation Signed-off-by: Hunter Kennon hunter.kennon@emerson.com
csjall
approved these changes
Jun 1, 2026
bkeryan
approved these changes
Jun 1, 2026
Collaborator
bkeryan
left a comment
There was a problem hiding this comment.
Approved with suggestions
Signed-off-by: Hunter Kennon hunter.kennon@emerson.com
csjall
approved these changes
Jun 2, 2026
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.
What does this Pull Request accomplish?
This set of changes updates the
Vectordata type so that bothVectorinitialization and__setitem__support as inputIterableobjects that can only be successfully iterated a single time, such as generator functions.Prior to these changes, the behaviors of
Vectorwere the following:__init__:__setitem__:In essence, because the
Iterablebeing supplied to__init__or__setitem__in these scenarios only supports being iterated once and the implementations of these methods were iterating over the providedIterabletwice, first for data validation and then again for actual value assignment, the actual value assignment was reading anIterablethat had already been exhausted. As a result, supplying anIterableof such a form resulted in behavior as if an emptyIterablehad been supplied into the method in question.Since the
Vectordata type provides a type hint indicating thatIterable[TScalar]is the expected type for thevalues/valueparameter in these cases, we should be robust in handling allIterables (including single-pass ones).Implementation
__init__to create alistof the suppliedvaluesbefore iterating through these values and performing element-level validation on them, rather than doing so after this validation has taken place__setitem__to create alistwrapper for the incomingIterableif theIterableis not aSequence(and we cannot be assured of multi-pass iteration support)Why should this Pull Request be merged?
This PR addresses a behavioral issue in which
Vectorwas not handling certain types ofIterables as input in an intuitive or expected manner.What testing has been done?
Added new test cases in
test_vector.pycovering usage of single-pass iterables with__init__and__setitem__