{"id":6281,"library":"types-antlr4-python3-runtime","title":"Typing stubs for antlr4-python3-runtime","description":"This package provides static type checking stubs for the `antlr4-python3-runtime` library, enabling type checkers like MyPy and Pyright to analyze code that uses ANTLR 4's Python runtime. It is part of the `typeshed` project and aims to provide accurate annotations for `antlr4-python3-runtime==4.13.*`. Releases are frequent, often incorporating a date suffix, reflecting updates within the `typeshed` project and alignment with the underlying runtime.","status":"active","version":"4.13.0.20260408","language":"python","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type-hints","antlr","parser","lexer","grammar"],"install":[{"cmd":"pip install types-antlr4-python3-runtime","lang":"bash","label":"Install Stubs"},{"cmd":"pip install antlr4-python3-runtime","lang":"bash","label":"Install Runtime (Required)"}],"dependencies":[{"reason":"This package provides type stubs for the 'antlr4-python3-runtime' library; the actual runtime must be installed to execute code.","package":"antlr4-python3-runtime"},{"reason":"Requires Python 3.10 or newer.","package":"python","optional":false}],"imports":[{"wrong":"from antlr4 import InputStream","symbol":"InputStream","correct":"from antlr4_stubs import InputStream"}],"quickstart":{"code":"import os\nfrom antlr4 import InputStream, CommonTokenStream, ParseTreeWalker\n\n# --- Example: Assumes MyGrammar.g4 was compiled to MyGrammarLexer.py and MyGrammarParser.py ---\n# To generate these files, you need the ANTLR Java tool (antlr-VERSION-complete.jar):\n# java -jar /path/to/antlr-VERSION-complete.jar MyGrammar.g4 -Dlanguage=Python3\n\n# Placeholder for generated classes (replace with actual generated imports)\n# For a real scenario, these would be in files like MyGrammarLexer.py and MyGrammarParser.py\nclass MyGrammarLexer:\n    def __init__(self, input_stream):\n        pass # Simplified for quickstart\n    def getAllTokens(self):\n        return [] # Simplified\n\nclass MyGrammarParser:\n    def __init__(self, token_stream):\n        pass # Simplified\n    def myRule(self):\n        class Context:\n            def accept(self, visitor): pass\n            def toStringTree(self, recog=None): return \"(myRule)\"\n        return Context() # Simplified\n\nclass MyGrammarListener:\n    def enterMyRule(self, ctx): pass\n    def exitMyRule(self, ctx): pass\n\n# Example usage of the antlr4-python3-runtime with generated classes\ninput_text = \"hello world\"\ninput_stream = InputStream(input_text)\n\nlexer = MyGrammarLexer(input_stream)\ntoken_stream = CommonTokenStream(lexer)\nparser = MyGrammarParser(token_stream)\n\n# Assume 'myRule' is the entry point for your grammar\ntree = parser.myRule()\n\nprint(f\"Parsed tree: {tree.toStringTree(recog=parser)}\")\n\n# Using a listener for tree traversal\nlistener = MyGrammarListener()\nwalker = ParseTreeWalker()\nwalker.walk(listener, tree)\n\nprint(\"Type checking enabled for antlr4 classes by types-antlr4-python3-runtime.\")\n","lang":"python","description":"This quickstart demonstrates how to use the core `antlr4-python3-runtime` components with ANTLR-generated lexer and parser classes. The `types-antlr4-python3-runtime` package provides type hints for all `antlr4` imports and the expected interfaces of generated classes, improving developer experience with static analysis tools. Note that the ANTLR tool (a Java JAR) is required separately to generate `MyGrammarLexer.py` and `MyGrammarParser.py` from your `.g4` grammar file."},"warnings":[{"fix":"Upgrade `antlr4-python3-runtime` to version `4.13.0` or newer when using Python 3.13+.","message":"The `antlr4-python3-runtime` library, which these stubs target, has known incompatibilities with specific Python versions. Notably, `antlr4-python3-runtime==4.11.1` is incompatible with Python 3.13+ due to changes in CPython's internal APIs. Users of Python 3.13 or newer should ensure they are using `antlr4-python3-runtime>=4.13.0`. Always check the compatibility matrix for the underlying runtime.","severity":"breaking","affected_versions":"antlr4-python3-runtime < 4.13.0 for Python >= 3.13"},{"fix":"Ensure both `types-antlr4-python3-runtime` and `antlr4-python3-runtime` are installed. If generating parsers, ensure Java is installed and the ANTLR `.jar` tool is available.","message":"This package provides *only* type stubs. It does not include the actual `antlr4-python3-runtime` library. For your code to run, you must install `antlr4-python3-runtime` separately. Additionally, the ANTLR parser generator tool itself (which converts `.g4` grammars to Python source files) requires a Java Runtime Environment (JRE) to operate, which can be a point of confusion for Python-only developers.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Report type-related issues or propose changes to the `antlr4-python3-runtime` stub in the main `typeshed` repository on GitHub.","message":"As a type stub package part of the `typeshed` project, fixes or improvements to the type annotations should be contributed directly to the `typeshed` GitHub repository, not to this `types-` package directly.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'4':35 '4.13':57 'accur':50 'aim':47 'align':73 'analyz':30 'annot':51 'antlr':34,83 'antlr4':5,18,54 'antlr4-python3-runtime':4,17,53 'check':13 'checker':24 'code':31 'date':64 'enabl':22 'frequent':60 'grammar':86 'hint':82 'incorpor':62 'lexer':85 'librari':21 'like':25 'mypi':26 'often':61 'packag':9 'parser':84 'part':41 'project':45,71 'provid':10,49 'pyright':28 'python':37 'python3':6,19,55 'reflect':66 'releas':58 'runtim':7,20,38,56,77 'static':11 'stub':2,14,79 'suffix':65 'type':1,12,23,78,81 'type-hint':80 'typesh':44,70 'under':76 'updat':67 'use':33 'within':68","created_at":"2026-04-14T18:49:48.399655+00:00","updated_at":"2026-04-16T23:29:24.710383+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nModuleNotFoundError: No module named 'antlr4_stubs'"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.13.0.20260518","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/antlr4-python3-runtime.md","pypi":"https://pypi.org/project/types-antlr4-python3-runtime/","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}}