Skip to content

Commit d4fd9bc

Browse files
committed
Ruff ANN201: fixed return value type annotations
1 parent eac181e commit d4fd9bc

File tree

9 files changed

+27
-33
lines changed

9 files changed

+27
-33
lines changed

duckdb/experimental/spark/sql/column.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,18 @@ def __getattr__(self, item: Any) -> "Column":
205205
raise AttributeError(msg)
206206
return self[item]
207207

208-
def alias(self, alias: str): # noqa: D102
208+
def alias(self, alias: str) -> "Column": # noqa: D102
209209
return Column(self.expr.alias(alias))
210210

211-
def when(self, condition: "Column", value: Any): # noqa: D102
211+
def when(self, condition: "Column", value: Any) -> "Column": # noqa: D102
212212
if not isinstance(condition, Column):
213213
msg = "condition should be a Column"
214214
raise TypeError(msg)
215215
v = _get_expr(value)
216216
expr = self.expr.when(condition.expr, v)
217217
return Column(expr)
218218

219-
def otherwise(self, value: Any): # noqa: D102
219+
def otherwise(self, value: Any) -> "Column": # noqa: D102
220220
v = _get_expr(value)
221221
expr = self.expr.otherwise(v)
222222
return Column(expr)

duckdb/experimental/spark/sql/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def groupBy(self, *cols: "ColumnOrName") -> "GroupedData": # type: ignore[misc]
989989
def write(self) -> DataFrameWriter: # noqa: D102
990990
return DataFrameWriter(self)
991991

992-
def printSchema(self): # noqa: D102
992+
def printSchema(self) -> None: # noqa: D102
993993
raise ContributionsAcceptedError
994994

995995
def union(self, other: "DataFrame") -> "DataFrame":

duckdb/experimental/spark/sql/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _invoke_function_over_columns(name: str, *cols: "ColumnOrName") -> Column:
3030
return _invoke_function(name, *cols)
3131

3232

33-
def col(column: str): # noqa: D103
33+
def col(column: str) -> Column: # noqa: D103
3434
return Column(ColumnExpression(column))
3535

3636

duckdb/experimental/spark/sql/readwriter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def csv( # noqa: D102
5555
encoding: Optional[str] = None,
5656
emptyValue: Optional[str] = None,
5757
lineSep: Optional[str] = None,
58-
):
58+
) -> None:
5959
if mode not in (None, "overwrite"):
6060
raise NotImplementedError
6161
if escapeQuotes:

duckdb/filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .bytes_io_wrapper import BytesIOWrapper
88

99

10-
def is_file_like(obj): # noqa: D103, ANN001
10+
def is_file_like(obj) -> bool: # noqa: D103, ANN001
1111
# We only care that we can read from the file
1212
return hasattr(obj, "read") and hasattr(obj, "seek")
1313

@@ -17,7 +17,7 @@ class ModifiedMemoryFileSystem(MemoryFileSystem): # noqa: D101
1717
# defer to the original implementation that doesn't hardcode the protocol
1818
_strip_protocol = classmethod(AbstractFileSystem._strip_protocol.__func__)
1919

20-
def add_file(self, object: IO, path: str): # noqa: D102
20+
def add_file(self, object: IO, path: str) -> None: # noqa: D102
2121
if not is_file_like(object):
2222
msg = "Can not read from a non file-like object"
2323
raise ValueError(msg)

duckdb/query_graph/__main__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@
5757
text-align: center;
5858
padding: 0px;
5959
border-radius: 1px;
60-
60+
6161
/* Positioning */
6262
position: absolute;
6363
z-index: 1;
6464
bottom: 100%;
6565
left: 50%;
6666
transform: translateX(-50%);
6767
margin-bottom: 8px;
68-
68+
6969
/* Tooltip Arrow */
7070
width: 400px;
7171
}
@@ -77,7 +77,7 @@
7777

7878

7979
class NodeTiming: # noqa: D101
80-
def __init__(self, phase: str, time: float) -> object: # noqa: D107
80+
def __init__(self, phase: str, time: float) -> None: # noqa: D107
8181
self.phase = phase
8282
self.time = time
8383
# percentage is determined later.
@@ -86,7 +86,7 @@ def __init__(self, phase: str, time: float) -> object: # noqa: D107
8686
def calculate_percentage(self, total_time: float) -> None: # noqa: D102
8787
self.percentage = self.time / total_time
8888

89-
def combine_timing(l: object, r: object) -> object: # noqa: D102
89+
def combine_timing(l: "NodeTiming", r: "NodeTiming") -> "NodeTiming": # noqa: D102
9090
# TODO: can only add timings for same-phase nodes
9191
total_time = l.time + r.time
9292
return NodeTiming(l.phase, total_time)
@@ -96,25 +96,25 @@ class AllTimings: # noqa: D101
9696
def __init__(self) -> None: # noqa: D107
9797
self.phase_to_timings = {}
9898

99-
def add_node_timing(self, node_timing: NodeTiming): # noqa: D102
99+
def add_node_timing(self, node_timing: NodeTiming) -> None: # noqa: D102
100100
if node_timing.phase in self.phase_to_timings:
101101
self.phase_to_timings[node_timing.phase].append(node_timing)
102-
return
103-
self.phase_to_timings[node_timing.phase] = [node_timing]
102+
else:
103+
self.phase_to_timings[node_timing.phase] = [node_timing]
104104

105-
def get_phase_timings(self, phase: str): # noqa: D102
105+
def get_phase_timings(self, phase: str) -> list[NodeTiming]: # noqa: D102
106106
return self.phase_to_timings[phase]
107107

108-
def get_summary_phase_timings(self, phase: str): # noqa: D102
108+
def get_summary_phase_timings(self, phase: str) -> NodeTiming: # noqa: D102
109109
return reduce(NodeTiming.combine_timing, self.phase_to_timings[phase])
110110

111-
def get_phases(self): # noqa: D102
111+
def get_phases(self) -> list[NodeTiming]: # noqa: D102
112112
phases = list(self.phase_to_timings.keys())
113113
phases.sort(key=lambda x: (self.get_summary_phase_timings(x)).time)
114114
phases.reverse()
115115
return phases
116116

117-
def get_sum_of_all_timings(self): # noqa: D102
117+
def get_sum_of_all_timings(self) -> float: # noqa: D102
118118
total_timing_sum = 0
119119
for phase in self.phase_to_timings.keys():
120120
total_timing_sum += self.get_summary_phase_timings(phase).time
@@ -132,7 +132,7 @@ def get_child_timings(top_node: object, query_timings: object) -> str: # noqa:
132132
get_child_timings(child, query_timings)
133133

134134

135-
def get_pink_shade_hex(fraction: float): # noqa: D103
135+
def get_pink_shade_hex(fraction: float) -> str: # noqa: D103
136136
fraction = max(0, min(1, fraction))
137137

138138
# Define the RGB values for very light pink (almost white) and dark pink
@@ -211,7 +211,7 @@ def generate_timing_html(graph_json: object, query_timings: object) -> object:
211211
gather_timing_information(json_graph, query_timings)
212212
total_time = float(json_graph.get("operator_timing") or json_graph.get("latency"))
213213
table_head = """
214-
<table class=\"styled-table\">
214+
<table class=\"styled-table\">
215215
<thead>
216216
<tr>
217217
<th>Phase</th>

duckdb/udf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Callable
22

33

4-
def vectorized(func: Callable):
4+
def vectorized(func: Callable) -> Callable:
55
"""Decorate a function with annotated function parameters, so DuckDB can infer that the function should be provided with pyarrow arrays and should expect pyarrow array(s) as output."""
66
import types
77
from inspect import signature

duckdb_packaging/pypi_cleanup.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,31 +178,25 @@ def __init__(self, target: str, contains_input: bool | None = None) -> None: #
178178
self._in_form = False # Currently parsing a form with an action we're interested in
179179
self._input_contained = False # Input field requested is contained in the current form
180180

181-
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]): # noqa: D102
181+
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None: # noqa: D102
182182
if tag == "form":
183183
attrs = dict(attrs)
184184
action = attrs.get("action") # Might be None.
185185
if action and (action == self._target or action.startswith(self._target)):
186186
self._in_form = True
187-
return
188-
189-
if self._in_form and tag == "input":
187+
elif self._in_form and tag == "input":
190188
attrs = dict(attrs)
191189
if attrs.get("name") == "csrf_token":
192190
self._csrf = attrs["value"]
193-
194191
if self._contains_input and attrs.get("name") == self._contains_input:
195192
self._input_contained = True
196193

197-
return
198-
199-
def handle_endtag(self, tag: str): # noqa: D102
194+
def handle_endtag(self, tag: str) -> None: # noqa: D102
200195
if tag == "form":
201196
self._in_form = False
202197
# If we're in a right form that contains the requested input and csrf is not set
203198
if (not self._contains_input or self._input_contained) and not self.csrf:
204199
self.csrf = self._csrf
205-
return
206200

207201

208202
class PyPICleanup:

duckdb_packaging/setuptools_scm_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _bump_version(base_version: str, distance: int, dirty: bool = False) -> str:
7676
return f"{format_version(major, minor, patch + 1)}.dev{distance}"
7777

7878

79-
def forced_version_from_env():
79+
def forced_version_from_env() -> str:
8080
"""Handle getting versions from environment variables.
8181
8282
Only supports a single way of manually overriding the version through
@@ -132,7 +132,7 @@ def _git_describe_override_to_pep_440(override_value: str) -> str:
132132
return pep440_version
133133

134134

135-
def _remove_unsupported_env_var(env_var: str):
135+
def _remove_unsupported_env_var(env_var: str) -> None:
136136
"""Remove an unsupported environment variable with a warning."""
137137
print(f"[versioning] WARNING: We do not support {env_var}! Removing.")
138138
del os.environ[env_var]

0 commit comments

Comments
 (0)