[Code Clean] Remove deadcodes about Python3.9 [7/N] (#163646)

As the title stated.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/163646
Approved by: https://github.com/jansel
ghstack dependencies: #163626, #163627, #163629, #163643, #163644, #163645
This commit is contained in:
FFFrog
2025-09-24 11:24:10 +08:00
committed by PyTorch MergeBot
parent a635505a99
commit 2390d34c9b
4 changed files with 4 additions and 12 deletions

View File

@ -73,10 +73,6 @@ class TestHash(JitTestCase):
self.checkScript(fn, (1.2345, float("inf")))
self.checkScript(fn, (float("inf"), float("inf")))
self.checkScript(fn, (1.2345, float("nan")))
if sys.version_info < (3, 10):
# Hash of two nans are not guaranteed to be equal. From https://docs.python.org/3/whatsnew/3.10.html :
# Hashes of NaN values of both float type and decimal.Decimal type now depend on object identity.
self.checkScript(fn, (float("nan"), float("nan")))
self.checkScript(fn, (float("nan"), float("inf")))
def test_hash_int(self):

View File

@ -20,7 +20,6 @@ from torch.testing._internal.common_utils import raise_on_run_directly
from torch.testing._internal.jit_utils import JitTestCase, make_global
@unittest.skipIf(sys.version_info < (3, 10), "Requires Python 3.10")
class TestUnion(JitTestCase):
"""
This class tests the functionality of `Union`.

View File

@ -529,7 +529,7 @@ def create_print_value(value: Any) -> list[Instruction]:
]
def linetable_310_writer(
def linetable_writer(
first_lineno: int,
) -> tuple[list[int], Callable[[int, int], None], Callable[[int], None]]:
"""
@ -759,7 +759,7 @@ def assemble(instructions: list[Instruction], firstlineno: int) -> tuple[bytes,
for _ in range(instruction_size(inst) // 2 - 1):
code.extend((0, 0))
else:
lnotab, update_lineno, end = linetable_310_writer(firstlineno)
lnotab, update_lineno, end = linetable_writer(firstlineno)
for inst in instructions:
if inst.starts_line is not None:
@ -871,7 +871,6 @@ def devirtualize_jumps(instructions: list[Instruction]) -> None:
inst.arg = abs(
int(target.offset - inst.offset - instruction_size(inst))
)
# see bytecode size comment in the absolute jump case above
inst.arg //= 2
inst.argval = target.offset
inst.argrepr = f"to {target.offset}"

View File

@ -52,8 +52,7 @@ from torch.futures import Future
_P = ParamSpec("_P")
_R = TypeVar("_R")
BuiltinUnionType: Union[type, tuple[type, ...]]
BuiltinUnionType = types.UnionType
BuiltinUnionType: Union[type, tuple[type, ...]] = types.UnionType
LockType: type
try:
@ -1248,8 +1247,7 @@ def _get_named_tuple_properties(
]
else:
defaults = []
# In 3.10 recommended way to get annotations is to call `inspect.get_annotations` function
# Also, annotations from base class are not inherited so they need to be queried explicitly
obj_annotations = inspect.get_annotations(obj)
if len(obj_annotations) == 0 and hasattr(obj, "__base__"):
obj_annotations = inspect.get_annotations(obj.__base__)