Using the following code:
from pathlib import Path
file = Path("test.txt")
with open(file) as fl:
pass
Pycharm gives the following warning on file
Unexpected type(s): (Path)
Possible types:
(Union[str, bytes, int])
(Union[str, bytes, int, PathLike]) less... (Ctrl+F1)
Inspection info: This inspection detects type errors in function call expressions. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Types of function parameters can be specified in docstrings or in Python 3 function annotations.
Am I doing something wrong ?
You can read file with Path function, like this:
file = Path("test.txt")
with file.open(mode="r", encoding="utf-8") as fl:
content = fl.read()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With