Skip to content

Bug: dict.copy() always returns None #33

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

Closed

Conversation

Humbedooh
Copy link
Member

We need the merged defaults copy returned to us, so the old return is instead split into three commands:

  • copy defaults
  • update the copy with match.groupdict()
  • return the updated copy

We need the merged defaults copy returned to us, so the old return is instead split into three commands:

- copy `defaults`
- update the copy with `match.groupdict()`
- return the updated copy
@brainy
Copy link
Member

brainy commented Jul 8, 2025

Eh? dict.copy() does not return None. dict.update() does.

@netomi
Copy link
Member

netomi commented Jul 8, 2025

the original code returns the result of update which is None. So you need to remember the result from copy, update that, and return it.

@brainy
Copy link
Member

brainy commented Jul 8, 2025

Yes, yes, the title of the PR is just wrong.

return defaults.copy().update(match.groupdict())
merged_defaults = defaults.copy()
merged_defaults.update(match.groupdict())
return merged_defaults
Copy link
Member

@brainy brainy Jul 8, 2025

Choose a reason for hiding this comment

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

It you can guarantee this is Python 3.5+ (which it should be, 3.6 is EOL), then:

return {**defaults, **match.groupdict()}

Otherwise, the above works with Python 2, too.

Copy link
Member

Choose a reason for hiding this comment

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

Please, no Perl code. 😉

asfgit pushed a commit that referenced this pull request Jul 8, 2025
* tools/hook-scripts/mailer/mailer.py
  (Config._prep_groups::repos_params): If there's a match for the
   repository configuration, copy the defaults dict and update it
   in place before returning the new dict.

Patch by: humbedooh


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1927075 13f79535-47bb-0310-9956-ffa450edef68
@brainy
Copy link
Member

brainy commented Jul 8, 2025

Committed a slightly tweaked patch in r1927075.

asfgit pushed a commit that referenced this pull request Jul 8, 2025
  (Config.repos_params): don't use "defaults" for the merged values.
    The comments make this confusing. Use "merged" for clarity.

[ related to PR #33 ]


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1927078 13f79535-47bb-0310-9956-ffa450edef68
@gstein
Copy link
Member

gstein commented Jul 8, 2025

Re-using the "defaults" variable for other purposes made the code confusing, especially with the "fall through" to where the comment mentions nothing to add.

I used Daniel's original form, with a new dict named "merged" which is explicitly returned in the if-branch.

@Humbedooh Humbedooh closed this Jul 8, 2025
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.

4 participants