Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

remove mutable default argument in prototype __deepcopy__ method#9

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
neochief merged 1 commit intoRefactoringGuru:masterfromsantunioni:master
Jan 12, 2022

Conversation

@santunioni
Copy link
Contributor

@santunionisantunioni commentedJan 2, 2022
edited
Loading

We should not use mutable objects as default arguments in python functions/methods, so I fixed it in the prototype class.

Before the change:
Every time we called the__deepcopy__ method (actually called by python when you use copy.deepcopy) without the memo argument, the same dict instance was being used. This happens because default arguments are instantiated atload-module time. Leads to dangerous behaviour: if you update the dict in some method-call, you will use the same updated dict in another calls.

Now:
The memo dict is created in every call without the memo argument.

ps: no changes to Output.txt are required

@neochiefneochief merged commit4fbd03c intoRefactoringGuru:masterJan 12, 2022
@neochief
Copy link
Contributor

Thanks a lot!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@santunioni@neochief

[8]ページ先頭

©2009-2025 Movatter.jp