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

Accordion style merge issue fix #2446

Merged
merged 4 commits into from Jan 26, 2024
Merged

Conversation

ElijahAhianyo
Copy link
Collaborator

@ElijahAhianyo ElijahAhianyo commented Jan 24, 2024

return the var is the var to be merged is None

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

the hesitation here is that the function now has two different behaviors:

  1. if other is not None, then we get a new Var
  2. if other is None, then we get the same Var

Code that is using ._merge shouldn't have to worry about whether the returned value can be safely mutated or not.

To keep both code paths consistent, i'd suggest return self._replace(), so that _merge always returns a new Var

@ElijahAhianyo
Copy link
Collaborator Author

the hesitation here is that the function now has two different behaviors:

  1. if other is not None, then we get a new Var
  2. if other is None, then we get the same Var

Code that is using ._merge shouldn't have to worry about whether the returned value can be safely mutated or not.

To keep both code paths consistent, i'd suggest return self._replace(), so that _merge always returns a new Var

Got it, thats interesting, what are the repercussions in returning same var vs new var though?

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

what are the repercussions in returning same var vs new var though

Var is a mutable object; so if i call ._merge and then change _var_is_local or some other attribute, i wouldn't expect that to actually change any of the input Var.

This is fresh in my mind because I just fixed #2421 which was a result of almost this same thing, except in the .create path, where if the object you're creating a Var from is already a Var, then the original object is returned directly as-is. I didn't change how .create works in that PR, because it's been like that for a long time, but we should avoid introducing new ways to shoot one's foot in a similar vein.

@picklelo picklelo merged commit aad009e into main Jan 26, 2024
45 checks passed
@picklelo picklelo deleted the elijah/accordion-style-merge-fix branch January 30, 2024 03:11
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

3 participants