changed all typing imports to import typing_extensions as te

This commit is contained in:
Jakob Pinterits
2024-09-27 12:35:44 +02:00
parent c4249bbe74
commit ceffb12874
18 changed files with 46 additions and 50 deletions
+1 -1
View File
@@ -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.
+4 -4
View File
@@ -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:
+2 -2
View File
@@ -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",
+3 -3
View File
@@ -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),
)
+3 -3
View File
@@ -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:
+2 -2
View File
@@ -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.
+2 -2
View File
@@ -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.
+2 -2
View File
@@ -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.
+4 -4
View File
@@ -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.
+2 -2
View File
@@ -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.
+2 -2
View File
@@ -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.
+3 -4
View File
@@ -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.
+4 -7
View File
@@ -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)
+2 -2
View File
@@ -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
)
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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(
+4 -4
View File
@@ -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
+2 -2
View File
@@ -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