- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: python-security/no-empty-list-as-parameter
Language: Python
Severity: Warning
Category: Security
Developers should not be setting a default argument to an empty list. Instead, use None
and check if the value is defined. Using a default list can cause unwanted behavior as the value of the argument is only evaluated once when the function is defined, not when it is run. Because of this, each function call will reference the same underlying memory when the default value is used, which can lead to unwanted behavior.
def newFunction(arg1, arg2: int, arg3 = [], arg4: MyType = []): # do not use an empty list as a default parameter
arg3.append(arg2)
arg4.append(arg1)
print(arg3, arg4)
newFunction('a', 1)
newFunction('b', 2)
newFunction('c', 3)
# Will print:
# [1] ['a']
# [1, 2] ['a', 'b']
# [1, 2, 3] ['a', 'b', 'c']
def newFunction(arg1, arg2: int, arg3 = None, arg4 = None): # do not use an empty list as a default parameter
if arg3 is None:
arg3 = []
if arg4 is None:
arg4 = []
arg3.append(arg2)
arg4.append(arg1)
print(arg3, arg4)
newFunction('a', 1)
newFunction('b', 2)
newFunction('c', 3)
# Will print:
# [1] ['a']
# [2] ['b']
# [3] ['c']
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products