rules:
- id: attr-mutable-initializer
  patterns:
  - pattern-not-inside: |
      def $Y(...):
        ...
  - pattern-not-inside: |
      def $Y(...) -> $TYPE:
        ...
  - pattern-inside: |
      @attr.s(...,auto_attribs=True, ...)
      class $X(...):
        ...
  - pattern-either:
    - pattern: |
        $M = {...}
    - pattern: $M = [...]
    - pattern: $M = list(...)
    - pattern: $M = set(...)
    - pattern: $M = dict(...)
  message: >-
    Unsafe usage of mutable initializer with attr.s decorator.
    Multiple instances of this class will re-use the same data structure, which is likely not the desired behavior.
    Consider instead: replace assignment to mutable initializer (ex. dict() or {}) with attr.ib(factory=type) where type is dict, set, or list
  severity: WARNING
  languages:
  - python
  metadata:
    category: correctness
    technology:
    - attr
