From 3488025fb6639917e50876fddc05365029ece874 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Wed, 6 Nov 2024 10:29:52 +0000 Subject: [PATCH] Improve Python version handling Checking just the second element of a version tuple is never good style, and it makes it less clear what actual versions of Python are in question. Signed-off-by: Colin Watson --- runtime/Python3/src/antlr4/Lexer.py | 2 +- runtime/Python3/src/antlr4/Parser.py | 2 +- .../org/antlr/v4/tool/templates/codegen/Python3/Python3.stg | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/Python3/src/antlr4/Lexer.py b/runtime/Python3/src/antlr4/Lexer.py index 82accadcbc..18ce7e3923 100644 --- a/runtime/Python3/src/antlr4/Lexer.py +++ b/runtime/Python3/src/antlr4/Lexer.py @@ -11,7 +11,7 @@ from io import StringIO import sys -if sys.version_info[1] > 5: +if sys.version_info >= (3, 6): from typing import TextIO else: from typing.io import TextIO diff --git a/runtime/Python3/src/antlr4/Parser.py b/runtime/Python3/src/antlr4/Parser.py index ae7f48cce0..710daab411 100644 --- a/runtime/Python3/src/antlr4/Parser.py +++ b/runtime/Python3/src/antlr4/Parser.py @@ -3,7 +3,7 @@ # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. import sys -if sys.version_info[1] > 5: +if sys.version_info >= (3, 6): from typing import TextIO else: from typing.io import TextIO diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg index 972b88b6d0..44e60f8cda 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg @@ -52,7 +52,7 @@ ParserFile(file, parser, namedActions, contextSuperClass) ::= << from antlr4 import * from io import StringIO import sys -if sys.version_info[1] > 5: +if sys.version_info >= (3, 6): from typing import TextIO else: from typing.io import TextIO @@ -761,7 +761,7 @@ LexerFile(lexerFile, lexer, namedActions) ::= << from antlr4 import * from io import StringIO import sys -if sys.version_info[1] > 5: +if sys.version_info >= (3, 6): from typing import TextIO else: from typing.io import TextIO