From 3250b349e6482e381c54db04188be515b0bac786 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Wed, 2 Dec 2026 19:09:32 -0800 Subject: [PATCH 1/2] Remove the positional detail argument of find() find(path, True) took True as detail, a form PyDrive2 1.x used, and warned. The second argument is maxdepth, as in other fsspec filesystems, and True would quietly mean a depth of 1, so a boolean there now raises TypeError. The upgrade guide says so. Co-Authored-By: Claude Opus 5.5 --- docs/upgrading.rst | 4 ++++ pydrive2/fs/spec.py | 12 ++++-------- pydrive2/test/test_fs_unit.py | 32 ++++++++++++++++---------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/upgrading.rst b/docs/upgrading.rst index 939ef021..9e714364 100644 --- a/docs/upgrading.rst +++ b/docs/upgrading.rst @@ -127,4 +127,8 @@ used it can fetch the metadata at the start of the method: The ``revoke_uri`` client setting is no longer read. A settings file that still has it keeps working. +The filesystem's ``find()`` takes ``maxdepth`` as its second argument, as +other fsspec filesystems do. Pass ``detail`` by keyword: +``fs.find(path, detail=True)``. ``fs.find(path, True)`` raises ``TypeError``. + .. _Drive v2 to v3 reference: https://developers.google.com/workspace/drive/api/guides/v2-to-v3-reference diff --git a/pydrive2/fs/spec.py b/pydrive2/fs/spec.py index ac47994b..3aad6877 100644 --- a/pydrive2/fs/spec.py +++ b/pydrive2/fs/spec.py @@ -11,7 +11,6 @@ import tempfile import threading import time -import warnings from collections import deque from contextlib import contextmanager, nullcontext from dataclasses import dataclass, field @@ -1152,15 +1151,12 @@ def _walk_folders(self, start, start_ids, generation, maxdepth, fields): def find( self, path, maxdepth=None, withdirs=False, detail=False, **kwargs ): - # PyDrive2 historically accepted a boolean detail as its second argument. + # PyDrive2 1.x took detail as the second argument, and True is 1. if isinstance(maxdepth, bool): - warnings.warn( - "Positional detail is deprecated. Pass detail=True or detail=False.", - DeprecationWarning, - stacklevel=2, + raise TypeError( + "find() takes maxdepth as its second argument. " + "Pass detail by keyword: find(path, detail=True)." ) - detail = detail or maxdepth - maxdepth = None root, base = self._split_mounted_path(path) if maxdepth is not None and maxdepth < 1: raise ValueError("maxdepth must be at least 1") diff --git a/pydrive2/test/test_fs_unit.py b/pydrive2/test/test_fs_unit.py index d9492b21..d1847944 100644 --- a/pydrive2/test/test_fs_unit.py +++ b/pydrive2/test/test_fs_unit.py @@ -557,22 +557,22 @@ def test_expanding_a_bounded_glob_does_not_list_children(mock_drive, pattern): assert "'root' in parents" in query(lookup)["q"][0] -def test_find_legacy_positional_detail_and_invalid_depth(mock_drive): - item = { - "name": "file", - "id": "F", - "mimeType": "text/plain", - "parents": ["root"], - } - page = response({"files": [item]}) - drive, _ = mock_drive(page, page) - fs = filesystem(drive) - with pytest.warns(DeprecationWarning, match="detail"): - legacy = fs.find("root", True) - assert legacy == fs.find("root", detail=True) - for depth in (0, -1): - with pytest.raises(ValueError, match="maxdepth"): - fs.find("root", maxdepth=depth) +@pytest.mark.parametrize( + ("maxdepth", "error", "message"), + [ + (True, TypeError, "detail=True"), + (False, TypeError, "detail=True"), + (0, ValueError, "maxdepth"), + (-1, ValueError, "maxdepth"), + ], +) +def test_find_with_a_depth_that_is_not_a_positive_number_raises_before_listing( + mock_drive, maxdepth, error, message +): + drive, requests = mock_drive() + with pytest.raises(error, match=message): + filesystem(drive).find("root", maxdepth) + assert requests == [] @pytest.mark.parametrize("bare", [True, False]) From 02ad6c1248ddaa87f39f782d6330833ec2df632b Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 3 Dec 2026 11:00:57 -0800 Subject: [PATCH 2/2] Name the caller's own value in the find() hint Co-Authored-By: Claude Opus 5.5 --- pydrive2/fs/spec.py | 2 +- pydrive2/test/test_fs_unit.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pydrive2/fs/spec.py b/pydrive2/fs/spec.py index 3aad6877..9358f680 100644 --- a/pydrive2/fs/spec.py +++ b/pydrive2/fs/spec.py @@ -1155,7 +1155,7 @@ def find( if isinstance(maxdepth, bool): raise TypeError( "find() takes maxdepth as its second argument. " - "Pass detail by keyword: find(path, detail=True)." + f"Pass detail by keyword: find(path, detail={maxdepth})." ) root, base = self._split_mounted_path(path) if maxdepth is not None and maxdepth < 1: diff --git a/pydrive2/test/test_fs_unit.py b/pydrive2/test/test_fs_unit.py index d1847944..107ff5b1 100644 --- a/pydrive2/test/test_fs_unit.py +++ b/pydrive2/test/test_fs_unit.py @@ -561,7 +561,7 @@ def test_expanding_a_bounded_glob_does_not_list_children(mock_drive, pattern): ("maxdepth", "error", "message"), [ (True, TypeError, "detail=True"), - (False, TypeError, "detail=True"), + (False, TypeError, "detail=False"), (0, ValueError, "maxdepth"), (-1, ValueError, "maxdepth"), ],