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 hints for utils.Lock.acquire (and __enter__) incorrect #97

Open
clo-vis opened this issue Jul 24, 2024 · 1 comment
Open

Type hints for utils.Lock.acquire (and __enter__) incorrect #97

clo-vis opened this issue Jul 24, 2024 · 1 comment
Labels

Comments

@clo-vis
Copy link

clo-vis commented Jul 24, 2024

Lock.acquire is defined as:

def acquire(...) -> typing.IO[typing.AnyStr]:

but typing.AnyStr is a TypeVar, and "A function returning TypeVar should receive at least one argument containing the same TypeVar" (this is what mypy should have said).

See python/mypy#16113

As a result, when I write

from portalocker import Lock

def load_binary_file(path: str) -> bytes:
    with Lock(path, mode="rb") as file:
        return file.read()  #  mypy and pyright complain

I get the errors:

mypy: Incompatible return value type (got "str", expected "bytes")
pyright: Return type is unknown

@github-actions github-actions bot added the Stale label Aug 24, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2024
@wolph
Copy link
Owner

wolph commented Aug 31, 2024

The stalebot 🤦🏻‍♂️

On the bright side, at least it reminds me of this issue. I'm working on getting portalocker pyright strict so this should be fixed soon :)

@wolph wolph reopened this Aug 31, 2024
@github-actions github-actions bot removed the Stale label Sep 1, 2024
@github-actions github-actions bot added the Stale label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants