Repository: python/mypy

Issue:
typing_extensions TypeVar seems to be unsupported

**Bug Report**

Mypy doesn't support `typing_extensions.TypeVar` at all

**To Reproduce**

[Playground](https://mypy-play.net/?mypy=latest&python=3.11&gist=e1e77a65ff20e0f16cd37281f18b95be)

```python
from typing import Generic
from typing_extensions import (
    TypeVar,
)

T = TypeVar("T")

class A(Generic[T]):
    def __init__(self, value: T):
        self.value = value

a: A = A(8)
b: A[str] = A("")
```

**Expected Behavior**

This code should work fine (importing `TypeVar` from `typing` works, but my actual use case depends on `default` argument of `TypeVar`, so I can't use `typing.TypeVar`)

**Actual Behavior**

```
main.py:8: error: Free type variable expected in Generic[...]  [misc]
main.py:9: error: Variable "__main__.T" is not valid as a type  [valid-type]
main.py:9: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
main.py:13: error: "A" expects no type arguments, but 1 given  [type-arg]
Found 3 errors in 1 file (checked 1 source file)
```

**Your Environment**

mypy Playground, latest mypy (0.991)



Discussion:
This should be an easy fix if you're up for it. For inspiration, you can look at the commit adding support for `typing_extensions.overload`: https://github.com/python/mypy/commit/0df8cf532918f888610a5afd7bb88192712de984.
I would be happy to contribute, but it seems that this approach would just alias `typing.TypeVar`. 

My actual usage (not from example) relies on `default` argument, which is absent from `typing` version (because it's from PEP 696 which is a draft).
Yes, that would be much harder. :) I think @Gobot1234 already has a draft implementation of PEP 696 for mypy.
https://github.com/Gobot1234/mypy/tree/TypeVar-defaults is my draft implementation of PEP 696, its not bug free and is more lax than the current specification but it should work for most basic things. 

Resolving patch:
diff --git a/mypy/semanal.py b/mypy/semanal.py
--- a/mypy/semanal.py
+++ b/mypy/semanal.py
@@ -3847,7 +3847,7 @@ def process_typevar_declaration(self, s: AssignmentStmt) -> bool:
         Return True if this looks like a type variable declaration (but maybe
         with errors), otherwise return False.
         """
-        call = self.get_typevarlike_declaration(s, ("typing.TypeVar",))
+        call = self.get_typevarlike_declaration(s, ("typing.TypeVar", "typing_extensions.TypeVar"))
         if not call:
             return False
 


Test patch:
diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test
--- a/test-data/unit/check-generics.test
+++ b/test-data/unit/check-generics.test
@@ -2663,3 +2663,36 @@ def foo(x: A) -> A:
                 # N: (Hint: Use "B" in function signature to bind "B" inside a function)
         return y.x
     return bar()[0]
+
+
+-- TypeVar imported from typing_extensions
+-- ---------------------------------------
+
+[case testTypeVarTypingExtensionsSimpleGeneric]
+from typing import Generic
+from typing_extensions import TypeVar
+
+T = TypeVar("T")
+
+class A(Generic[T]):
+    def __init__(self, value: T) -> None:
+        self.value = value
+
+a: A = A(8)
+b: A[str] = A("")
+
+reveal_type(A(1.23))  # N: Revealed type is "__main__.A[builtins.float]"
+
+[builtins fixtures/tuple.pyi]
+
+[case testTypeVarTypingExtensionsSimpleBound]
+from typing_extensions import TypeVar
+
+T= TypeVar("T")
+
+def func(var: T) -> T:
+    return var
+
+reveal_type(func(1))  # N: Revealed type is "builtins.int"
+
+[builtins fixtures/tuple.pyi]