Summary
We don't emit a diagnostic on this snippet... but we should, because _T_co is not defined 😆
class SupportsNext:
def __next__(self) -> _T_co:
raise NotImplementedError
We infer _T_co as being available here because of its definition in builtins.pyi here. But that definition should be treated as private-to-the-stub, I think.
Possibly we should just filter out typevar definitions when falling back to the builtin scope in name lookup? The same could also be said for type-alias definitions and protocol definitions in builtins.pyi, but they're arguably both more useful and less confusing to have available (you might want to use them quoted in type annotations, e.g. x: "_PositiveInteger" wouldn't be an unreasonable type annotation.
Version
No response