{"id":7829,"library":"types-typed-ast","title":"Typing Stubs for typed-ast","description":"types-typed-ast provides static type annotations (stubs) for the `typed-ast` library, enabling type checkers like MyPy to understand its API and catch type-related errors. It is part of the `typeshed` project, a community-maintained repository of type stubs for Python packages. The current version is 1.5.8.7, and `typeshed` releases new stubs regularly as upstream libraries evolve.","status":"active","version":"1.5.8.7","language":"python","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type-checking","typed-ast","mypy","typeshed"],"install":[{"cmd":"pip install types-typed-ast","lang":"bash","label":"Install stubs"},{"cmd":"pip install typed-ast mypy","lang":"bash","label":"Install runtime + type checker"}],"dependencies":[{"reason":"Provides the runtime functionality for which these stubs are created.","package":"typed-ast","optional":false},{"reason":"A common static type checker that utilizes these stubs.","package":"mypy","optional":true}],"imports":[{"wrong":"from typed_ast_stubs.ast3 import AST","symbol":"AST","correct":"from typed_ast_stubs.ast3 import AST"}],"quickstart":{"code":"import typed_ast.ast3 as typed_ast\n\ndef analyze_node(node: typed_ast.AST) -> str:\n    \"\"\"Analyzes an AST node and returns its type name.\"\"\"\n    if isinstance(node, typed_ast.Expr):\n        return f\"Expression node: {typed_ast.dump(node)}\"\n    return f\"Generic node: {type(node).__name__}\"\n\nsource_code = \"def example_func(a: int, b: int) -> int: return a + b\"\nparsed_module = typed_ast.parse(source_code, mode='exec')\n\n# This call is type-checked by MyPy using the stubs provided by types-typed-ast\nresult = analyze_node(parsed_module)\nprint(result)\n\n# To run type checking, save this as 'my_script.py' and run:\n# mypy my_script.py\n","lang":"python","description":"This example demonstrates how to use `typed-ast` (the runtime library) and how `types-typed-ast` (the stub package) provides type hints for it. The `mypy` command would use the installed stubs to verify type correctness of `analyze_node`'s arguments and return types without any explicit import of `types-typed-ast`."},"warnings":[{"fix":"Always import symbols from the *runtime library* (`typed-ast`), not the stub package. The stub package is consumed implicitly by type checkers like MyPy.","message":"Stub packages like `types-typed-ast` provide *only* type information and are not intended for direct import or runtime execution. Attempting to `import types_typed_ast` will result in a `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure both `pip install typed-ast` and `pip install types-typed-ast` are executed. `typed-ast` for runtime, `types-typed-ast` for type checking.","message":"For `types-typed-ast` to be effective, the actual runtime library `typed-ast` must also be installed. The stubs don't provide the implementation, only the type signatures.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When encountering unexpected type errors, ensure your `types-typed-ast` version is compatible with your `typed-ast` version. Consult the `typeshed` repository or `typed-ast` documentation for compatibility notes. Upgrading both packages might resolve the issue.","message":"Version compatibility between stub packages and their corresponding runtime libraries can be an issue. Stubs are generated for specific versions of the runtime, and mismatches can lead to incorrect type checking results or missing definitions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.5.8.7':59 'annot':14 'api':30 'ast':6,10,20,77 'catch':32 'check':74 'checker':24 'communiti':46 'community-maintain':45 'current':56 'enabl':22 'error':36 'evolv':69 'librari':21,68 'like':25 'maintain':47 'mypi':26,78 'new':63 'packag':54 'part':39 'project':43 'provid':11 'python':53 'regular':65 'relat':35 'releas':62 'repositori':48 'static':12 'stub':2,15,51,64,71 'type':1,5,8,9,13,19,23,34,50,70,73,76 'type-check':72 'type-rel':33 'typed-ast':4,18,75 'types-typed-ast':7 'typesh':42,61,79 'understand':28 'upstream':67 'version':57","created_at":"2026-04-16T14:15:10.948438+00:00","updated_at":"2026-04-16T14:15:10.948438+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nModuleNotFoundError: No module named 'typed_ast_stubs'"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.5.8.7","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/typeshed-internal/stub_uploader","docs":null,"changelog":"https://github.com/typeshed-internal/stub_uploader/blob/main/data/changelogs/typed-ast.md","pypi":"https://pypi.org/project/types-typed-ast/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["type-stubs"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}