{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Type variable."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The preferred way to construct a type variable is via the dedicated syntax for generic functions, classes, and type aliases      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "class Sequence[T]:  # T is a TypeVar\n    ...",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This syntax can also be used to create bound and constrained type variables      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "# S is a TypeVar bound to str\nclass StrSequence[S: str]:\n    ...\n\n# A is a TypeVar constrained to str or bytes\nclass StrOrBytesSequence[A: (str, bytes)]:\n    ...",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Type variables can also have defaults:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "DefList",
              "__tag": 4033,
              "children": [
                {
                  "__type": "DefListItem",
                  "__tag": 4037,
                  "dt": {
                    "__type": "Paragraph",
                    "__tag": 4045,
                    "children": [
                      {
                        "__type": "Text",
                        "__tag": 4046,
                        "value": "class IntDefault[T = int]:"
                      }
                    ]
                  },
                  "dd": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "..."
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "However, if desired, reusable type variables can also be constructed manually, like so     "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "T = TypeVar('T')  # Can be anything\nS = TypeVar('S', bound=str)  # Can be any subtype of str\nA = TypeVar('A', str, bytes)  # Must be exactly str or bytes\nD = TypeVar('D', default=int)  # Defaults to int",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Type variables exist primarily for the benefit of static type checkers.  They serve as the parameters for generic types as well as for generic function and type alias definitions."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The variance of type variables is inferred by type checkers when they are created through the type parameter syntax and when "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "infer_variance=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is passed. Manually created type variables may be explicitly marked covariant or contravariant by passing "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "covariant=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "contravariant=True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". By default, manually created type variables are invariant. See PEP 484 and PEP 695 for more details."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/opt/hostedtoolcache/Python/3.14.5/x64/lib/python3.14/typing.py",
  "item_line": null,
  "item_type": "TypeVar",
  "aliases": [
    "IPython.core.magic._F"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "IPython.core.magic:_F",
  "arbitrary": [],
  "local_refs": []
}