From: SunghwanShim <128351792+SunghwanShim@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:17:49 +0000 (+0900) Subject: Fix wrong signature of `safe_open.__init__` in stub file (#557) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=adeda636b52a78c920e06d547d613a9cb22c5d28;p=safetensors.git Fix wrong signature of `safe_open.__init__` in stub file (#557) * fix: pyi binding bug * Fixing the stubbing script (breaking change in PyO3). --------- Co-authored-by: Nicolas Patry --- diff --git a/bindings/python/py_src/safetensors/__init__.pyi b/bindings/python/py_src/safetensors/__init__.pyi index 81442bd..7781229 100644 --- a/bindings/python/py_src/safetensors/__init__.pyi +++ b/bindings/python/py_src/safetensors/__init__.pyi @@ -69,7 +69,7 @@ class safe_open: The device on which you want the tensors. """ - def __init__(filename, framework, device=...): + def __init__(self, filename, framework, device=...): pass def __enter__(self): """ diff --git a/bindings/python/stub.py b/bindings/python/stub.py index 78ddc47..71fef2c 100644 --- a/bindings/python/stub.py +++ b/bindings/python/stub.py @@ -42,10 +42,7 @@ def fn_predicate(obj): return ( obj.__doc__ and obj.__text_signature__ - and ( - not obj.__name__.startswith("_") - or obj.__name__ in {"__enter__", "__exit__"} - ) + and (not obj.__name__.startswith("_") or obj.__name__ in {"__enter__", "__exit__"}) ) if inspect.isgetsetdescriptor(obj): return obj.__doc__ and not obj.__name__.startswith("_") @@ -81,15 +78,14 @@ def pyi_file(obj, indent=""): body = "" if obj.__doc__: - body += ( - f'{indent}"""\n{indent}{do_indent(obj.__doc__, indent)}\n{indent}"""\n' - ) + body += f'{indent}"""\n{indent}{do_indent(obj.__doc__, indent)}\n{indent}"""\n' fns = inspect.getmembers(obj, fn_predicate) # Init if obj.__text_signature__: - body += f"{indent}def __init__{obj.__text_signature__}:\n" + signature = obj.__text_signature__.replace("(", "(self, ") + body += f"{indent}def __init__{signature}:\n" body += f"{indent+INDENT}pass\n" body += "\n" @@ -146,11 +142,7 @@ def do_black(content, is_pyi): def write(module, directory, origin, check=False): - submodules = [ - (name, member) - for name, member in inspect.getmembers(module) - if inspect.ismodule(member) - ] + submodules = [(name, member) for name, member in inspect.getmembers(module) if inspect.ismodule(member)] filename = os.path.join(directory, "__init__.pyi") pyi_content = pyi_file(module) @@ -159,9 +151,7 @@ def write(module, directory, origin, check=False): if check: with open(filename, "r") as f: data = f.read() - assert ( - data == pyi_content - ), f"The content of {filename} seems outdated, please run `python stub.py`" + assert data == pyi_content, f"The content of {filename} seems outdated, please run `python stub.py`" else: with open(filename, "w") as f: f.write(pyi_content) @@ -184,9 +174,7 @@ def write(module, directory, origin, check=False): if check: with open(filename, "r") as f: data = f.read() - assert ( - data == py_content - ), f"The content of {filename} seems outdated, please run `python stub.py`" + assert data == py_content, f"The content of {filename} seems outdated, please run `python stub.py`" else: with open(filename, "w") as f: f.write(py_content)