Skip to content

Commit

Permalink
Fix compatibility issue with python <3.11 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManiMozaffar authored Dec 3, 2023
1 parent 2ef00f7 commit 2579b18
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions python/demo/forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations as _annotations

import enum
from collections import defaultdict
from datetime import date
from enum import StrEnum
from typing import Annotated, Literal, TypeAlias

from fastapi import APIRouter, Request, UploadFile
Expand Down Expand Up @@ -123,7 +123,7 @@ async def login_form_post(form: Annotated[LoginForm, fastui_form(LoginForm)]) ->
return FormResponse(event=GoToEvent(url='/'))


class ToolEnum(StrEnum):
class ToolEnum(str, enum.Enum):
hammer = 'hammer'
screwdriver = 'screwdriver'
saw = 'saw'
Expand Down
5 changes: 3 additions & 2 deletions python/fastui/components/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

import annotated_types
import pydantic
import typing_extensions

from .. import class_name as _class_name
from .. import events

__all__ = 'DisplayMode', 'DisplayLookup', 'Display', 'Details'


class DisplayMode(enum.StrEnum):
class DisplayMode(str, enum.Enum):
"""
How to a value.
"""
Expand Down Expand Up @@ -64,7 +65,7 @@ class Details(pydantic.BaseModel, typing.Generic[DataModel], extra='forbid'):
type: typing.Literal['Details'] = 'Details'

@pydantic.model_validator(mode='after')
def fill_fields(self) -> typing.Self:
def fill_fields(self) -> typing_extensions.Self:
if self.fields is None:
self.fields = [
DisplayLookup(field=name, title=field.title) for name, field in self.data.model_fields.items()
Expand Down
9 changes: 5 additions & 4 deletions python/fastui/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import json
import re
import typing
from typing import Iterable, Literal, Required, TypeAlias, TypedDict, TypeGuard, cast
from typing import Iterable, Literal, TypeAlias, TypedDict, TypeGuard, cast

from pydantic import BaseModel
from typing_extensions import Required

from .components.forms import (
FormField,
Expand All @@ -31,9 +32,9 @@ def model_json_schema_to_fields(model: type[BaseModel]) -> list[FormField]:
return list(json_schema_obj_to_fields(schema, [], [], defs))


JsonSchemaInput: TypeAlias = (
'JsonSchemaString | JsonSchemaStringEnum | JsonSchemaFile | JsonSchemaInt | JsonSchemaNumber'
)
JsonSchemaInput: (
TypeAlias
) = 'JsonSchemaString | JsonSchemaStringEnum | JsonSchemaFile | JsonSchemaInt | JsonSchemaNumber'
JsonSchemaField: TypeAlias = 'JsonSchemaInput | JsonSchemaBool'
JsonSchemaConcrete: TypeAlias = 'JsonSchemaField | JsonSchemaArray | JsonSchemaObject'
JsonSchemaAny: TypeAlias = 'JsonSchemaConcrete | JsonSchemaAnyOf | JsonSchemaAllOf | JsonSchemaRef'
Expand Down

2 comments on commit 2579b18

@anorprogrammer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has this been updated on pypi?

@samuelcolvin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you can see that on pypi.

Please sign in to comment.