From 6e6c57b8cb47282d7a5f4e304b11a1061e8f4225 Mon Sep 17 00:00:00 2001 From: AN Long Date: Fri, 15 Sep 2023 20:01:31 +0800 Subject: [PATCH] compatible with old python versions --- thriftpy2/parser/exc.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/thriftpy2/parser/exc.py b/thriftpy2/parser/exc.py index add8305..4130587 100644 --- a/thriftpy2/parser/exc.py +++ b/thriftpy2/parser/exc.py @@ -2,6 +2,7 @@ from __future__ import absolute_import +import sys from warnings import warn @@ -17,9 +18,12 @@ class ThriftGrammarError(ThriftParserError): pass -def __getattr__(name): - if name == "ThriftGrammerError": - warn("'ThriftGrammerError' is a typo of 'ThriftGrammarError'", DeprecationWarning) - return ThriftGrammarError +if sys.version_info >= (3, 7): + def __getattr__(name): + if name == "ThriftGrammerError": + warn("'ThriftGrammerError' is a typo of 'ThriftGrammarError'", DeprecationWarning) + return ThriftGrammarError - raise AttributeError("module %r has no attribute %r" % (__name__, name)) + raise AttributeError("module %r has no attribute %r" % (__name__, name)) +else: + ThriftGrammerError = ThriftGrammarError