python.lang.maintainability.useless-literal-set.useless-literal-set

profile photo of semgrepsemgrep
Author
unknown
Download Count*

$X is uselessly assigned twice inside the creation of the set

Run Locally

Run in CI

Defintion

rules:
  - id: useless-literal-set
    patterns:
      - pattern: |
          set(..., ($X, $A), ..., ($X, $B), ...)
      - focus-metavariable: $X
    message: "`$X` is uselessly assigned twice inside the creation of the set"
    languages:
      - python
    severity: ERROR
    metadata:
      category: maintainability
      references:
        - https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset
      technology:
        - python
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

useless-literal-set.py

# ruleid: useless-literal-set
s = set((1, "a"), (2, "b"), (1, "a"))

# ok: useless-literal-set
s = set((1, "a"), (2, "b"), (3, "c"))