Skip to content

Commit 24c2711

Browse files
committed
stubfix as cli
1 parent 42e89eb commit 24c2711

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

duckdb/_duckdb.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ class DuckDBPyRelation:
694694
def torch(self) -> dict: ...
695695
def union(self, union_rel: DuckDBPyRelation) -> DuckDBPyRelation: ...
696696
def unique(self, unique_aggr: str) -> DuckDBPyRelation: ...
697-
def update(self, set: Expression | str, *, condition: Expression | str = None) -> None: ...
697+
def update(self, set: Expression | str, *, condition: Expression | str | None = None) -> None: ...
698698
def value_counts(self, column: str, groups: str = "") -> DuckDBPyRelation: ...
699699
def var(
700700
self, column: str, groups: str = "", window_spec: str = "", projected_columns: str = ""

duckdb/_duckdb/functional.pyi

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
import typing
1+
import typing as pytyping
22

33
__all__: list[str] = ["ARROW", "DEFAULT", "NATIVE", "SPECIAL", "FunctionNullHandling", "PythonUDFType"]
44

55
class FunctionNullHandling:
6-
DEFAULT: typing.ClassVar[FunctionNullHandling] # value = <FunctionNullHandling.DEFAULT: 0>
7-
SPECIAL: typing.ClassVar[FunctionNullHandling] # value = <FunctionNullHandling.SPECIAL: 1>
8-
__members__: typing.ClassVar[
6+
DEFAULT: pytyping.ClassVar[FunctionNullHandling] # value = <FunctionNullHandling.DEFAULT: 0>
7+
SPECIAL: pytyping.ClassVar[FunctionNullHandling] # value = <FunctionNullHandling.SPECIAL: 1>
8+
__members__: pytyping.ClassVar[
99
dict[str, FunctionNullHandling]
1010
] # value = {'DEFAULT': <FunctionNullHandling.DEFAULT: 0>, 'SPECIAL': <FunctionNullHandling.SPECIAL: 1>}
1111
def __eq__(self, other: object) -> bool: ...
1212
def __getstate__(self) -> int: ...
1313
def __hash__(self) -> int: ...
1414
def __index__(self) -> int: ...
15-
def __init__(self, value: typing.SupportsInt) -> None: ...
15+
def __init__(self, value: pytyping.SupportsInt) -> None: ...
1616
def __int__(self) -> int: ...
1717
def __ne__(self, other: object) -> bool: ...
18-
def __setstate__(self, state: typing.SupportsInt) -> None: ...
18+
def __setstate__(self, state: pytyping.SupportsInt) -> None: ...
1919
@property
2020
def name(self) -> str: ...
2121
@property
2222
def value(self) -> int: ...
2323

2424
class PythonUDFType:
25-
ARROW: typing.ClassVar[PythonUDFType] # value = <PythonUDFType.ARROW: 1>
26-
NATIVE: typing.ClassVar[PythonUDFType] # value = <PythonUDFType.NATIVE: 0>
27-
__members__: typing.ClassVar[
25+
ARROW: pytyping.ClassVar[PythonUDFType] # value = <PythonUDFType.ARROW: 1>
26+
NATIVE: pytyping.ClassVar[PythonUDFType] # value = <PythonUDFType.NATIVE: 0>
27+
__members__: pytyping.ClassVar[
2828
dict[str, PythonUDFType]
2929
] # value = {'NATIVE': <PythonUDFType.NATIVE: 0>, 'ARROW': <PythonUDFType.ARROW: 1>}
3030
def __eq__(self, other: object) -> bool: ...
3131
def __getstate__(self) -> int: ...
3232
def __hash__(self) -> int: ...
3333
def __index__(self) -> int: ...
34-
def __init__(self, value: typing.SupportsInt) -> None: ...
34+
def __init__(self, value: pytyping.SupportsInt) -> None: ...
3535
def __int__(self) -> int: ...
3636
def __ne__(self, other: object) -> bool: ...
37-
def __setstate__(self, state: typing.SupportsInt) -> None: ...
37+
def __setstate__(self, state: pytyping.SupportsInt) -> None: ...
3838
@property
3939
def name(self) -> str: ...
4040
@property

scripts/stubfix.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _fix_overloaded_functions(text: str) -> str:
232232
out.append(lines[i])
233233
i += 1
234234

235-
return "\n".join(out)
235+
return "\n".join(out) + "\n"
236236

237237

238238
# -------------------------
@@ -289,15 +289,16 @@ def repl(m: re.Match) -> str:
289289
# Skip if annotation already explicitly optional / contains None (covers `X | None`, `Union[..., None]`, etc.)
290290
if "none" in ann_lower:
291291
return colon + ann_raw + trail
292-
if ("optional[" in ann_lower) or ("typing.optional[" in ann_lower) or ("duckdb_typing.optional[" in ann_lower):
292+
if "optional[" in ann_lower:
293293
return colon + ann_raw + trail
294-
if ("classvar[" in ann_lower) or ("typing.classvar[" in ann_lower):
294+
if "classvar[" in ann_lower:
295295
return colon + ann_raw + trail
296-
if ann in {"Any", "typing.Any", "duckdb_typing.Any", "object", "ClassVar"}:
296+
if ann in {"Any", "typing.Any", "pytyping.Any", "object", "ClassVar"}:
297297
return colon + ann_raw + trail
298298

299299
# Otherwise wrap conservatively preserving original whitespace and annotation text
300-
return f"{colon}typing.Optional[{ann}]{trail}"
300+
# return f"{colon}typing.Optional[{ann}]{trail}"
301+
return f"{colon}{ann} | None {trail}"
301302

302303
return pattern.sub(repl, text)
303304

@@ -348,8 +349,6 @@ def _is_valid_stubfile(path: Path) -> bool:
348349
)
349350
parser.add_argument("-r", "--recursive", action="store_true", default=False)
350351
args = parser.parse_args()
351-
fix_stub(args.path)
352-
args = parser.parse_args()
353352
if args.path.is_file():
354353
if not _is_valid_stubfile(args.path):
355354
print(f"{args.path} is a file, but not a pyi file.")

0 commit comments

Comments
 (0)