From 21011917ac799a0bcd1f887eefa83198d01ddcbc Mon Sep 17 00:00:00 2001 From: Ryan Morshead Date: Sat, 10 Feb 2024 10:59:16 -0800 Subject: [PATCH] fix black lint (#1193) --- .../_examples/set_remove.py | 6 ++--- .../_examples/set_update.py | 6 ++--- pyproject.toml | 6 ++--- .../reactpy/reactpy/core/_life_cycle_hook.py | 3 +-- src/py/reactpy/reactpy/core/events.py | 6 ++--- src/py/reactpy/reactpy/core/hooks.py | 27 +++++++------------ src/py/reactpy/reactpy/core/types.py | 17 +++++------- src/py/reactpy/reactpy/core/vdom.py | 9 +++---- src/py/reactpy/reactpy/web/module.py | 6 ++--- src/py/reactpy/reactpy/widgets.py | 3 +-- .../test_rewrite_camel_case_props.py | 6 ++--- .../tests/test__console/test_rewrite_keys.py | 6 ++--- src/py/reactpy/tests/test_core/test_layout.py | 6 ++--- tasks.py | 3 +-- 14 files changed, 43 insertions(+), 67 deletions(-) diff --git a/docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_remove.py b/docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_remove.py index be5366cb..abe55a91 100644 --- a/docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_remove.py +++ b/docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_remove.py @@ -24,9 +24,9 @@ def Grid(): "style": { "height": "30px", "width": "30px", - "background_color": "black" - if index in selected_indices - else "white", + "background_color": ( + "black" if index in selected_indices else "white" + ), "outline": "1px solid grey", "cursor": "pointer", }, diff --git a/docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_update.py b/docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_update.py index 8ff2e1ca..27f170a4 100644 --- a/docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_update.py +++ b/docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/set_update.py @@ -21,9 +21,9 @@ def Grid(): "style": { "height": "30px", "width": "30px", - "background_color": "black" - if index in selected_indices - else "white", + "background_color": ( + "black" if index in selected_indices else "white" + ), "outline": "1px solid grey", "cursor": "pointer", }, diff --git a/pyproject.toml b/pyproject.toml index 3cf94e23..775ab01a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,10 +12,10 @@ detached = true dependencies = [ "invoke", # lint - "black", - "ruff==0.0.278", # Ruff is moving really fast, so pinning for now. + "black==24.1.1", # Pin lint tools we don't control to avoid breaking changes + "ruff==0.0.278", # Pin lint tools we don't control to avoid breaking changes "toml", - "flake8", + "flake8==7.0.0", # Pin lint tools we don't control to avoid breaking changes "flake8-pyproject", "reactpy-flake8 >=0.7", # types diff --git a/src/py/reactpy/reactpy/core/_life_cycle_hook.py b/src/py/reactpy/reactpy/core/_life_cycle_hook.py index ea5e6d63..88d3386a 100644 --- a/src/py/reactpy/reactpy/core/_life_cycle_hook.py +++ b/src/py/reactpy/reactpy/core/_life_cycle_hook.py @@ -13,8 +13,7 @@ T = TypeVar("T") class EffectFunc(Protocol): - async def __call__(self, stop: Event) -> None: - ... + async def __call__(self, stop: Event) -> None: ... logger = logging.getLogger(__name__) diff --git a/src/py/reactpy/reactpy/core/events.py b/src/py/reactpy/reactpy/core/events.py index cd5de322..f715b7e9 100644 --- a/src/py/reactpy/reactpy/core/events.py +++ b/src/py/reactpy/reactpy/core/events.py @@ -15,8 +15,7 @@ def event( *, stop_propagation: bool = ..., prevent_default: bool = ..., -) -> EventHandler: - ... +) -> EventHandler: ... @overload @@ -25,8 +24,7 @@ def event( *, stop_propagation: bool = ..., prevent_default: bool = ..., -) -> Callable[[Callable[..., Any]], EventHandler]: - ... +) -> Callable[[Callable[..., Any]], EventHandler]: ... def event( diff --git a/src/py/reactpy/reactpy/core/hooks.py b/src/py/reactpy/reactpy/core/hooks.py index 4513dade..640cbf14 100644 --- a/src/py/reactpy/reactpy/core/hooks.py +++ b/src/py/reactpy/reactpy/core/hooks.py @@ -42,13 +42,11 @@ _Type = TypeVar("_Type") @overload -def use_state(initial_value: Callable[[], _Type]) -> State[_Type]: - ... +def use_state(initial_value: Callable[[], _Type]) -> State[_Type]: ... @overload -def use_state(initial_value: _Type) -> State[_Type]: - ... +def use_state(initial_value: _Type) -> State[_Type]: ... def use_state(initial_value: _Type | Callable[[], _Type]) -> State[_Type]: @@ -105,16 +103,14 @@ _EffectApplyFunc: TypeAlias = "_SyncEffectFunc | _AsyncEffectFunc" def use_effect( function: None = None, dependencies: Sequence[Any] | ellipsis | None = ..., -) -> Callable[[_EffectApplyFunc], None]: - ... +) -> Callable[[_EffectApplyFunc], None]: ... @overload def use_effect( function: _EffectApplyFunc, dependencies: Sequence[Any] | ellipsis | None = ..., -) -> None: - ... +) -> None: ... def use_effect( @@ -313,16 +309,14 @@ _CallbackFunc = TypeVar("_CallbackFunc", bound=Callable[..., Any]) def use_callback( function: None = None, dependencies: Sequence[Any] | ellipsis | None = ..., -) -> Callable[[_CallbackFunc], _CallbackFunc]: - ... +) -> Callable[[_CallbackFunc], _CallbackFunc]: ... @overload def use_callback( function: _CallbackFunc, dependencies: Sequence[Any] | ellipsis | None = ..., -) -> _CallbackFunc: - ... +) -> _CallbackFunc: ... def use_callback( @@ -358,24 +352,21 @@ def use_callback( class _LambdaCaller(Protocol): """MyPy doesn't know how to deal with TypeVars only used in function return""" - def __call__(self, func: Callable[[], _Type]) -> _Type: - ... + def __call__(self, func: Callable[[], _Type]) -> _Type: ... @overload def use_memo( function: None = None, dependencies: Sequence[Any] | ellipsis | None = ..., -) -> _LambdaCaller: - ... +) -> _LambdaCaller: ... @overload def use_memo( function: Callable[[], _Type], dependencies: Sequence[Any] | ellipsis | None = ..., -) -> _Type: - ... +) -> _Type: ... def use_memo( diff --git a/src/py/reactpy/reactpy/core/types.py b/src/py/reactpy/reactpy/core/types.py index 39a9b353..b451be30 100644 --- a/src/py/reactpy/reactpy/core/types.py +++ b/src/py/reactpy/reactpy/core/types.py @@ -159,8 +159,7 @@ EventHandlerDict: TypeAlias = "dict[str, EventHandlerType]" class EventHandlerFunc(Protocol): """A coroutine which can handle event data""" - async def __call__(self, data: Sequence[Any]) -> None: - ... + async def __call__(self, data: Sequence[Any]) -> None: ... @runtime_checkable @@ -192,18 +191,17 @@ class VdomDictConstructor(Protocol): """Standard function for constructing a :class:`VdomDict`""" @overload - def __call__(self, attributes: VdomAttributes, *children: VdomChildren) -> VdomDict: - ... + def __call__( + self, attributes: VdomAttributes, *children: VdomChildren + ) -> VdomDict: ... @overload - def __call__(self, *children: VdomChildren) -> VdomDict: - ... + def __call__(self, *children: VdomChildren) -> VdomDict: ... @overload def __call__( self, *attributes_and_children: VdomAttributes | VdomChildren - ) -> VdomDict: - ... + ) -> VdomDict: ... class LayoutUpdateMessage(TypedDict): @@ -236,8 +234,7 @@ class Context(Protocol[_Type]): *children: Any, value: _Type = ..., key: Key | None = ..., - ) -> ContextProviderType[_Type]: - ... + ) -> ContextProviderType[_Type]: ... class ContextProviderType(ComponentType, Protocol[_Type]): diff --git a/src/py/reactpy/reactpy/core/vdom.py b/src/py/reactpy/reactpy/core/vdom.py index 840a09c7..e494b526 100644 --- a/src/py/reactpy/reactpy/core/vdom.py +++ b/src/py/reactpy/reactpy/core/vdom.py @@ -125,13 +125,11 @@ def is_vdom(value: Any) -> bool: @overload -def vdom(tag: str, *children: VdomChildren) -> VdomDict: - ... +def vdom(tag: str, *children: VdomChildren) -> VdomDict: ... @overload -def vdom(tag: str, attributes: VdomAttributes, *children: VdomChildren) -> VdomDict: - ... +def vdom(tag: str, attributes: VdomAttributes, *children: VdomChildren) -> VdomDict: ... def vdom( @@ -345,8 +343,7 @@ class _CustomVdomDictConstructor(Protocol): children: Sequence[VdomChild], key: Key | None, event_handlers: EventHandlerDict, - ) -> VdomDict: - ... + ) -> VdomDict: ... class _EllipsisRepr: diff --git a/src/py/reactpy/reactpy/web/module.py b/src/py/reactpy/reactpy/web/module.py index 48322fe2..c3192da4 100644 --- a/src/py/reactpy/reactpy/web/module.py +++ b/src/py/reactpy/reactpy/web/module.py @@ -314,8 +314,7 @@ def export( export_names: str, fallback: Any | None = ..., allow_children: bool = ..., -) -> VdomDictConstructor: - ... +) -> VdomDictConstructor: ... @overload @@ -324,8 +323,7 @@ def export( export_names: list[str] | tuple[str, ...], fallback: Any | None = ..., allow_children: bool = ..., -) -> list[VdomDictConstructor]: - ... +) -> list[VdomDictConstructor]: ... def export( diff --git a/src/py/reactpy/reactpy/widgets.py b/src/py/reactpy/reactpy/widgets.py index 29f94144..63b45a7e 100644 --- a/src/py/reactpy/reactpy/widgets.py +++ b/src/py/reactpy/reactpy/widgets.py @@ -82,8 +82,7 @@ _CastTo_co = TypeVar("_CastTo_co", covariant=True) class _CastFunc(Protocol[_CastTo_co]): - def __call__(self, value: str) -> _CastTo_co: - ... + def __call__(self, value: str) -> _CastTo_co: ... if TYPE_CHECKING: diff --git a/src/py/reactpy/tests/test__console/test_rewrite_camel_case_props.py b/src/py/reactpy/tests/test__console/test_rewrite_camel_case_props.py index 47b8baab..ca928cf3 100644 --- a/src/py/reactpy/tests/test__console/test_rewrite_camel_case_props.py +++ b/src/py/reactpy/tests/test__console/test_rewrite_camel_case_props.py @@ -106,9 +106,9 @@ def test_rewrite_camel_case_props_declarations_no_files(): None, ), ], - ids=lambda item: " ".join(map(str.strip, item.split())) - if isinstance(item, str) - else item, + ids=lambda item: ( + " ".join(map(str.strip, item.split())) if isinstance(item, str) else item + ), ) def test_generate_rewrite(source, expected): actual = generate_rewrite(Path("test.py"), dedent(source).strip()) diff --git a/src/py/reactpy/tests/test__console/test_rewrite_keys.py b/src/py/reactpy/tests/test__console/test_rewrite_keys.py index da0b26c4..95c49a01 100644 --- a/src/py/reactpy/tests/test__console/test_rewrite_keys.py +++ b/src/py/reactpy/tests/test__console/test_rewrite_keys.py @@ -225,9 +225,9 @@ def test_rewrite_key_declarations_no_files(): None, ), ], - ids=lambda item: " ".join(map(str.strip, item.split())) - if isinstance(item, str) - else item, + ids=lambda item: ( + " ".join(map(str.strip, item.split())) if isinstance(item, str) else item + ), ) def test_generate_rewrite(source, expected): actual = generate_rewrite(Path("test.py"), dedent(source).strip()) diff --git a/src/py/reactpy/tests/test_core/test_layout.py b/src/py/reactpy/tests/test_core/test_layout.py index 6eec7a8d..cfb54475 100644 --- a/src/py/reactpy/tests/test_core/test_layout.py +++ b/src/py/reactpy/tests/test_core/test_layout.py @@ -48,8 +48,7 @@ def no_logged_errors(): def test_layout_repr(): @reactpy.component - def MyComponent(): - ... + def MyComponent(): ... my_component = MyComponent() layout = reactpy.Layout(my_component) @@ -65,8 +64,7 @@ def test_layout_expects_abstract_component(): async def test_layout_cannot_be_used_outside_context_manager(caplog): @reactpy.component - def Component(): - ... + def Component(): ... component = Component() layout = reactpy.Layout(component) diff --git a/tasks.py b/tasks.py index 65f75b20..e11d291e 100644 --- a/tasks.py +++ b/tasks.py @@ -28,8 +28,7 @@ if TYPE_CHECKING: class ReleasePrepFunc(Protocol): def __call__( self, context: Context, package: PackageInfo - ) -> Callable[[bool], None]: - ... + ) -> Callable[[bool], None]: ... LanguageName: TypeAlias = "Literal['py', 'js']"