python.lang.maintainability.is-function-without-parentheses.is-function-without-parentheses

profile photo of semgrepsemgrep
Author
unknown
Download Count*

Is "$FUNC" a function or an attribute? If it is a function, you may have meant $X.$FUNC() because $X.$FUNC is always true.

Run Locally

Run in CI

Defintion

rules:
  - id: is-function-without-parentheses
    languages:
      - python
    message: Is "$FUNC" a function or an attribute? If it is a function, you may
      have meant $X.$FUNC() because $X.$FUNC is always true.
    patterns:
      - pattern: $X.$FUNC
      - pattern-not-inside: $X.$FUNC(...)
      - metavariable-regex:
          metavariable: $FUNC
          regex: is_.*
    severity: WARNING
    metadata:
      category: maintainability
      technology:
        - python
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

is-function-without-parentheses.py

class MyClass:
  some_attr = 3
  def is_positive(self):
    return self.some_attr > 0

example = MyClass()
# ok:is-function-without-parentheses
example.is_positive()
# ruleid:is-function-without-parentheses
if (example.is_positive):
  do_something()
# ok:is-function-without-parentheses
elif (example.some_attr):
  do_something_else()
else:
  return