mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-24 10:14:26 +00:00
updated plugin to look for dotenv.load_dotenv also (attribute call vs direct call)
This commit is contained in:
parent
07f54f9942
commit
48b4ec0312
1 changed files with 17 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
|||
"""Flake8 Extension that finds usage of load_dotenv."""
|
||||
|
||||
import ast
|
||||
from typing import Generator
|
||||
|
||||
FORBIDDEN_CALLS = ["load_dotenv"]
|
||||
PLUGIN_CODE = "FC1"
|
||||
|
||||
|
||||
class ForbiddenCallPlugin:
|
||||
name = "flake8_forbidden_calls"
|
||||
version = "1.0.0"
|
||||
|
@ -14,6 +16,18 @@ class ForbiddenCallPlugin:
|
|||
|
||||
def run(self) -> Generator:
|
||||
for node in ast.walk(self._tree):
|
||||
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
|
||||
if node.func.id in FORBIDDEN_CALLS:
|
||||
yield (node.lineno, node.col_offset, f"{PLUGIN_CODE} `{node.func.id}` is not allowed.", type(self))
|
||||
if isinstance(node, ast.Call):
|
||||
func_name = (
|
||||
node.func.id
|
||||
if isinstance(node.func, ast.Name)
|
||||
else (
|
||||
node.func.attr if isinstance(node.func, ast.Attribute) else None
|
||||
)
|
||||
)
|
||||
if func_name in FORBIDDEN_CALLS:
|
||||
yield (
|
||||
node.lineno,
|
||||
node.col_offset,
|
||||
f"{PLUGIN_CODE} `{func_name}` is not allowed.",
|
||||
type(self),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue