Fix overloads and remove PathLike in finders (#1063)

* Fix overloads in finders

Signed-off-by: Anders Kaseorg <andersk@mit.edu>

* Remove PathLike from finders

Django really requires these paths to be str.  For example, in
FileSystemFinder, .find(path) calls .find_location(…, path, …) which
evaluates path.startswith(prefix) and path[len(prefix) :]; these don’t
work on arbitrary PathLike objects.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg authored and GitHub committed 2022-07-22 10:35:24 +03:00
1 parent 563e947402
commit 3d8d900487
2 files changed
+27 -30

No files matched your search

@@ -2,38 +2,38 @@
main: |
from django.contrib.staticfiles import finders
reveal_type(finders.find("filepath")) # N: Revealed type is "Union[builtins.str, os.PathLike[builtins.str], None]"
reveal_type(finders.find("filepath")) # N: Revealed type is "Union[builtins.str, None]"
for finder in finders.get_finders():
reveal_type(finder.find("filepath")) # N: Revealed type is "Union[builtins.str, os.PathLike[builtins.str], None]"
reveal_type(finder.find("filepath")) # N: Revealed type is "Union[builtins.str, None]"
reveal_type(finders.FileSystemFinder().find("filepath")) # N: Revealed type is "Union[builtins.str, os.PathLike[builtins.str], None]"
reveal_type(finders.AppDirectoriesFinder().find("filepath")) # N: Revealed type is "Union[builtins.str, os.PathLike[builtins.str], None]"
reveal_type(finders.DefaultStorageFinder().find("filepath")) # N: Revealed type is "Union[builtins.str, os.PathLike[builtins.str], None]"
reveal_type(finders.FileSystemFinder().find("filepath")) # N: Revealed type is "Union[builtins.str, None]"
reveal_type(finders.AppDirectoriesFinder().find("filepath")) # N: Revealed type is "Union[builtins.str, None]"
reveal_type(finders.DefaultStorageFinder().find("filepath")) # N: Revealed type is "Union[builtins.str, None]"
- case: test_find_all
main: |
from django.contrib.staticfiles import finders
reveal_type(finders.find("filepath", all=True)) # N: Revealed type is "builtins.list[Union[builtins.str, os.PathLike[builtins.str]]]"
reveal_type(finders.find("filepath", all=True)) # N: Revealed type is "builtins.list[builtins.str]"
for finder in finders.get_finders():
reveal_type(finder.find("filepath", all=True)) # N: Revealed type is "builtins.list[Union[builtins.str, os.PathLike[builtins.str]]]"
reveal_type(finder.find("filepath", all=True)) # N: Revealed type is "builtins.list[builtins.str]"
reveal_type(finders.FileSystemFinder().find("filepath", all=True)) # N: Revealed type is "builtins.list[Union[builtins.str, os.PathLike[builtins.str]]]"
reveal_type(finders.AppDirectoriesFinder().find("filepath", all=True)) # N: Revealed type is "builtins.list[Union[builtins.str, os.PathLike[builtins.str]]]"
reveal_type(finders.DefaultStorageFinder().find("filepath", all=True)) # N: Revealed type is "builtins.list[Union[builtins.str, os.PathLike[builtins.str]]]"
reveal_type(finders.FileSystemFinder().find("filepath", all=True)) # N: Revealed type is "builtins.list[builtins.str]"
reveal_type(finders.AppDirectoriesFinder().find("filepath", all=True)) # N: Revealed type is "builtins.list[builtins.str]"
reveal_type(finders.DefaultStorageFinder().find("filepath", all=True)) # N: Revealed type is "builtins.list[builtins.str]"
- case: test_file_system_finder # test methods *only* on FileSystemFinder
main: |
from django.contrib.staticfiles.finders import FileSystemFinder
finder = FileSystemFinder()
reveal_type(finder.find_location(".", "filepath")) # N: Revealed type is "Union[builtins.str, os.PathLike[builtins.str], None]"
reveal_type(finder.find_location(".", "filepath")) # N: Revealed type is "Union[builtins.str, None]"
- case: test_app_directories_finder # test methods *only* on AppDirectoriesFinder
main: |
from django.contrib.staticfiles.finders import AppDirectoriesFinder
finder = AppDirectoriesFinder()
reveal_type(finder.find_in_app("app", "filepath")) # N: Revealed type is "Union[builtins.str, os.PathLike[builtins.str], None]"
reveal_type(finder.find_in_app("app", "filepath")) # N: Revealed type is "Union[builtins.str, None]"