Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dangerous_default_value_py30.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # pylint: disable=missing-docstring
  2. HEHE = {}
  3. def function1(value=[]): # [dangerous-default-value]
  4. """docstring"""
  5. return value
  6. def function2(value=HEHE): # [dangerous-default-value]
  7. """docstring"""
  8. return value
  9. def function3(value):
  10. """docstring"""
  11. return value
  12. def function4(value=set()): # [dangerous-default-value]
  13. """set is mutable and dangerous."""
  14. return value
  15. def function5(value=frozenset()):
  16. """frozenset is immutable and safe."""
  17. return value
  18. GLOBAL_SET = set()
  19. def function6(value=GLOBAL_SET): # [dangerous-default-value]
  20. """set is mutable and dangerous."""
  21. return value
  22. def function7(value=dict()): # [dangerous-default-value]
  23. """dict is mutable and dangerous."""
  24. return value
  25. def function8(value=list()): # [dangerous-default-value]
  26. """list is mutable and dangerous."""
  27. return value
  28. def function9(value=[1, 2, 3, 4]): # [dangerous-default-value]
  29. """list with items should not output item values in error message"""
  30. return value
  31. def function10(value={'a': 1, 'b': 2}): # [dangerous-default-value]
  32. """dictionaries with items should not output item values in error message"""
  33. return value
  34. def function11(value=list([1, 2, 3])): # [dangerous-default-value]
  35. """list with items should not output item values in error message"""
  36. return value
  37. def function12(value=dict([('a', 1), ('b', 2)])): # [dangerous-default-value]
  38. """dictionaries with items should not output item values in error message"""
  39. return value
  40. OINK = {
  41. 'a': 1,
  42. 'b': 2
  43. }
  44. def function13(value=OINK): # [dangerous-default-value]
  45. """dictionaries with items should not output item values in error message"""
  46. return value
  47. def function14(value=dict([(1, 2), (1, 2, 3)])): # [dangerous-default-value]
  48. """a dictionary which will not be inferred to a syntax AST, but to an
  49. astroid.Instance.
  50. """
  51. return value
  52. INVALID_DICT = dict([(1, 2), (1, 2, 3)])
  53. def function15(value=INVALID_DICT): # [dangerous-default-value]
  54. """The same situation as function14."""
  55. return value
  56. def function16(value={1}): # [dangerous-default-value]
  57. """set literal as default value"""
  58. return value