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

Refactor code, add Enum deprecation utils #2259

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, Optional

from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dataclasses
from typing import Any, List, Optional

from flet_core.canvas.path import Path
Expand Down
1 change: 0 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/canvas/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from flet_core.canvas.shape import Shape
from flet_core.control import OptionalNumber
from flet_core.inline_span import InlineSpan
from flet_core.text_span import TextSpan
from flet_core.text_style import TextStyle
from flet_core.types import TextAlign

Expand Down
10 changes: 0 additions & 10 deletions sdk/python/packages/flet-core/src/flet_core/circle_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def main(page):

def __init__(
self,
icon: Optional[str] = None,
key: Optional[str] = None,
ref: Optional[Ref] = None,
width: OptionalNumber = None,
Expand Down Expand Up @@ -175,15 +174,6 @@ def background_image_url(self):
def background_image_url(self, value):
self._set_attr("backgroundImageUrl", value)

# icon
@property
def icon(self):
return self._get_attr("icon")

@icon.setter
def icon(self, value):
self._set_attr("icon", value)

# radius
@property
def radius(self):
Expand Down
1 change: 0 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/clipboard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dataclasses
import time
from typing import Any, Optional

from flet_core.control import Control
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional, Union
from typing import Any, Optional, Union

from flet_core.constrained_control import ConstrainedControl
from flet_core.control import OptionalNumber
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional, Union
from typing import Any, Optional, Union

from flet_core.constrained_control import ConstrainedControl
from flet_core.control import OptionalNumber
Expand All @@ -7,7 +7,6 @@
AnimationValue,
LabelPosition,
LabelPositionString,
MaterialState,
OffsetValue,
ResponsiveNumber,
RotateValue,
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-core/src/flet_core/date_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.text_style import TextStyle
from flet_core.textfield import KeyboardType, KeyboardTypeString
from flet_core.textfield import KeyboardType
from flet_core.types import ResponsiveNumber

try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import dataclasses
import time
from typing import Any, Optional

from flet_core.control import Control
Expand Down
1 change: 0 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
ResponsiveNumber,
RotateValue,
ScaleValue,
ScrollMode,
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import List

import flet_core
from flet_core.connection import Connection
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/locks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class NopeLock():
class NopeLock:
def __enter__(self):
pass

def __exit__(self, *args):
pass


class AsyncNopeLock():
class AsyncNopeLock:
async def __aenter__(self):
pass

Expand Down
11 changes: 3 additions & 8 deletions sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from enum import Enum
from typing import Any, List, Optional, Union
from typing import Any, List, Optional

from flet_core.constrained_control import ConstrainedControl
from flet_core.buttons import OutlinedBorder
from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.types import (
PaddingValue,
)

from flet_core.buttons import OutlinedBorder
from flet_core.types import PaddingValue


class NavigationDrawerDestination(Control):
Expand Down
1 change: 0 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
RotateValue,
ScaleValue,
ScrollMode,
ScrollModeString,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,4 @@ def __init__(
self.velocity: Optional[float] = v

def __str__(self):
attrs = {}
return f"{self.event_type}: pixels={self.pixels}, min_scroll_extent={self.min_scroll_extent}, max_scroll_extent={self.max_scroll_extent}, viewport_dimension={self.viewport_dimension}, scroll_delta={self.scroll_delta}, direction={self.direction}, overscroll={self.overscroll}, velocity={self.velocity}"
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import time
from typing import Any, List, Optional, Set, Union

from flet_core.buttons import ButtonStyle
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-core/src/flet_core/semantics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Optional

from flet_core.control import Control, OptionalNumber
from flet_core.control import Control
from flet_core.ref import Ref


Expand Down
1 change: 0 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/tabs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, Dict, List, Optional, Union

from flet_core.border import BorderSide
from flet_core.border_radius import BorderRadius
from flet_core.constrained_control import ConstrainedControl
from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
Expand Down
6 changes: 4 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from flet_core.border import BorderSide
from flet_core.border_radius import BorderRadius
from flet_core.text_style import TextStyle
from flet_core.types import MaterialState, PaddingValue, ThemeMode
from flet_core.types import MaterialState, PaddingValue
from flet_core.utils import DeprecatedEnumMeta

try:
from typing import Literal
Expand All @@ -18,12 +19,13 @@
]


class ThemeVisualDensity(Enum):
class ThemeVisualDensity(Enum, metaclass=DeprecatedEnumMeta):
NONE = None
STANDARD = "standard"
COMPACT = "compact"
COMFORTABLE = "comfortable"
ADAPTIVEPLATFORMDENSITY = "adaptivePlatformDensity"
ADAPTIVE_PLATFORM_DENSITY = "adaptivePlatformDensity"


PageTransitionString = Literal["fadeUpwards", "openUpwards", "zoom", "cupertino"]
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-core/src/flet_core/time_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def value(self) -> Optional[time]:

@value.setter
def value(self, value: Optional[Union[time, str]]):
if isinstance(value, (time)):
if isinstance(value, time):
value = value.strftime("%H:%M")
self._set_attr("value", value)

Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-core/src/flet_core/tooltip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Union
from typing import Any, Optional

from flet_core.border import Border
from flet_core.control import Control, OptionalNumber
Expand Down
16 changes: 15 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import string
import sys
import unicodedata
from enum import EnumMeta
from warnings import warn


def random_string(length):
return "".join(random.choice(string.ascii_letters) for i in range(length))
return "".join(random.choice(string.ascii_letters) for _ in range(length))


def is_asyncio():
Expand Down Expand Up @@ -159,3 +161,15 @@ def with_degrees(self, value):
radians = math.radians(value)
magnitude = abs(self)
return type(self).polar(radians, magnitude)


class DeprecatedEnumMeta(EnumMeta):

ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
def __getattribute__(self, item):
if item == 'ADAPTIVEPLATFORMDENSITY':
warn(
'ADAPTIVEPLATFORMDENSITY is deprecated, use ADAPTIVE_PLATFORM_DENSITY instead.',
DeprecationWarning,
stacklevel=2
)
return EnumMeta.__getattribute__(self, item)
8 changes: 1 addition & 7 deletions sdk/python/packages/flet-core/src/flet_core/webview.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
from enum import Enum
from typing import Any, List, Optional, Union
from typing import Any, Optional, Union

from flet_core.constrained_control import ConstrainedControl
from flet_core.control import OptionalNumber
from flet_core.ref import Ref
from flet_core.text_span import TextSpan
from flet_core.types import (
AnimationValue,
FontWeight,
FontWeightString,
OffsetValue,
ResponsiveNumber,
RotateValue,
ScaleValue,
TextAlign,
TextAlignString,
)

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from datetime import datetime, timedelta
from typing import Any, Dict, List, Optional

from fastapi import WebSocket

import flet_fastapi
from fastapi import WebSocket, WebSocketDisconnect
from flet_core.event import Event
from flet_core.local_connection import LocalConnection
from flet_core.page import Page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
from typing import Any, Callable, Coroutine, Dict, List, Optional, Sequence, Type, Union

import fastapi
import flet_fastapi
from fastapi.applications import AppType
from fastapi.datastructures import Default
from fastapi.params import Depends
from fastapi.utils import generate_unique_id
from starlette.middleware import Middleware
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
from starlette.routing import BaseRoute
from starlette.types import Lifespan

import flet_fastapi


class FastAPI(fastapi.FastAPI):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import HTTPException, Request
from fastapi.responses import HTMLResponse, RedirectResponse

from flet_fastapi.flet_app_manager import app_manager
from flet_fastapi.oauth_state import OAuthState


class FletOAuth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from pathlib import Path
from typing import Optional, Tuple

import flet_fastapi
from fastapi.staticfiles import StaticFiles
from starlette.types import Receive, Scope, Send

import flet_fastapi
from flet_core.types import WebRenderer
from flet_fastapi.flet_app_manager import app_manager
from flet_fastapi.once import Once
Expand All @@ -15,7 +17,6 @@
patch_index_html,
patch_manifest_json,
)
from starlette.types import Receive, Scope, Send

logger = logging.getLogger(flet_fastapi.__name__)

Expand Down Expand Up @@ -82,7 +83,7 @@ def lookup_path(self, path: str) -> Tuple[str, Optional[os.stat_result]]:
if stat_result is None:
return super().lookup_path(self.index)

return (full_path, stat_result)
return full_path, stat_result

async def __config(self, root_path: str):
if self.__proxy_path:
Expand Down
9 changes: 1 addition & 8 deletions sdk/python/packages/flet-runtime/src/flet_runtime/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
import flet_runtime
from flet_core.event import Event
from flet_core.page import Page
from flet_core.types import (
FLET_APP,
FLET_APP_HIDDEN,
FLET_APP_WEB,
WEB_BROWSER,
AppView,
WebRenderer,
)
from flet_core.types import AppView, WebRenderer
from flet_core.utils import is_coroutine, random_string
from flet_runtime.async_local_socket_connection import AsyncLocalSocketConnection
from flet_runtime.sync_local_socket_connection import SyncLocalSocketConnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from typing import List, Optional, Tuple

import httpx
from oauthlib.oauth2 import WebApplicationClient
from oauthlib.oauth2.rfc6749.tokens import OAuth2Token

from flet.version import version
from flet_core.locks import AsyncNopeLock, NopeLock
from flet_core.utils import is_asyncio
from flet_runtime.auth.oauth_provider import OAuthProvider
from flet_runtime.auth.oauth_token import OAuthToken
from flet_runtime.auth.user import User
from oauthlib.oauth2 import WebApplicationClient
from oauthlib.oauth2.rfc6749.tokens import OAuth2Token


class Authorization:
Expand Down Expand Up @@ -77,7 +78,7 @@ def get_authorization_data(self) -> Tuple[str, str]:
scope=self.scope,
state=self.state,
)
return (authorization_url, self.state)
return authorization_url, self.state

def request_token(self, code: str):
req = self.__get_request_token_request(code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import hmac
import logging
import os
import sys
import urllib.parse
from datetime import datetime, timedelta
from typing import Optional
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-runtime/src/flet_runtime/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_local_ip():
s.connect(("8.8.8.8", 80))
local_ip = s.getsockname()[0]
return local_ip
except Exception as e:
except Exception:
hostname = socket.gethostname()
return socket.gethostbyname(hostname)

Expand Down
Loading