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

Support for any iterable type as input data #88

Merged
merged 1 commit into from
Feb 19, 2024
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
5 changes: 5 additions & 0 deletions send2trash/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
text_type = unicode # noqa: F821
binary_type = str
environb = os.environ

try:
from collections.abc import Iterable as iterable_type
except ImportError:
from collections import Iterable as iterable_type
6 changes: 5 additions & 1 deletion send2trash/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license

from send2trash.compat import text_type, binary_type, iterable_type


def preprocess_paths(paths):
if not isinstance(paths, list):
if isinstance(paths, iterable_type) and not isinstance(paths, (text_type, binary_type)):
paths = list(paths)
elif not isinstance(paths, list):
paths = [paths]
# Convert items such as pathlib paths to strings
paths = [path.__fspath__() if hasattr(path, "__fspath__") else path for path in paths]
Expand Down