Repository: pylint-dev/astroid

Issue:
Regression in Astroid version 2.15.7 in handling subscriptable type parameters
Astroid version 2.15.7 fails to correctly handle a subscriptable type parameter  most likely due to the change in this [PR](https://github.com/pylint-dev/astroid/pull/2239). 

### Steps to reproduce

```python
from collections.abc import Mapping
from typing import Generic, TypeVar, TypedDict
from dataclasses import dataclass

class Identity(TypedDict):
    """It's the identity."""

    name: str

T = TypeVar("T", bound=Mapping)

@dataclass
class Animal(Generic[T]):
    """It's an animal."""

    identity: T

class Dog(Animal[Identity]):
    """It's a Dog."""

dog = Dog(identity=Identity(name="Dog"))
print(dog.identity["name"])
```

### Current behavior
Pylint (running Astroid 2.15.7) gives the following error for the example above:
```
E1136: Value 'dog.identity' is unsubscriptable (unsubscriptable-object)
```
### Expected behavior
Astroid should correctly handle a subscriptable type parameter.


### `python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"` output
2.15.7


Discussion:
Thanks for the report.
@mbyrnepr2 Would you be willing to take a look?

Patch:
diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py
--- a/astroid/brain/brain_typing.py
+++ b/astroid/brain/brain_typing.py
@@ -17,6 +17,7 @@
 from astroid.builder import AstroidBuilder, _extract_single_node
 from astroid.const import PY39_PLUS, PY312_PLUS
 from astroid.exceptions import (
+    AstroidSyntaxError,
     AttributeInferenceError,
     InferenceError,
     UseInferenceDefault,
@@ -136,14 +137,10 @@ def infer_typing_typevar_or_newtype(
         raise UseInferenceDefault
 
     typename = node.args[0].as_string().strip("'")
-    node = ClassDef(
-        name=typename,
-        lineno=node.lineno,
-        col_offset=node.col_offset,
-        parent=node.parent,
-        end_lineno=node.end_lineno,
-        end_col_offset=node.end_col_offset,
-    )
+    try:
+        node = extract_node(TYPING_TYPE_TEMPLATE.format(typename))
+    except AstroidSyntaxError as exc:
+        raise InferenceError from exc
     return node.infer(context=context_itton)
 
 


Test patch:
diff --git a/tests/brain/test_typing.py b/tests/brain/test_typing.py
--- a/tests/brain/test_typing.py
+++ b/tests/brain/test_typing.py
@@ -2,7 +2,10 @@
 # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
 # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
 
-from astroid import builder, nodes
+import pytest
+
+from astroid import builder
+from astroid.exceptions import InferenceError
 
 
 def test_infer_typevar() -> None:
@@ -12,13 +15,11 @@ def test_infer_typevar() -> None:
     Test that an inferred `typing.TypeVar()` call produces a `nodes.ClassDef`
     node.
     """
-    assign_node = builder.extract_node(
+    call_node = builder.extract_node(
         """
     from typing import TypeVar
-    MyType = TypeVar('My.Type')
+    TypeVar('My.Type')
     """
     )
-    call = assign_node.value
-    inferred = next(call.infer())
-    assert isinstance(inferred, nodes.ClassDef)
-    assert inferred.name == "My.Type"
+    with pytest.raises(InferenceError):
+        call_node.inferred()