Skip to content

Commit ec0cd81

Browse files
fffrogpytorchmergebot
authored andcommitted
[Code Clean] Remove deadcodes about Python3.9 [4/N] (pytorch#163643)
As the title stated. Pull Request resolved: pytorch#163643 Approved by: https://github.com/albanD ghstack dependencies: pytorch#163626, pytorch#163627, pytorch#163629
1 parent 33aabdd commit ec0cd81

File tree

3 files changed

+20
-33
lines changed

3 files changed

+20
-33
lines changed

torch/fx/graph.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,19 +500,10 @@ def type_repr(o: Any):
500500

501501
origin_typename = add_global(_type_repr(origin_type), origin_type)
502502

503-
if hasattr(o, "__args__"):
504-
# Assign global names for each of the inner type variables.
503+
if hasattr(o, "__args__") and o.__args__:
505504
args = [type_repr(arg) for arg in o.__args__]
506-
507-
if len(args) == 0:
508-
# Bare type, such as `typing.Tuple` with no subscript
509-
# This code-path used in Python < 3.9
510-
return origin_typename
511-
512505
return f"{origin_typename}[{','.join(args)}]"
513506
else:
514-
# Bare type, such as `typing.Tuple` with no subscript
515-
# This code-path used in Python 3.9+
516507
return origin_typename
517508

518509
# Common case: this is a regular module name like 'foo.bar.baz'

torch/utils/_config_module.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
_UNSET_SENTINEL = object()
3838

3939

40-
@dataclass
40+
@dataclass(kw_only=True)
4141
class _Config(Generic[T]):
4242
"""Represents a config with richer behaviour than just a default value.
4343
::
@@ -81,32 +81,23 @@ class _Config(Generic[T]):
8181
justknob: Optional[str] = None
8282
env_name_default: Optional[list[str]] = None
8383
env_name_force: Optional[list[str]] = None
84+
value_type: Optional[type] = None
8485
alias: Optional[str] = None
8586

86-
def __init__(
87-
self,
88-
default: Union[T, object] = _UNSET_SENTINEL,
89-
justknob: Optional[str] = None,
90-
env_name_default: Optional[Union[str, list[str]]] = None,
91-
env_name_force: Optional[Union[str, list[str]]] = None,
92-
value_type: Optional[type] = None,
93-
alias: Optional[str] = None,
94-
):
95-
# python 3.9 does not support kw_only on the dataclass :(.
96-
self.default = default
97-
self.justknob = justknob
87+
def __post_init__(self) -> None:
9888
self.env_name_default = _Config.string_or_list_of_string_to_list(
99-
env_name_default
89+
self.env_name_default
10090
)
101-
self.env_name_force = _Config.string_or_list_of_string_to_list(env_name_force)
102-
self.value_type = value_type
103-
self.alias = alias
91+
self.env_name_force = _Config.string_or_list_of_string_to_list(
92+
self.env_name_force
93+
)
94+
10495
if self.alias is not None:
10596
assert (
106-
default is _UNSET_SENTINEL
107-
and justknob is None
108-
and env_name_default is None
109-
and env_name_force is None
97+
self.default is _UNSET_SENTINEL
98+
and self.justknob is None
99+
and self.env_name_default is None
100+
and self.env_name_force is None
110101
), "if alias is set, none of {default, justknob and env var} can be set"
111102

112103
@staticmethod
@@ -147,7 +138,12 @@ def Config(
147138
alias: Optional[str] = None,
148139
) -> _Config[T]:
149140
return _Config(
150-
default, justknob, env_name_default, env_name_force, value_type, alias
141+
default=default,
142+
justknob=justknob,
143+
env_name_default=env_name_default,
144+
env_name_force=env_name_force,
145+
value_type=value_type,
146+
alias=alias,
151147
)
152148

153149

torch/utils/cpp_extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def _get_sycl_device_flags(cflags):
345345
'win-amd64' : 'x86_amd64',
346346
}
347347

348-
min_supported_cpython = "0x03090000" # Python 3.9 hexcode
348+
min_supported_cpython = "0x030A0000" # Python 3.10 hexcode
349349

350350
def get_cxx_compiler():
351351
if IS_WINDOWS:

0 commit comments

Comments
 (0)