mirror of
https://github.com/davidhalter/django-stubs.git
synced 2026-02-22 01:28:29 +08:00
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:
@@ -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]"
|
||||
|
||||
Reference in New Issue
Block a user