Skip to content

Commit 7e6f9a3

Browse files
committed
Remove deprecated code
1 parent 3e2931d commit 7e6f9a3

File tree

7 files changed

+34
-150
lines changed

7 files changed

+34
-150
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ Don't forget to remove deprecated code on each major release!
4040

4141
- Removed dependency on `aiofile`.
4242

43+
### Removed
44+
45+
- Removed the following **deprecated** features:
46+
- The `compatibility` argument on `reactpy_django.components.view_to_component`
47+
- `reactpy_django.components.view_to_component` **usage as a decorator**
48+
- `reactpy_django.decorators.auth_required`
49+
- `reactpy_django.REACTPY_WEBSOCKET_PATH`
50+
- `settings.py:REACTPY_WEBSOCKET_URL`
51+
4352
## [4.0.0] - 2024-06-22
4453

4554
### Added

src/reactpy_django/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import nest_asyncio
44

55
from reactpy_django import (
6-
checks,
76
components,
87
decorators,
98
hooks,
@@ -12,22 +11,17 @@
1211
types,
1312
utils,
1413
)
15-
from reactpy_django.websocket.paths import (
16-
REACTPY_WEBSOCKET_PATH,
17-
REACTPY_WEBSOCKET_ROUTE,
18-
)
14+
from reactpy_django.websocket.paths import REACTPY_WEBSOCKET_ROUTE
1915

2016
__version__ = "4.0.0"
2117
__all__ = [
22-
"REACTPY_WEBSOCKET_PATH",
2318
"REACTPY_WEBSOCKET_ROUTE",
2419
"html",
2520
"hooks",
2621
"components",
2722
"decorators",
2823
"types",
2924
"utils",
30-
"checks",
3125
"router",
3226
]
3327

src/reactpy_django/checks.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,7 @@ def reactpy_warnings(app_configs, **kwargs):
102102

103103
# DELETED W007: Check if REACTPY_WEBSOCKET_URL doesn't end with a slash
104104
# DELETED W008: Check if REACTPY_WEBSOCKET_URL doesn't start with an alphanumeric character
105-
106-
# Removed REACTPY_WEBSOCKET_URL setting
107-
if getattr(settings, "REACTPY_WEBSOCKET_URL", None):
108-
warnings.append(
109-
Warning(
110-
"REACTPY_WEBSOCKET_URL has been removed.",
111-
hint="Use REACTPY_URL_PREFIX instead.",
112-
id="reactpy_django.W009",
113-
)
114-
)
105+
# DELETED W009: Check if deprecated value REACTPY_WEBSOCKET_URL exists
115106

116107
# Check if REACTPY_URL_PREFIX is being used properly in our HTTP URLs
117108
with contextlib.suppress(NoReverseMatch):
@@ -158,15 +149,7 @@ def reactpy_warnings(app_configs, **kwargs):
158149
)
159150
)
160151

161-
# Removed REACTPY_RECONNECT_MAX setting
162-
if getattr(settings, "REACTPY_RECONNECT_MAX", None):
163-
warnings.append(
164-
Warning(
165-
"REACTPY_RECONNECT_MAX has been removed.",
166-
hint="See the docs for the new REACTPY_RECONNECT_* settings.",
167-
id="reactpy_django.W013",
168-
)
169-
)
152+
# DELETED W013: Check if deprecated value REACTPY_RECONNECT_MAX exists
170153

171154
if (
172155
isinstance(config.REACTPY_RECONNECT_INTERVAL, int)

src/reactpy_django/components.py

Lines changed: 17 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import json
44
import os
5-
from typing import Any, Callable, Sequence, Union, cast, overload
5+
from typing import Any, Callable, Sequence, Union, cast
66
from urllib.parse import urlencode
77
from uuid import uuid4
8-
from warnings import warn
98

109
from django.contrib.staticfiles.finders import find
1110
from django.core.cache import caches
@@ -26,40 +25,15 @@
2625
)
2726

2827

29-
# Type hints for:
30-
# 1. example = view_to_component(my_view, ...)
31-
# 2. @view_to_component
32-
@overload
3328
def view_to_component(
3429
view: Callable | View | str,
35-
compatibility: bool = False,
3630
transforms: Sequence[Callable[[VdomDict], Any]] = (),
3731
strict_parsing: bool = True,
38-
) -> Any: ...
39-
40-
41-
# Type hints for:
42-
# 1. @view_to_component(...)
43-
@overload
44-
def view_to_component(
45-
view: None = ...,
46-
compatibility: bool = False,
47-
transforms: Sequence[Callable[[VdomDict], Any]] = (),
48-
strict_parsing: bool = True,
49-
) -> Callable[[Callable], Any]: ...
50-
51-
52-
def view_to_component(
53-
view: Callable | View | str | None = None,
54-
compatibility: bool = False,
55-
transforms: Sequence[Callable[[VdomDict], Any]] = (),
56-
strict_parsing: bool = True,
57-
) -> Any | Callable[[Callable], Any]:
32+
) -> Any:
5833
"""Converts a Django view to a ReactPy component.
5934
6035
Keyword Args:
6136
view: The view to convert, or the view's dotted path as a string.
62-
compatibility: **DEPRECATED.** Use `view_to_iframe` instead.
6337
transforms: A list of functions that transforms the newly generated VDOM. \
6438
The functions will be called on each VDOM node.
6539
strict_parsing: If True, an exception will be generated if the HTML does not \
@@ -69,37 +43,23 @@ def view_to_component(
6943
A function that takes `request, *args, key, **kwargs` and returns a ReactPy component.
7044
"""
7145

72-
def decorator(view: Callable | View | str):
73-
if not view:
74-
raise ValueError("A view must be provided to `view_to_component`")
75-
76-
def constructor(
77-
request: HttpRequest | None = None,
78-
*args,
79-
key: Key | None = None,
80-
**kwargs,
81-
):
82-
return _view_to_component(
83-
view=view,
84-
compatibility=compatibility,
85-
transforms=transforms,
86-
strict_parsing=strict_parsing,
87-
request=request,
88-
args=args,
89-
kwargs=kwargs,
90-
key=key,
91-
)
92-
93-
return constructor
94-
95-
if not view:
96-
warn(
97-
"Using `view_to_component` as a decorator is deprecated. "
98-
"This functionality will be removed in a future version.",
99-
DeprecationWarning,
46+
def constructor(
47+
request: HttpRequest | None = None,
48+
*args,
49+
key: Key | None = None,
50+
**kwargs,
51+
):
52+
return _view_to_component(
53+
view=view,
54+
transforms=transforms,
55+
strict_parsing=strict_parsing,
56+
request=request,
57+
args=args,
58+
kwargs=kwargs,
59+
key=key,
10060
)
10161

102-
return decorator(view) if view else decorator
62+
return constructor
10363

10464

10565
def view_to_iframe(
@@ -180,7 +140,6 @@ def pyscript_component(
180140
@component
181141
def _view_to_component(
182142
view: Callable | View | str,
183-
compatibility: bool,
184143
transforms: Sequence[Callable[[VdomDict], Any]],
185144
strict_parsing: bool,
186145
request: HttpRequest | None,
@@ -209,10 +168,6 @@ def _view_to_component(
209168
)
210169
async def async_render():
211170
"""Render the view in an async hook to avoid blocking the main thread."""
212-
# Compatibility mode doesn't require a traditional render
213-
if compatibility:
214-
return
215-
216171
# Render the view
217172
response = await render_view(resolved_view, _request, _args, _kwargs)
218173
set_converted_view(
@@ -224,17 +179,6 @@ async def async_render():
224179
)
225180
)
226181

227-
# Render in compatibility mode, if needed
228-
if compatibility:
229-
# Warn the user that compatibility mode is deprecated
230-
warn(
231-
"view_to_component(compatibility=True) is deprecated and will be removed in a future version. "
232-
"Please use `view_to_iframe` instead.",
233-
DeprecationWarning,
234-
)
235-
236-
return view_to_iframe(resolved_view)(*_args, **_kwargs)
237-
238182
# Return the view if it's been rendered via the `async_render` hook
239183
return converted_view
240184

src/reactpy_django/config.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@
2323
REACTPY_FAILED_COMPONENTS: set[str] = set()
2424
REACTPY_REGISTERED_IFRAME_VIEWS: dict[str, Callable | View] = {}
2525

26-
27-
# Remove in a future release
28-
REACTPY_WEBSOCKET_URL = getattr(
29-
settings,
30-
"REACTPY_WEBSOCKET_URL",
31-
"reactpy/",
32-
)
33-
3426
# Configurable through Django settings.py
3527
REACTPY_URL_PREFIX: str = getattr(
3628
settings,
3729
"REACTPY_URL_PREFIX",
38-
REACTPY_WEBSOCKET_URL,
30+
"reactpy/",
3931
).strip("/")
4032
REACTPY_SESSION_MAX_AGE: int = getattr(
4133
settings,

src/reactpy_django/decorators.py

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,17 @@
22

33
from functools import wraps
44
from typing import TYPE_CHECKING, Any, Callable
5-
from warnings import warn
65

76
from reactpy import component
8-
from reactpy.core.types import ComponentConstructor, ComponentType, VdomDict
7+
from reactpy.core.types import ComponentConstructor
98

109
from reactpy_django.exceptions import DecoratorParamError
11-
from reactpy_django.hooks import use_scope, use_user
10+
from reactpy_django.hooks import use_user
1211

1312
if TYPE_CHECKING:
1413
from django.contrib.auth.models import AbstractUser
1514

1615

17-
def auth_required(
18-
component: Callable | None = None,
19-
auth_attribute: str = "is_active",
20-
fallback: ComponentType | Callable | VdomDict | None = None,
21-
) -> Callable:
22-
"""If the user passes authentication criteria, the decorated component will be rendered.
23-
Otherwise, the fallback component will be rendered.
24-
25-
This decorator can be used with or without parentheses.
26-
27-
Args:
28-
auth_attribute: The value to check within the user object. \
29-
This is checked in the form of `UserModel.<auth_attribute>`. \
30-
fallback: The component or VDOM (`reactpy.html` snippet) to render if the user is not authenticated.
31-
"""
32-
33-
warn(
34-
"auth_required is deprecated and will be removed in the next major version. "
35-
"An equivalent to this decorator's default is @user_passes_test(lambda user: user.is_active).",
36-
DeprecationWarning,
37-
)
38-
39-
def decorator(component):
40-
@wraps(component)
41-
def _wrapped_func(*args, **kwargs):
42-
scope = use_scope()
43-
44-
if getattr(scope["user"], auth_attribute):
45-
return component(*args, **kwargs)
46-
return fallback(*args, **kwargs) if callable(fallback) else fallback
47-
48-
return _wrapped_func
49-
50-
# Return for @authenticated(...) and @authenticated respectively
51-
return decorator if component is None else decorator(component)
5216

5317

5418
def user_passes_test(

src/reactpy_django/websocket/paths.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
)
1111
"""A URL path for :class:`ReactpyAsyncWebsocketConsumer`.
1212
13-
Required since the `reverse()` function does not exist for Django Channels, but we need
14-
to know the websocket path.
13+
Required since the `reverse()` function does not exist for Django Channels, but ReactPy needs
14+
to know the current websocket path.
1515
"""
16-
17-
REACTPY_WEBSOCKET_PATH = REACTPY_WEBSOCKET_ROUTE

0 commit comments

Comments
 (0)