diff --git a/rio/app_server/fastapi_server.py b/rio/app_server/fastapi_server.py index 25958fcb..41a192c5 100644 --- a/rio/app_server/fastapi_server.py +++ b/rio/app_server/fastapi_server.py @@ -111,7 +111,7 @@ def read_frontend_template(template_name: str) -> str: def add_cache_headers( func: t.Callable[P, t.Awaitable[fastapi.Response]], -) -> t.Callable[P, Coroutine[None, None, fastapi.Response]]: +) -> t.Callable[P, t.Coroutine[None, None, fastapi.Response]]: """ Decorator for routes that serve static files. Ensures that the response has the `Cache-Control` header set appropriately. diff --git a/rio/assets.py b/rio/assets.py index 0c90ce78..b3641f80 100644 --- a/rio/assets.py +++ b/rio/assets.py @@ -8,8 +8,8 @@ import typing as t from pathlib import Path import httpx +import typing_extensions as te from PIL.Image import Image -from typing_extensions import Self from yarl import URL import rio @@ -150,7 +150,7 @@ class Asset(SelfSerializing): return self._eq(other) @abc.abstractmethod - def _eq(self, other: Self) -> bool: + def _eq(self, other: te.Self) -> bool: raise NotImplementedError @abc.abstractmethod @@ -191,7 +191,7 @@ class HostedAsset(Asset): def __hash__(self) -> int: return hash(self.secret_id) - def _eq(self, other: Self) -> bool: + def _eq(self, other: te.Self) -> bool: return self.secret_id == other.secret_id def _serialize(self, sess: rio.Session) -> str: @@ -277,7 +277,7 @@ class UrlAsset(Asset): def __hash__(self) -> int: return hash(self._url) - def _eq(self, other: Self) -> bool: + def _eq(self, other: te.Self) -> bool: return self._url == other._url def _serialize(self, sess: rio.Session) -> str: diff --git a/rio/color.py b/rio/color.py index 16313076..d2f644de 100644 --- a/rio/color.py +++ b/rio/color.py @@ -4,7 +4,7 @@ import colorsys import math import typing as t -from typing_extensions import TypeAlias +import typing_extensions as te from uniserde import Jsonable import rio @@ -675,7 +675,7 @@ Color.TRANSPARENT = Color.from_rgb(0.0, 0.0, 0.0, 0.0) # Like color, but also allows referencing theme colors -ColorSet: TypeAlias = ( +ColorSet: te.TypeAlias = ( Color | t.Literal[ "background", diff --git a/rio/component_meta.py b/rio/component_meta.py index 18acb786..60c74a13 100644 --- a/rio/component_meta.py +++ b/rio/component_meta.py @@ -9,7 +9,7 @@ from collections import defaultdict from dataclasses import field import introspection -from typing_extensions import dataclass_transform +import typing_extensions as te import rio @@ -26,8 +26,8 @@ C = t.TypeVar("C", bound="rio.Component") # For some reason vscode doesn't understand that this class is a -# `@dataclass_transform`, so we'll annotate it again... -@dataclass_transform( +# `@te.dataclass_transform`, so we'll annotate it again... +@te.dataclass_transform( eq_default=False, field_specifiers=(internal_field, field), ) diff --git a/rio/components/component.py b/rio/components/component.py index a78fc057..e60b5ef6 100644 --- a/rio/components/component.py +++ b/rio/components/component.py @@ -7,7 +7,7 @@ from abc import abstractmethod from dataclasses import KW_ONLY from pathlib import Path -from typing_extensions import Self +import typing_extensions as te from uniserde import Jsonable, JsonDoc import rio @@ -378,9 +378,9 @@ class Component(abc.ABC, metaclass=ComponentMeta): """ return self._session_ - # There isn't really a good type annotation for this... Self is the closest + # There isn't really a good type annotation for this... `te.Self` is the closest # thing - def bind(self) -> Self: + def bind(self) -> te.Self: return AttributeBindingMaker(self) # type: ignore def _custom_serialize_(self) -> JsonDoc: diff --git a/rio/components/flow_container.py b/rio/components/flow_container.py index 8ab81c2d..d32b10b8 100644 --- a/rio/components/flow_container.py +++ b/rio/components/flow_container.py @@ -3,7 +3,7 @@ from __future__ import annotations import typing as t from dataclasses import KW_ONLY -from typing_extensions import Self +import typing_extensions as te from uniserde import JsonDoc import rio @@ -113,7 +113,7 @@ class FlowContainer(FundamentalComponent): self.column_spacing = column_spacing self.justify = justify - def add(self, child: rio.Component) -> Self: + def add(self, child: rio.Component) -> te.Self: """ Appends a child component. diff --git a/rio/components/grid.py b/rio/components/grid.py index 1670f371..82e06160 100644 --- a/rio/components/grid.py +++ b/rio/components/grid.py @@ -4,7 +4,7 @@ import math import typing as t from dataclasses import KW_ONLY, dataclass -from typing_extensions import Self +import typing_extensions as te from uniserde import JsonDoc import rio @@ -210,7 +210,7 @@ class Grid(FundamentalComponent): *, width: int = 1, height: int = 1, - ) -> Self: + ) -> te.Self: """ Add a child to the grid at a specified position. diff --git a/rio/components/labeled_column.py b/rio/components/labeled_column.py index d3989d1e..adb96152 100644 --- a/rio/components/labeled_column.py +++ b/rio/components/labeled_column.py @@ -3,7 +3,7 @@ from __future__ import annotations import typing as t from dataclasses import field -from typing_extensions import Self +import typing_extensions as te import rio @@ -99,7 +99,7 @@ class LabeledColumn(Component): self._content = dict(children) self._child_list = list(children.values()) - def add(self, label: str, child: rio.Component) -> Self: + def add(self, label: str, child: rio.Component) -> te.Self: """ Appends a child component. diff --git a/rio/components/linear_containers.py b/rio/components/linear_containers.py index f046df3b..6d5365ec 100644 --- a/rio/components/linear_containers.py +++ b/rio/components/linear_containers.py @@ -2,7 +2,7 @@ from __future__ import annotations import typing as t -from typing_extensions import Self +import typing_extensions as te from uniserde import JsonDoc import rio @@ -24,7 +24,7 @@ class _LinearContainer(FundamentalComponent): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - def add(self, child: rio.Component) -> Self: + def add(self, child: rio.Component) -> te.Self: self.children.append(child) return self @@ -169,7 +169,7 @@ class Row(_LinearContainer): self.spacing = spacing self.proportions = proportions - def add(self, child: rio.Component) -> Self: + def add(self, child: rio.Component) -> te.Self: """ Appends a child component. @@ -325,7 +325,7 @@ class Column(_LinearContainer): self.spacing = spacing self.proportions = proportions - def add(self, child: rio.Component) -> Self: + def add(self, child: rio.Component) -> te.Self: """ Appends a child component. diff --git a/rio/components/list_view.py b/rio/components/list_view.py index fa9c2f4f..f7d7ba76 100644 --- a/rio/components/list_view.py +++ b/rio/components/list_view.py @@ -2,7 +2,7 @@ from __future__ import annotations import typing as t -from typing_extensions import Self +import typing_extensions as te import rio @@ -140,7 +140,7 @@ class ListView(FundamentalComponent): self.children = list(children) - def add(self, child: rio.Component) -> Self: + def add(self, child: rio.Component) -> te.Self: """ Appends a child component. diff --git a/rio/components/stack.py b/rio/components/stack.py index 79bb482c..5330abbb 100644 --- a/rio/components/stack.py +++ b/rio/components/stack.py @@ -2,7 +2,7 @@ from __future__ import annotations import typing as t -from typing_extensions import Self +import typing_extensions as te import rio @@ -113,7 +113,7 @@ class Stack(FundamentalComponent): self.children = list(children) - def add(self, child: rio.Component) -> Self: + def add(self, child: rio.Component) -> te.Self: """ Appends a child component. diff --git a/rio/data_models.py b/rio/data_models.py index 0d0e0ff0..44767fb9 100644 --- a/rio/data_models.py +++ b/rio/data_models.py @@ -3,11 +3,10 @@ from __future__ import annotations import typing as t from dataclasses import dataclass -import uniserde - # Never import * from typing_extensions! It breaks `Any` on 3.10, preventing # users from connecting. Ask me how I know. -from typing_extensions import Self +import typing_extensions as te +import uniserde import rio @@ -89,7 +88,7 @@ class InitialClientMessage(uniserde.Serde): *, url: str, user_settings: uniserde.JsonDoc = {}, - ) -> Self: + ) -> te.Self: """ Convenience method for creating default settings when they don't really matter: unit tests, crawlers, etc. diff --git a/rio/dataclass.py b/rio/dataclass.py index fb6c9d2a..4f85f668 100644 --- a/rio/dataclass.py +++ b/rio/dataclass.py @@ -7,10 +7,7 @@ import functools import inspect import typing as t -from typing_extensions import ( - Self, - dataclass_transform, -) +import typing_extensions as te from . import inspection @@ -86,7 +83,7 @@ class RioField(dataclasses.Field): self.real_default_value = real_default_value @classmethod - def from_dataclass_field(cls, field: dataclasses.Field) -> Self: + def from_dataclass_field(cls, field: dataclasses.Field) -> te.Self: if field.default is dataclasses.MISSING: default = field.default default_factory = field.default_factory @@ -130,12 +127,12 @@ def _make_default_factory_for_value(value: T) -> t.Callable[[], T]: return functools.partial(copy.deepcopy, value) -@dataclass_transform( +@te.dataclass_transform( eq_default=False, field_specifiers=(internal_field, dataclasses.field), ) class RioDataclassMeta(abc.ABCMeta): - def __init__(cls, *args, **kwargs): + def __init__(cls, *args, **kwargs) -> None: super().__init__(*args, **kwargs) cls_vars = vars(cls) diff --git a/rio/fills.py b/rio/fills.py index 591214e2..4a569505 100644 --- a/rio/fills.py +++ b/rio/fills.py @@ -4,7 +4,7 @@ import typing as t from abc import ABC from dataclasses import dataclass -from typing_extensions import TypeAlias +import typing_extensions as te from uniserde import Jsonable import rio @@ -239,6 +239,6 @@ class FrostedGlassFill(Fill): } -_FillLike: TypeAlias = ( +_FillLike: te.TypeAlias = ( SolidFill | LinearGradientFill | ImageFill | FrostedGlassFill | Color ) diff --git a/rio/snippets/__init__.py b/rio/snippets/__init__.py index 083ece0c..d266528c 100644 --- a/rio/snippets/__init__.py +++ b/rio/snippets/__init__.py @@ -9,8 +9,8 @@ import urllib.parse from dataclasses import dataclass from pathlib import Path +import typing_extensions as te import uniserde -from typing_extensions import TypeAlias from .. import utils @@ -31,7 +31,7 @@ DEFAULT_META_DICT = { # # THE ORDER MATTERS. `revel` will display the options in the same order as they # appear in the literal -AvailableTemplatesLiteral: TypeAlias = t.Literal[ +AvailableTemplatesLiteral: te.TypeAlias = t.Literal[ # Keep the empty template first "Empty", # Sort the remainder alphabetically diff --git a/rio/testing.py b/rio/testing.py index 53f77438..191861ad 100644 --- a/rio/testing.py +++ b/rio/testing.py @@ -3,7 +3,7 @@ import typing as t import ordered_set import starlette.datastructures -from typing_extensions import Self +import typing_extensions as te from uniserde import JsonDoc import rio @@ -102,7 +102,7 @@ class TestClient: if message["method"] == "updateComponentStates": self._first_refresh_completed.set() - async def __aenter__(self) -> Self: + async def __aenter__(self) -> te.Self: url = str(rio.URL("http://unit.test") / self._active_url.lstrip("/")) self._session = await self._app_server.create_session( diff --git a/rio/user_settings_module.py b/rio/user_settings_module.py index 5453e68c..1ced12d2 100644 --- a/rio/user_settings_module.py +++ b/rio/user_settings_module.py @@ -4,8 +4,8 @@ import copy import typing as t from dataclasses import field +import typing_extensions as te import uniserde -from typing_extensions import Self from . import inspection, session from .dataclass import RioDataclassMeta, all_class_fields @@ -102,8 +102,8 @@ class UserSettings(metaclass=RioDataclassMeta): def _from_json( cls, settings_json: uniserde.JsonDoc, - defaults: Self, - ) -> Self: + defaults: te.Self, + ) -> te.Self: # Create the instance for this attachment. Bypass the constructor so the # instance doesn't immediately try to synchronize with the frontend. self = object.__new__(cls) @@ -163,7 +163,7 @@ class UserSettings(metaclass=RioDataclassMeta): if not t.TYPE_CHECKING: __setattr__ = __setattr - def _equals(self, other: Self) -> bool: + def _equals(self, other: te.Self) -> bool: if type(self) != type(other): return False diff --git a/rio/utils.py b/rio/utils.py index 7faaf4c9..06353efb 100644 --- a/rio/utils.py +++ b/rio/utils.py @@ -14,8 +14,8 @@ from io import BytesIO, StringIO from pathlib import Path import imy.assets +import typing_extensions as te from PIL.Image import Image -from typing_extensions import Annotated from yarl import URL import rio @@ -57,7 +57,7 @@ else: # Constants & types _READONLY = object() T = t.TypeVar("T") -Readonly = Annotated[T, _READONLY] +Readonly = te.Annotated[T, _READONLY] ImageLike = Path | Image | URL | bytes