Skip to content

Commit b347ac7

Browse files
authored
Do not use os.path.sep to detect / in names. (#21682)
Operation and layer names do not represent a filesystem path and should not be OS dependent. Namescope paths always use "/" as a separator, which is what we should be looking for. This reverts #21343 just for `Operation`. Note that [the unit test](https://github.com/keras-team/keras/blob/master/keras/src/ops/operation_test.py#L331) was correct. Simply, we never run in on Windows, which is why this was not caught.
1 parent 565d694 commit b347ac7

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

keras/src/ops/operation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import inspect
2-
import os.path
32
import textwrap
43

54
from keras.src import backend
@@ -20,10 +19,10 @@ class Operation(KerasSaveable):
2019
def __init__(self, name=None):
2120
if name is None:
2221
name = auto_name(self.__class__.__name__)
23-
if not isinstance(name, str) or os.path.sep in name:
22+
if not isinstance(name, str) or "/" in name:
2423
raise ValueError(
2524
"Argument `name` must be a string and "
26-
f"cannot contain character `{os.path.sep}`. "
25+
f"cannot contain character `/`. "
2726
f"Received: name={name} (of type {type(name)})"
2827
)
2928
self.name = name

0 commit comments

Comments
 (0)