Title: Add new gotcha · Issue #1158 · realpython/python-guide · GitHub
Open Graph Title: Add new gotcha · Issue #1158 · realpython/python-guide
X Title: Add new gotcha · Issue #1158 · realpython/python-guide
Description: Hi, While running tests on my code I was doing something like: class Data: mylist = [1,2,3,4] def test_function(): local_list = Data.mylist local_list+=new_list # Do stuff with and there are multiple tests using mylist. This is going to ...
Open Graph Description: Hi, While running tests on my code I was doing something like: class Data: mylist = [1,2,3,4] def test_function(): local_list = Data.mylist local_list+=new_list # Do stuff with and there are multip...
X Description: Hi, While running tests on my code I was doing something like: class Data: mylist = [1,2,3,4] def test_function(): local_list = Data.mylist local_list+=new_list # Do stuff with and there are multip...
Opengraph URL: https://github.com/realpython/python-guide/issues/1158
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add new gotcha","articleBody":"Hi,\n\nWhile running tests on my code I was doing something like:\n\n```python\nclass Data:\n mylist = [1,2,3,4]\n\n\ndef test_function():\n local_list = Data.mylist\n local_list+=new_list\n\n # Do stuff with \n```\n\nand there are multiple tests using `mylist`. This is going to modify the list instead of creating a new one, an unexpected behavior of `+=`. This will let one test talk to the tests happening later. The safer approach is:\n\n```python\nclass Data:\n mylist = [1,2,3,4]\n\n\ndef test_function():\n local_list =new_list + Data.mylist\n\n # Do stuff with \n```\n\nhere `+` will copy the list. Could you please add this case?\n\nCheers.","author":{"url":"https://github.com/acampove","@type":"Person","name":"acampove"},"datePublished":"2025-05-18T15:14:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1158/python-guide/issues/1158"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8cf458f6-3a29-9273-71af-190174d5d09a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C4FA:24328B:7BE1452:A1B2DF7:696DB8ED |
| html-safe-nonce | 7483f73913fb8be7fbd743d11a2c85cc81f81b9457adbbf1c3a2f07ca880b872 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEZBOjI0MzI4Qjo3QkUxNDUyOkExQjJERjc6Njk2REI4RUQiLCJ2aXNpdG9yX2lkIjoiMTkwNTE0MDY3NDE0Mjc3OTYyOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c729c7a70987467357114e7c482d7e8148408df1afd9c89f49605b0d8fc9d89f |
| hovercard-subject-tag | issue:3071858564 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/realpython/python-guide/1158/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dac27da5997a7f22ec1222218d49cf576fee461fcd1df9207a4a4e741bda1b44/realpython/python-guide/issues/1158 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dac27da5997a7f22ec1222218d49cf576fee461fcd1df9207a4a4e741bda1b44/realpython/python-guide/issues/1158 |
| og:image:alt | Hi, While running tests on my code I was doing something like: class Data: mylist = [1,2,3,4] def test_function(): local_list = Data.mylist local_list+=new_list # Do stuff with and there are multip... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | acampove |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064 |
| turbo-cache-control | no-preview |
| go-import | github.com/realpython/python-guide git https://github.com/realpython/python-guide.git |
| octolytics-dimension-user_id | 5448020 |
| octolytics-dimension-user_login | realpython |
| octolytics-dimension-repository_id | 1481305 |
| octolytics-dimension-repository_nwo | realpython/python-guide |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1481305 |
| octolytics-dimension-repository_network_root_nwo | realpython/python-guide |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7e5ae23c70136152637ceee8d6faceb35596ec46 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width