Eugene Toder

Results 74 comments of Eugene Toder

Hi @rchen152! What is the status of Self type now? It looks like you added support for even some complex cases, but when I try the example from OP with...

Got it, thanks!

A similar example with the recent mypy version: https://mypy-play.net/?mypy=latest&python=3.11&gist=069b99fd10df82bef0769c52209ce00e ```python from typing import assert_type class Desc: def __get__(self, obj, owner=None) -> int: return 1 class C: a = Desc() @property...

Actually, this does not need TypeVars: ```python def test(obj: int | None) -> type[int]: if obj is None: return int return obj.__class__ ``` produces ``` $ pytype class_narrow.py ... File...

@jgarvin You can cheat using `TYPE_CHECKING`: ```python if TYPE_CHECKING: # what you want type checkers to think lang_int = int lang_str = str lang_z = int else: # what you...

The `@given` decorator is pretty hard to type precisely. It takes a bunch of strategies and passes a value from each to the decorated function. (It also does the same...

Actually, I tried this, and it did not work. If I do ```python T = TypeVar("T") def given() -> Callable[[T], T]: ... # pytype: disable=bad-return-type class Test: @given() def test_foo(self)...

I found that the recommended way to make sentinels that work with type checking is to use an Enum[^1]: ```python from enum import Enum from typing import Iterable class Sentinel(Enum):...

Yes, the trick in this patten is to convince the type checker that the `is` check is sufficient. (`is` is much faster than `isinstance` at runtime.) With the enum approach,...