Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Replaced edit distance with NLTK package #686

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies = [
"setuptools>=65.5.1",
"typer>=0.12.1",
"typing-extensions>=4.7.1",
"python-levenshtein>=0.25.1",
"nltk>=3.9",
]
license = "MIT"
license-files = ["LICENSES/*"]
Expand Down
4 changes: 2 additions & 2 deletions safety/tool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tempfile import mkstemp

import typer
from Levenshtein import distance
import nltk
from filelock import FileLock
from rich.padding import Padding
from rich.prompt import Prompt
Expand Down Expand Up @@ -227,7 +227,7 @@ def __check_typosquatting(self, package_name):

for pkg in MOST_FREQUENTLY_DOWNLOADED_PYPI_PACKAGES:
if (abs(len(pkg) - len(package_name)) <= max_edit_distance
and distance(pkg, package_name) <= max_edit_distance):
and nltk.edit_distance(pkg, package_name) <= max_edit_distance):
return (False, pkg)

return (True, package_name)
Expand Down
Loading