Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Dangerous default value [] as argument

未关闭
#458 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
python
领域
backend

调研方向

从 PR #456 开始,在 Python 代码库中搜索默认值为 [] 的函数参数。使用此 issue 中的 Test 示例来理解共享状态 bug,并确认哪些出现位置属于范围之内。当预期的可变列表默认值使用安全初始化且现有测试套件通过时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

bug

This issue came up in PR #456.

I wasn't really aware of this issue ... thought it would be just coding style. We should open an issue and fix it in a new PR, maybe like this:

def __init__(self, some_list=None):
    self.some_list = some_list or []

Codacy is giving me "Dangerous default value [] as argument" but this happens a lot elsewhere. I agree this should be changed, but maybe not in this PR...

I think this should really be changed, because this can lead to very hard to find bugs:

class Test:
    def __init__(self, some_list=[]):
        self.some_list = some_list


t1 = Test()
t2 = Test()

t2.some_list.append(1)
print(t1.some_list)  # prints [1]

Originally posted by @cehbrecht in https://github.com/geopython/pywps/pull/456#issuecomment-471551513

主要语言
Python
星标
186
派生
116
平均合并
11 天 20 小时
30 天内合并 PR
1

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

geopython/pywps 的其他 Issue

查看 geopython/pywps 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。