python.lang.best-practice.pass-body.pass-body-fn

profile photo of semgrepsemgrep
Author
6,393
Download Count*

pass is the body of function $X. Consider removing this or raise NotImplementedError() if this is a TODO

Run Locally

Run in CI

Defintion

rules:
  - id: pass-body-fn
    patterns:
      - pattern-not-inside: |
          def __init__(self, ...):
              ...
      - pattern-not-inside: |
          class $A:
               ...
      - pattern: |
          def $X(...):
              pass
    message: "`pass` is the body of function $X. Consider removing this or raise
      NotImplementedError() if this is a TODO"
    languages:
      - python
    severity: WARNING
    metadata:
      category: best-practice
      technology:
        - python
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

pass-body.py

# ruleid:pass-body-range
for i in range(100):
    pass

# ruleid:pass-body-fn
def foo():
    pass

def __init__(self):
    # ok:pass-body-fn
    pass

def __init__(self, other):
    # ok:pass-body-fn
    pass

class foo:
    def somemethod():
        # ok:pass-body-fn
        pass


class foobar:
    def someothermethod():
        # ruleid:pass-body-range
        for i in range(100):
            pass