Repository: joke2k/faker

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'
```


Discussion:
just to add my 2-cents, we are seeing this issue pop-up in automated `latest` build workflows that use Faker as a dependency. For now, we are pinning workflow python execution to `3.8.6`. A fix would be greatly appreciated to avoid less tech-savvy users from unwittingly running into this issue with fresh python installs. 

Resolving patch:
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 @@ def list_module(module: ModuleType) -> List[str]:
         # 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]:


Test patch: