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

Simplify populating each target's classes list in ReclassInventory #1126

Merged
merged 1 commit into from
Jan 27, 2024

Conversation

simu
Copy link
Contributor

@simu simu commented Jan 27, 2024

There's no need to reconstruct the list of classes for each target. Reclass provides this information in rendered_target["classes"] already.

This commit removes the loop which reconstructs the list and replaces it by assigning rendered_target["classes"] to the target's classes field.

Side-note: the previous implementation also mangled the list, because Python implements += for lists as list concatenation, and (not so helpfully) treats strings as lists of characters when they appear in a context where a list is expected. To correctly construct the list of classes with the previous approach, the += should be replaced with append:

self.targets[target_name].classes.append(class_name)

Docs and Tests

  • Tests added
  • Updated documentation

There's no need to reconstruct the list of classes for each target.
Reclass provides this information in `rendered_target["classes"]`
already.

This commit removes the loop which reconstructs the list and replaces
it by assigning `rendered_target["classes"]` to the target's `classes`
field.

Side-note: the previous implementation also mangled the list, because
Python implements `+=` for lists as list concatenation, and (not so
helpfully) treats strings as lists of characters when they appear in a
context where a list is expected. To correctly construct the list of
classes with the previous approach, the `+=` should be replaced with
append:

```python
self.targets[target_name].classes.append(class_name)
```
Copy link
Contributor

@MatteoVoges MatteoVoges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not aware of reclass storing this already in the target. Thanks 😃

@MatteoVoges MatteoVoges merged commit 94687b6 into kapicorp:master Jan 27, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants