Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type model is incorrect #29

Closed
rogalski opened this issue Nov 10, 2022 · 1 comment
Closed

Type model is incorrect #29

rogalski opened this issue Nov 10, 2022 · 1 comment
Milestone

Comments

@rogalski
Copy link

rogalski commented Nov 10, 2022

Typing of pathvalidate is incorrect. It uses Union for input/output arguments instead of using generics.
This throws mypy off - it cannot infer exact type of output variable, even if it's easily inferable from code structure.

repro.py

import pathlib
import typing

import pathvalidate

print(pathvalidate.__version__)

s = pathvalidate.sanitize_filename("lorem_ipsum")
print(type(s))
if typing.TYPE_CHECKING:
    reveal_type(s)

p = pathvalidate.sanitize_filename(pathlib.Path("lorem_ipsum"))
print(type(p))
if typing.TYPE_CHECKING:
    reveal_type(p)

Outputs:

$ python3 repro.py 
2.5.0
<class 'str'>
<class 'pathlib.PosixPath'>
$ mypy repro.py 
repro.py:11: note: Revealed type is "Union[builtins.str, pathlib.Path]"
repro.py:16: note: Revealed type is "Union[builtins.str, pathlib.Path]"
Success: no issues found in 1 source file

Expected output:
str type inferred for first reveal_type, pathlib.Path inferred for second reveal_type

@thombashi thombashi added this to the v3 milestone Feb 26, 2023
thombashi added a commit that referenced this issue Feb 26, 2023
@thombashi
Copy link
Owner

Thank you for your report.
f7f5c8f fixed the problem.

mypy issue29.py --python-version 3.7
issue29.py:11: note: Revealed type is "builtins.str"
issue29.py:16: note: Revealed type is "pathlib.Path"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants