Skip to content

AttributeError: type object 'Path' has no attribute '_flavour' - error seen when using Click 8 #600

@adamtheturtle

Description

@adamtheturtle

Describe the bug

In Click 8, a new feature was introduced, enabling users to use pathlib.Path as
a type for arguments.

This indirectly uses the _flavour attribute of Path.
This errors when I use PyFakeFS.

I get the following error:

Traceback (most recent call last):
  File "/Users/adam/Desktop/click_example/example.py", line 27, in <module>
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/core.py", line 1134, in __call__
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/core.py", line 1058, in main
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/core.py", line 927, in make_context
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/core.py", line 1376, in parse_args
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/core.py", line 2352, in handle_parse_result
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/core.py", line 2308, in process_value
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/core.py", line 2295, in type_cast_value
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/types.py", line 75, in __call__
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/types.py", line 891, in convert
  File "/Users/adam/.virtualenvs/click-example/lib/python3.9/site-packages/click/types.py", line 826, in coerce_path_result
  File "/opt/homebrew/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 1073, in __new__
  File "/opt/homebrew/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 698, in _from_parts
  File "/opt/homebrew/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 691, in _parse_args
AttributeError: type object 'Path' has no attribute '_flavour'

I believe that this may be related to https://bugs.python.org/issue24132.

How To Reproduce

Realistic use case

# Requires
# pip install pyfakefs==4.4.0 click==8.0.0

import click
import pathlib
from pyfakefs.fake_filesystem_unittest import Patcher

@click.command()
@click.argument('foo', type=click.Path(path_type=pathlib.Path))
def hello(foo):
    pass

_patcher = Patcher()
_patcher.setUp()
hello(['/'])
_patcher.tearDown()

Narrow use case

import pathlib

import click
from pyfakefs.fake_filesystem_unittest import Patcher

patcher = Patcher()
click_path = click.Path(path_type=pathlib.Path)
patcher.setUp()
click_path.convert(value='/', param=None, ctx=None)
patcher.tearDown()

Your environment

Python 3.9.5 (default, May  3 2021, 19:12:05) 
[Clang 12.0.5 (clang-1205.0.22.9)]
pyfakefs 4.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions