Skip to content

Commit 1d8d672

Browse files
authored
Detect invalid examples in class docstrings (mlflow#14476)
Signed-off-by: harupy <[email protected]>
1 parent 889fa80 commit 1d8d672

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

dev/clint/src/clint/linter.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,14 @@ def _is_in_test(self) -> bool:
277277
def visit_ClassDef(self, node: ast.ClassDef) -> None:
278278
self.stack.append(node)
279279
self._no_rst(node)
280+
self._syntax_error_example(node)
280281
self._mlflow_class_name(node)
281282
self.generic_visit(node)
282283
self.stack.pop()
283284

284-
def _syntax_error_example(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
285+
def _syntax_error_example(
286+
self, node: ast.FunctionDef | ast.AsyncFunctionDef | ast.ClassDef
287+
) -> None:
285288
if docstring_node := self._docstring(node):
286289
for code_block in _iter_code_blocks(docstring_node.value):
287290
try:

mlflow/pyfunc/dbconnect_artifact_cache.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ class DBConnectArtifactCache:
2727
db_artifact_cache = DBConnectArtifactCache.get_or_create()
2828
db_artifact_cache.add_artifact_archive("archive1", "/tmp/archive1.tar.gz")
2929
30+
3031
@pandas_udf(...)
31-
def my_udf(...):
32-
# we can get the unpacked archive files in `archive1_unpacked_dir`
33-
archive1_unpacked_dir = db_artifact_cache.get("archive1")
32+
def my_udf(x):
33+
# we can get the unpacked archive files in `archive1_unpacked_dir`
34+
archive1_unpacked_dir = db_artifact_cache.get("archive1")
3435
"""
3536

3637
_global_cache = None

0 commit comments

Comments
 (0)