Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dummy_implementations preview style formatting #9240

Merged
merged 1 commit into from
Dec 22, 2023

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Dec 22, 2023

Summary

Improve dummy_implementations preview style

  • Only collapse dummy blocks if the parent is a function definition or class definition
  • Don't insert empty lines between two function definitions if the preceding statement is a dummy definition and the two definitions aren't separated by an empty line. Not enforcing an empty lines allows grouping overloaded function definitions.

Test Plan

  • cargo test
  • Verified that the similarity index are unchanged
  • Manually reviewed the ecosystem changes

@MichaReiser MichaReiser added formatter Related to the formatter preview Related to preview mode features labels Dec 22, 2023
@MichaReiser MichaReiser force-pushed the dummy-implementations branch 3 times, most recently from 2ce7f10 to 760d12e Compare December 22, 2023 03:17
Copy link
Contributor

github-actions bot commented Dec 22, 2023

ruff-ecosystem results

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

ℹ️ ecosystem check detected format changes. (+38 -68 lines in 23 files in 7 projects; 34 projects unchanged)

apache/airflow (+16 -8 lines across 5 files)

ruff format --preview

airflow/models/dag.py~L3971

             default_args=default_args,
             schedule="0 0 * * *",
             dagrun_timeout=timedelta(minutes=60),
-        ) as dag: ...
+        ) as dag:
+            ...
 
     If you do this the context stores the DAG and whenever new task is created, it will use
     such stored DAG as the parent DAG.

airflow/utils/log/secrets_masker.py~L359

 
     Expected usage::
 
-        with contextlib.redirect_stdout(RedactedIO()): ...  # Writes to stdout will be redacted.
+        with contextlib.redirect_stdout(RedactedIO()):
+            ...  # Writes to stdout will be redacted.
     """
 
     def __init__(self):

tests/decorators/test_bash.py~L39

     def setup(self, dag_maker):
         self.dag_maker = dag_maker
 
-        with dag_maker(dag_id="bash_deco_dag") as dag: ...
+        with dag_maker(dag_id="bash_deco_dag") as dag:
+            ...
 
         self.dag = dag
 

tests/models/test_dagrun.py~L2599

 )
 def test_dag_run_id_config(session, dag_maker, pattern, run_id, result):
     with conf_vars({("scheduler", "allowed_run_id_pattern"): pattern}):
-        with dag_maker(): ...
+        with dag_maker():
+            ...
         if result:
             dag_maker.create_dagrun(run_id=run_id)
         else:

tests/providers/amazon/aws/hooks/test_hooks_signature.py~L159

                 self.spam = spam
 
             def method1(self):
-                if self.foo == "bar": ...
+                if self.foo == "bar":
+                    ...
 
             def method2(self):
-                if self.spam == "egg": ...
+                if self.spam == "egg":
+                    ...
 
     .. code-block:: python
 

tests/providers/amazon/aws/hooks/test_hooks_signature.py~L173

                 super().__init__(*args, **kwargs)
 
             def method1(self, foo: str):
-                if foo == "bar": ...
+                if foo == "bar":
+                    ...
 
             def method2(self, spam: str):
-                if spam == "egg": ...
+                if spam == "egg":
+                    ...
 
     """
     hooks = get_aws_hooks_from_module(hook_module)

bokeh/bokeh (+0 -36 lines across 9 files)

ruff format --preview

src/bokeh/core/property/enum.py~L55

 
     @overload
     def __init__(self, enum: enums.Enumeration, *, default: Init[str] = ..., help: str | None = ...) -> None: ...
-
     @overload
     def __init__(self, enum: str, *values: str, default: Init[str] = ..., help: str | None = ...) -> None: ...
 

src/bokeh/embed/standalone.py~L143

     wrap_plot_info: Literal[True] = ...,
     theme: ThemeLike = ...,
 ) -> tuple[str, str]: ...
-
-
 @overload
 def components(models: Model, wrap_script: bool = ..., wrap_plot_info: Literal[False] = ..., theme: ThemeLike = ...) -> tuple[str, RenderRoot]: ...
 

src/bokeh/embed/standalone.py~L156

     wrap_plot_info: Literal[True] = ...,
     theme: ThemeLike = ...,
 ) -> tuple[str, Sequence[str]]: ...
-
-
 @overload
 def components(
     models: Sequence[Model], wrap_script: bool = ..., wrap_plot_info: Literal[False] = ..., theme: ThemeLike = ...

src/bokeh/embed/standalone.py~L171

     wrap_plot_info: Literal[True] = ...,
     theme: ThemeLike = ...,
 ) -> tuple[str, dict[str, str]]: ...
-
-
 @overload
 def components(
     models: dict[str, Model], wrap_script: bool = ..., wrap_plot_info: Literal[False] = ..., theme: ThemeLike = ...

src/bokeh/io/notebook.py~L609

 
 @overload
 def show_doc(obj: Model, state: State) -> None: ...
-
-
 @overload
 def show_doc(obj: Model, state: State, notebook_handle: CommsHandle) -> CommsHandle: ...
 

src/bokeh/layouts.py~L87

 
 @overload
 def row(children: list[UIElement], *, sizing_mode: SizingModeType | None = None, **kwargs: Any) -> Row: ...
-
-
 @overload
 def row(*children: UIElement, sizing_mode: SizingModeType | None = None, **kwargs: Any) -> Row: ...
 

src/bokeh/layouts.py~L126

 
 @overload
 def column(children: list[UIElement], *, sizing_mode: SizingModeType | None = None, **kwargs: Any) -> Column: ...
-
-
 @overload
 def column(*children: UIElement, sizing_mode: SizingModeType | None = None, **kwargs: Any) -> Column: ...
 

src/bokeh/layouts.py~L375

 # XXX https://github.com/python/mypy/issues/731
 @overload
 def grid(children: list[UIElement | list[UIElement | list[Any]]], *, sizing_mode: SizingModeType | None = ...) -> GridBox: ...
-
-
 @overload
 def grid(children: Row | Column, *, sizing_mode: SizingModeType | None = ...) -> GridBox: ...
-
-
 @overload
 def grid(children: list[UIElement | None], *, sizing_mode: SizingModeType | None = ..., nrows: int) -> GridBox: ...
-
-
 @overload
 def grid(children: list[UIElement | None], *, sizing_mode: SizingModeType | None = ..., ncols: int) -> GridBox: ...
-
-
 @overload
 def grid(children: list[UIElement | None], *, sizing_mode: SizingModeType | None = ..., nrows: int, ncols: int) -> GridBox: ...
-
-
 @overload
 def grid(children: str, *, sizing_mode: SizingModeType | None = ...) -> GridBox: ...
 

src/bokeh/models/plots.py~L326

 
     @overload
     def add_glyph(self, glyph: Glyph, **kwargs: Any) -> GlyphRenderer: ...
-
     @overload
     def add_glyph(self, source: ColumnarDataSource, glyph: Glyph, **kwargs: Any) -> GlyphRenderer: ...
 

src/bokeh/models/sources.py~L234

 
     @overload
     def __init__(self, data: DataDict | pd.DataFrame | pd.core.groupby.GroupBy, **kwargs: TAny) -> None: ...
-
     @overload
     def __init__(self, **kwargs: TAny) -> None: ...
 

src/bokeh/protocol/init.py~L101

 
     @overload
     def create(self, msgtype: Literal["ACK"], **metadata: Any) -> ack: ...
-
     @overload
     def create(self, msgtype: Literal["ERROR"], request_id: ID, text: str, **metadata: Any) -> error: ...
-
     @overload
     def create(self, msgtype: Literal["OK"], request_id: ID, **metadata: Any) -> ok: ...
-
     @overload
     def create(self, msgtype: Literal["PATCH-DOC"], events: list[DocumentPatchedEvent], **metadata: Any) -> patch_doc: ...
-
     @overload
     def create(self, msgtype: Literal["PULL-DOC-REPLY"], request_id: ID, document: Document, **metadata: Any) -> pull_doc_reply: ...
-
     @overload
     def create(self, msgtype: Literal["PULL-DOC-REQ"], **metadata: Any) -> pull_doc_req: ...
-
     @overload
     def create(self, msgtype: Literal["PUSH-DOC"], document: Document, **metadata: Any) -> push_doc: ...
-
     @overload
     def create(self, msgtype: Literal["SERVER-INFO-REPLY"], request_id: ID, **metadata: Any) -> server_info_reply: ...
-
     @overload
     def create(self, msgtype: Literal["SERVER-INFO-REQ"], **metadata: Any) -> server_info_req: ...
 

src/bokeh/themes/theme.py~L151

 
     @overload
     def __init__(self, filename: PathLike) -> None: ...
-
     @overload
     def __init__(self, json: dict[str, Any]) -> None: ...
 

src/bokeh/util/strings.py~L114

 
 @overload
 def format_docstring(docstring: None, *args: Any, **kwargs: Any) -> None: ...
-
-
 @overload
 def format_docstring(docstring: str, *args: Any, **kwargs: Any) -> str: ...
 

ibis-project/ibis (+4 -2 lines across 2 files)

ruff format --preview

ibis/backends/base/sql/init.py~L160

         Or you can use a context manager:
 
         ```python
-        with con.raw_sql("SELECT ...") as cursor: ...
+        with con.raw_sql("SELECT ...") as cursor:
+            ...
         ```
         :::
 

ibis/backends/base/sql/alchemy/init.py~L628

         Or you can use a context manager:
 
         ```python
-        with con.raw_sql("SELECT ...") as cursor: ...
+        with con.raw_sql("SELECT ...") as cursor:
+            ...
         ```
         :::
 

latchbio/latch (+14 -7 lines across 4 files)

ruff format --preview

latch_cli/docker_utils/init.py~L252

 
                 has_buildable_pyproject = True
                 break
-    except FileNotFoundError: ...
+    except FileNotFoundError:
+        ...
 
     # from https://peps.python.org/pep-0518/ and https://peps.python.org/pep-0621/
     if has_setup_py or has_buildable_pyproject:

latch_cli/services/get_executions.py~L221

                 prev = (curr_selected, hor_index, term_width, term_height)
                 menus.clear_screen()
                 max_row_len = render(curr_selected, hor_index, term_width, term_height)
-    except KeyboardInterrupt: ...
+    except KeyboardInterrupt:
+        ...
     finally:
         menus.clear_screen()
         menus.reveal_cursor()

latch_cli/services/get_executions.py~L314

                 menus.clear_screen()
                 prev = (curr_selected, term_width, term_height)
                 render(curr_selected, term_width, term_height)
-    except KeyboardInterrupt: ...
+    except KeyboardInterrupt:
+        ...
     finally:
         menus.clear_screen()
         menus.move_cursor((0, 0))

latch_cli/services/get_executions.py~L450

                 menus.clear_screen()
                 prev_term_dims = (vert_index, hor_index, term_width, term_height)
                 render(vert_index, hor_index, term_width, term_height)
-    except KeyboardInterrupt: ...
+    except KeyboardInterrupt:
+        ...
     finally:
         log_sched.shutdown()
         log_file.unlink(missing_ok=True)

latch_cli/services/get_executions.py~L511

             if prev_term_dims != (term_width, term_height):
                 prev_term_dims = (term_width, term_height)
                 render(term_width, term_height)
-    except KeyboardInterrupt: ...
+    except KeyboardInterrupt:
+        ...
     finally:
         menus.clear_screen()
         menus.move_cursor((0, 0))

latch_cli/services/local_dev_old.py~L313

     try:
         io_task = asyncio.gather(input_task(), output_task(), resize_task())
         await io_task
-    except asyncio.CancelledError: ...
+    except asyncio.CancelledError:
+        ...
     finally:
         termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, old_settings_stdin)
         signal.signal(signal.SIGWINCH, old_sigwinch_handler)

latch_cli/utils/init.py~L202

                     continue
 
                 exclude.append(l)
-    except FileNotFoundError: ...
+    except FileNotFoundError:
+        ...
 
     from docker.utils import exclude_paths
 

python/typeshed (+2 -1 lines across 1 file)

ruff format --preview

test_cases/stdlib/check_pathlib.py~L2

 
 from pathlib import Path, PureWindowsPath
 
-if Path("asdf") == Path("asdf"): ...
+if Path("asdf") == Path("asdf"):
+    ...
 
 # https://github.com/python/typeshed/issues/10661
 # Provide a true positive error when comparing Path to str

rotki/rotki (+2 -1 lines across 1 file)

ruff format --preview

rotkehlchen/tests/db/test_savepoints.py~L44

         conn.release_savepoint()
 
     conn._enter_savepoint("point")
-    with pytest.raises(ContextError), conn._enter_savepoint("point"): ...
+    with pytest.raises(ContextError), conn._enter_savepoint("point"):
+        ...
 
     with pytest.raises(ContextError):
         conn.rollback_savepoint("abc")

sphinx-doc/sphinx (+0 -13 lines across 1 file)

ruff format --preview

sphinx/environment/init.py~L101

     class _DomainsType(MutableMapping[str, Domain]):
         @overload
         def __getitem__(self, key: Literal["c"]) -> CDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["cpp"]) -> CPPDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["changeset"]) -> ChangeSetDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["citation"]) -> CitationDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["index"]) -> IndexDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["js"]) -> JavaScriptDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["math"]) -> MathDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["py"]) -> PythonDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["rst"]) -> ReSTDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["std"]) -> StandardDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["duration"]) -> DurationDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: Literal["todo"]) -> TodoDomain: ...  # NoQA: E704
-
         @overload
         def __getitem__(self, key: str) -> Domain: ...  # NoQA: E704
-
         def __getitem__(self, key):
             raise NotImplementedError  # NoQA: E704
 

@MichaReiser MichaReiser marked this pull request as ready for review December 22, 2023 03:31
@MichaReiser MichaReiser linked an issue Dec 22, 2023 that may be closed by this pull request
* Only collapse dummy blocks if the parent is a function definition or class definition
* Don't insert empty lines between two function definitions if the preceding statement is a dummy definition and the two definitions aren't separated by an empty line. Not enforcing an empty lines allows grouping overloaded function definitions.

Signed-off-by: Micha Reiser <[email protected]>
@MichaReiser MichaReiser merged commit 9cc257e into main Dec 22, 2023
17 checks passed
@MichaReiser MichaReiser deleted the dummy-implementations branch December 22, 2023 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter: dummy_implementations preview style
2 participants