You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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
With the following example pytype generates wrong annotations:
where the built in
os.chdir
function expectsstr | bytes | os.PathLike[str] | os.PathLike[bytes]
.However, pytpe genrates
bytes | int | str | os.PathLike[bytes | str]]
, where the inclusion ofint
is wrong and theos.PathLike[Union[bytes, str]]
is problematic becausePathLike
should be eitherPathLike[str]
orPathLike[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 complainsIs this a known issue, or is there a recommended fix?
The text was updated successfully, but these errors were encountered: