mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[torch.package, 3.13] fixes to torch.package for 3.13 (#141409)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/141409 Approved by: https://github.com/PaliC, https://github.com/atalman
This commit is contained in:
committed by
PyTorch MergeBot
parent
e6e75ebd0a
commit
22ae34af88
10
test/package/package_a/std_sys_module_hacks_3_13.py
Normal file
10
test/package/package_a/std_sys_module_hacks_3_13.py
Normal file
@ -0,0 +1,10 @@
|
||||
import os # noqa: F401
|
||||
import os.path # noqa: F401
|
||||
import typing # noqa: F401
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
class Module(torch.nn.Module):
|
||||
def forward(self):
|
||||
return os.path.abspath("test")
|
@ -178,6 +178,7 @@ class DirectoryReaderTest(PackageTestCase):
|
||||
self.assertIsNone(importer.get_resource_reader("nonexistent_package"))
|
||||
|
||||
@skipIf(version_info < (3, 7), "ResourceReader API introduced in Python 3.7")
|
||||
@skipIf(version_info >= (3, 13), "https://github.com/python/cpython/issues/127012")
|
||||
def test_package_resource_access(self):
|
||||
"""Packaged modules should be able to use the importlib.resources API to access
|
||||
resources saved in the package.
|
||||
|
@ -338,10 +338,13 @@ class TestMisc(PackageTestCase):
|
||||
causes modules who do this hackery to fail on import. See
|
||||
https://github.com/pytorch/pytorch/issues/57490 for more information.
|
||||
"""
|
||||
import package_a.std_sys_module_hacks
|
||||
if sys.version_info < (3, 13):
|
||||
import package_a.std_sys_module_hacks as std_sys_module_hacks
|
||||
else:
|
||||
import package_a.std_sys_module_hacks_3_13 as std_sys_module_hacks
|
||||
|
||||
buffer = BytesIO()
|
||||
mod = package_a.std_sys_module_hacks.Module()
|
||||
mod = std_sys_module_hacks.Module()
|
||||
|
||||
with PackageExporter(buffer) as pe:
|
||||
pe.intern("**")
|
||||
|
@ -77,6 +77,7 @@ class TestResources(PackageTestCase):
|
||||
|
||||
self.assertIsNone(importer.get_resource_reader("nonexistent_package"))
|
||||
|
||||
@skipIf(version_info >= (3, 13), "https://github.com/python/cpython/issues/127012")
|
||||
def test_package_resource_access(self):
|
||||
"""Packaged modules should be able to use the importlib.resources API to access
|
||||
resources saved in the package.
|
||||
|
@ -6,6 +6,7 @@ import inspect
|
||||
import io
|
||||
import linecache
|
||||
import os
|
||||
import sys
|
||||
import types
|
||||
from contextlib import contextmanager
|
||||
from typing import (
|
||||
@ -526,6 +527,7 @@ class PackageImporter(Importer):
|
||||
if name == "os":
|
||||
self.modules["os.path"] = cast(Any, module).path
|
||||
elif name == "typing":
|
||||
if sys.version_info < (3, 13):
|
||||
self.modules["typing.io"] = cast(Any, module).io
|
||||
self.modules["typing.re"] = cast(Any, module).re
|
||||
|
||||
|
Reference in New Issue
Block a user