Use sys.version_info to guard Python 3.11 only code.

This makes pytype happier since it understands sys.version_info, but didn't understand the previous hasattr() test.

PiperOrigin-RevId: 587846307
This commit is contained in:
Peter Hawkins 2023-12-04 14:42:44 -08:00 committed by jax authors
parent aa270489bf
commit 193eb1289d

View File

@ -18,6 +18,7 @@ import dataclasses
import functools
import itertools
import os.path
import sys
import sysconfig
import threading
import types
@ -141,8 +142,7 @@ def is_user_filename(filename: str) -> bool:
not any(filename.startswith(p) for p in _exclude_paths) or
any(filename.startswith(p) for p in _include_paths))
if hasattr(xla_client.Traceback, "code_addr2location"):
# Python 3.11+
if sys.version_info >= (3, 11):
def raw_frame_to_frame(code: types.CodeType, lasti: int) -> Frame:
loc = xla_client.Traceback.code_addr2location(code, lasti)
start_line, start_column, end_line, end_column = loc