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

BUG: pytype generates wrong annotation for built in function #1880

Open
gothicVI opened this issue Mar 11, 2025 · 0 comments
Open

BUG: pytype generates wrong annotation for built in function #1880

gothicVI opened this issue Mar 11, 2025 · 0 comments

Comments

@gothicVI
Copy link

With the following example pytype generates wrong annotations:

$ cat t.py
from os import chdir
from pathlib import Path

f = Path(__file__).resolve()
chdir(f)
$ pytype t.py
$ cat .pytype/pyi/t.pyi
# (generated with --quick)

import os
import pathlib
from typing import Union

Path: type[pathlib.Path]
f: pathlib.Path

def chdir(path: Union[bytes, int, str, os.PathLike[Union[bytes, str]]]) -> None: ...

where the built in os.chdir function expects str | bytes | os.PathLike[str] | os.PathLike[bytes].

However, pytpe genrates bytes | int | str | os.PathLike[bytes | str]], where the inclusion of int is wrong and the os.PathLike[Union[bytes, str]] is problematic because PathLike should be either PathLike[str] or PathLike[bytes].

This can't be intended behavior, right? How to fix that? This creates issues with our pre-commit because pyright picks up the .pytype folder and complains

error: Type "bytes | str" cannot be assigned to type variable "AnyStr_co@PathLike"
    Type "bytes | str" is not assignable to constrained type variable "AnyStr_co@PathLike" (reportInvalidTypeArguments)

Is this a known issue, or is there a recommended fix?

@gothicVI gothicVI changed the title BUG: pytype generates wrong annotation for build in function BUG: pytype generates wrong annotation for built in function Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant