prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Change in Python 3.9.5 (and 3.8.10) causes Faker's list_module() to fail
  * Faker version: 8.1.2
  * OS: macOS 11.3.1
  
  A [regression in Python](https://bugs.python.org/issue44061) breaks Faker, specifically [this line of code in Faker](https://github.com/joke2k/faker/blob/master/faker/utils/loading.py#L35) that calls `pkgutil.iter_modules([path])`.
  
  It's not clear to me from the discussion in that python bug report exactly how they intend to resolve the issue, but I thought I'd flag this here.
  
  ### Steps to reproduce
  
  1. Install python 3.9.5 or 3.8.10
  1. Install faker
  1. `import faker`
  
  ### Expected behavior
  
  `import faker` should succeed
  
  ### Actual behavior
  
  `import faker` raises an exception
  
  ```shell
  >>> import faker
  >>> import faker
  Traceback (most recent call last):
    File "/python/3.9/lib/python3.9/pkgutil.py", line 416, in get_importer
      importer = sys.path_importer_cache[path_item]
  KeyError: PosixPath('/venv/lib/python3.9/site-packages/faker/providers')
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/venv/lib/python3.9/site-packages/faker/__init__.py", line 1, in <module>
      from faker.factory import Factory
    File "/venv/lib/python3.9/site-packages/faker/factory.py", line 7, in <module>
      from faker.config import AVAILABLE_LOCALES, DEFAULT_LOCALE, PROVIDERS
    File "/venv/lib/python3.9/site-packages/faker/config.py", line 11, in <module>
      PROVIDERS = find_available_providers(
    File "/venv/lib/python3.9/site-packages/faker/utils/loading.py", line 57, in find_available_providers
      for mod in list_module(providers_mod) if mod != '__pycache__'
    File "/venv/lib/python3.9/site-packages/faker/utils/loading.py", line 35, in list_module
      return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]
    File "/venv/lib/python3.9/site-packages/faker/utils/loading.py", line 35, in <listcomp>
      return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]
    File "/python/3.9/lib/python3.9/pkgutil.py", line 130, in iter_modules
      for i in importers:
    File "/python/3.9/lib/python3.9/pkgutil.py", line 420, in get_importer
      importer = path_hook(path_item)
    File "<frozen importlib._bootstrap_external>", line 1601, in path_hook_for_FileFinder
    File "<frozen importlib._bootstrap_external>", line 1476, in __init__
    File "<frozen importlib._bootstrap_external>", line 177, in _path_isabs
  AttributeError: 'PosixPath' object has no attribute 'startswith'
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `faker/utils/loading.py`
  Content:
  ```
  1 import pkgutil
  2 import sys
  3 
  4 from importlib import import_module
  5 from pathlib import Path
  6 from types import ModuleType
  7 from typing import List, Set
  8 
  9 
  10 def get_path(module: ModuleType) -> str:
  11     if getattr(sys, 'frozen', False):
  12         # frozen
  13 
  14         if getattr(sys, '_MEIPASS', False):
  15             # PyInstaller
  16             lib_dir = Path(getattr(sys, '_MEIPASS'))
  17         else:
  18             # others
  19             lib_dir = Path(sys.executable).parent / 'lib'
  20 
  21         path = lib_dir.joinpath(*module.__package__.split("."))
  22     else:
  23         # unfrozen
  24         path = Path(module.__file__).parent
  25     return str(path)
  26 
  27 
  28 def list_module(module: ModuleType) -> List[str]:
  29     path = get_path(module)
  30 
  31     if getattr(sys, '_MEIPASS', False):
  32         # PyInstaller
  33         return [file.parent.name for file in Path(path).glob('*/__init__.py')]
  34     else:
  35         return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]
  36 
  37 
  38 def find_available_locales(providers: List[str]) -> List[str]:
  39     available_locales: Set[str] = set()
  40 
  41     for provider_path in providers:
  42 
  43         provider_module = import_module(provider_path)
  44         if getattr(provider_module, 'localized', False):
  45             langs = list_module(provider_module)
  46             available_locales.update(langs)
  47     available_locales: List[str] = sorted(available_locales)
  48     return available_locales
  49 
  50 
  51 def find_available_providers(modules: List[ModuleType]) -> List[str]:
  52     available_providers = set()
  53     for providers_mod in modules:
  54         if providers_mod.__package__:
  55             providers = [
  56                 '.'.join([providers_mod.__package__, mod])
  57                 for mod in list_module(providers_mod) if mod != '__pycache__'
  58             ]
  59             available_providers.update(providers)
  60     return sorted(available_providers)
  61
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/faker/utils/loading.py b/faker/utils/loading.py
  --- a/faker/utils/loading.py
  +++ b/faker/utils/loading.py
  @@ -32,7 +32,7 @@
           # PyInstaller
           return [file.parent.name for file in Path(path).glob('*/__init__.py')]
       else:
  -        return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]
  +        return [name for _, name, is_pkg in pkgutil.iter_modules([str(path)]) if is_pkg]
   
   
   def find_available_locales(providers: List[str]) -> List[str]:
  
verification_info: {"golden_diff": "diff --git a/faker/utils/loading.py b/faker/utils/loading.py\n--- a/faker/utils/loading.py\n+++ b/faker/utils/loading.py\n@@ -32,7 +32,7 @@\n         # PyInstaller\n         return [file.parent.name for file in Path(path).glob('*/__init__.py')]\n     else:\n-        return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]\n+        return [name for _, name, is_pkg in pkgutil.iter_modules([str(path)]) if is_pkg]\n \n \n def find_available_locales(providers: List[str]) -> List[str]:\n", "issue": "Change in Python 3.9.5 (and 3.8.10) causes Faker's list_module() to fail\n* Faker version: 8.1.2\r\n* OS: macOS 11.3.1\r\n\r\nA [regression in Python](https://bugs.python.org/issue44061) breaks Faker, specifically [this line of code in Faker](https://github.com/joke2k/faker/blob/master/faker/utils/loading.py#L35) that calls `pkgutil.iter_modules([path])`.\r\n\r\nIt's not clear to me from the discussion in that python bug report exactly how they intend to resolve the issue, but I thought I'd flag this here.\r\n\r\n### Steps to reproduce\r\n\r\n1. Install python 3.9.5 or 3.8.10\r\n1. Install faker\r\n1. `import faker`\r\n\r\n### Expected behavior\r\n\r\n`import faker` should succeed\r\n\r\n### Actual behavior\r\n\r\n`import faker` raises an exception\r\n\r\n```shell\r\n>>> import faker\r\n>>> import faker\r\nTraceback (most recent call last):\r\n  File \"/python/3.9/lib/python3.9/pkgutil.py\", line 416, in get_importer\r\n    importer = sys.path_importer_cache[path_item]\r\nKeyError: PosixPath('/venv/lib/python3.9/site-packages/faker/providers')\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/venv/lib/python3.9/site-packages/faker/__init__.py\", line 1, in <module>\r\n    from faker.factory import Factory\r\n  File \"/venv/lib/python3.9/site-packages/faker/factory.py\", line 7, in <module>\r\n    from faker.config import AVAILABLE_LOCALES, DEFAULT_LOCALE, PROVIDERS\r\n  File \"/venv/lib/python3.9/site-packages/faker/config.py\", line 11, in <module>\r\n    PROVIDERS = find_available_providers(\r\n  File \"/venv/lib/python3.9/site-packages/faker/utils/loading.py\", line 57, in find_available_providers\r\n    for mod in list_module(providers_mod) if mod != '__pycache__'\r\n  File \"/venv/lib/python3.9/site-packages/faker/utils/loading.py\", line 35, in list_module\r\n    return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]\r\n  File \"/venv/lib/python3.9/site-packages/faker/utils/loading.py\", line 35, in <listcomp>\r\n    return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]\r\n  File \"/python/3.9/lib/python3.9/pkgutil.py\", line 130, in iter_modules\r\n    for i in importers:\r\n  File \"/python/3.9/lib/python3.9/pkgutil.py\", line 420, in get_importer\r\n    importer = path_hook(path_item)\r\n  File \"<frozen importlib._bootstrap_external>\", line 1601, in path_hook_for_FileFinder\r\n  File \"<frozen importlib._bootstrap_external>\", line 1476, in __init__\r\n  File \"<frozen importlib._bootstrap_external>\", line 177, in _path_isabs\r\nAttributeError: 'PosixPath' object has no attribute 'startswith'\r\n```\n", "before_files": [{"content": "import pkgutil\nimport sys\n\nfrom importlib import import_module\nfrom pathlib import Path\nfrom types import ModuleType\nfrom typing import List, Set\n\n\ndef get_path(module: ModuleType) -> str:\n    if getattr(sys, 'frozen', False):\n        # frozen\n\n        if getattr(sys, '_MEIPASS', False):\n            # PyInstaller\n            lib_dir = Path(getattr(sys, '_MEIPASS'))\n        else:\n            # others\n            lib_dir = Path(sys.executable).parent / 'lib'\n\n        path = lib_dir.joinpath(*module.__package__.split(\".\"))\n    else:\n        # unfrozen\n        path = Path(module.__file__).parent\n    return str(path)\n\n\ndef list_module(module: ModuleType) -> List[str]:\n    path = get_path(module)\n\n    if getattr(sys, '_MEIPASS', False):\n        # PyInstaller\n        return [file.parent.name for file in Path(path).glob('*/__init__.py')]\n    else:\n        return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]\n\n\ndef find_available_locales(providers: List[str]) -> List[str]:\n    available_locales: Set[str] = set()\n\n    for provider_path in providers:\n\n        provider_module = import_module(provider_path)\n        if getattr(provider_module, 'localized', False):\n            langs = list_module(provider_module)\n            available_locales.update(langs)\n    available_locales: List[str] = sorted(available_locales)\n    return available_locales\n\n\ndef find_available_providers(modules: List[ModuleType]) -> List[str]:\n    available_providers = set()\n    for providers_mod in modules:\n        if providers_mod.__package__:\n            providers = [\n                '.'.join([providers_mod.__package__, mod])\n                for mod in list_module(providers_mod) if mod != '__pycache__'\n            ]\n            available_providers.update(providers)\n    return sorted(available_providers)\n", "path": "faker/utils/loading.py"}], "after_files": [{"content": "import pkgutil\nimport sys\n\nfrom importlib import import_module\nfrom pathlib import Path\nfrom types import ModuleType\nfrom typing import List, Set\n\n\ndef get_path(module: ModuleType) -> str:\n    if getattr(sys, 'frozen', False):\n        # frozen\n\n        if getattr(sys, '_MEIPASS', False):\n            # PyInstaller\n            lib_dir = Path(getattr(sys, '_MEIPASS'))\n        else:\n            # others\n            lib_dir = Path(sys.executable).parent / 'lib'\n\n        path = lib_dir.joinpath(*module.__package__.split(\".\"))\n    else:\n        # unfrozen\n        path = Path(module.__file__).parent\n    return str(path)\n\n\ndef list_module(module: ModuleType) -> List[str]:\n    path = get_path(module)\n\n    if getattr(sys, '_MEIPASS', False):\n        # PyInstaller\n        return [file.parent.name for file in Path(path).glob('*/__init__.py')]\n    else:\n        return [name for _, name, is_pkg in pkgutil.iter_modules([str(path)]) if is_pkg]\n\n\ndef find_available_locales(providers: List[str]) -> List[str]:\n    available_locales: Set[str] = set()\n\n    for provider_path in providers:\n\n        provider_module = import_module(provider_path)\n        if getattr(provider_module, 'localized', False):\n            langs = list_module(provider_module)\n            available_locales.update(langs)\n    available_locales: List[str] = sorted(available_locales)\n    return available_locales\n\n\ndef find_available_providers(modules: List[ModuleType]) -> List[str]:\n    available_providers = set()\n    for providers_mod in modules:\n        if providers_mod.__package__:\n            providers = [\n                '.'.join([providers_mod.__package__, mod])\n                for mod in list_module(providers_mod) if mod != '__pycache__'\n            ]\n            available_providers.update(providers)\n    return sorted(available_providers)\n", "path": "faker/utils/loading.py"}]}