Skip to content

Conversation

@lstein
Copy link
Collaborator

@lstein lstein commented Dec 3, 2022

This is a code cleanup enhancement originally contributed by @devops117 which didn't get into the 2.2 release. Reissuing the PR now in order to base against main.

This is a code cleanup enhancement originally contributed by
@devops117 which didn't get into the 2.2 release. Reissuing
the PR now in order to base against main.
}
models.update(
{
name: {
Copy link
Contributor

Choose a reason for hiding this comment

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

The syntax is a new dict that overwrites the existing keys, so this needs quotes.

Suggested change
name: {
'name': {

Copy link

@mebelz mebelz Dec 11, 2022

Choose a reason for hiding this comment

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

I personally don't understand the original change, or psychedelicious's suggestion.
In my opinion, the original change is switching between equivalent ways of updating a dict (the pre-commit being more readable than the commit).
psychedelicious's suggestion changes the code such that the keys to models are only 'name', and it's constantly overwritten.
Anyway I suggest adding a code comment explaining what is the exact merit of the change, for future reference.

Copy link
Contributor

Choose a reason for hiding this comment

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

@psychedelicious is correct; this code will throw an unknown key exception without the quotes.

Having said that, they're "a horse apiece" - using Dict's update() method is more Pythonic, but I find them equally readable, and equally obvious.

Copy link
Contributor

@psychedelicious psychedelicious Dec 11, 2022

Choose a reason for hiding this comment

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

Actually @tildebyte I think @mebelz is correct, name is a variable in this context - the name of the model to be updated. I missed this.

@lstein
Copy link
Collaborator Author

lstein commented Dec 14, 2022

Some of the CI tests are stuck and it isn't worth it to unstick them for this bit of syntactic sugar. So closing.

@lstein lstein closed this Dec 14, 2022
@lstein lstein deleted the devops117-fix-dict-update-in-list-models branch December 14, 2022 22:09
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.

5 participants