Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down
3 changes: 1 addition & 2 deletions ruoyi-fastapi-backend/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
from collections.abc import Iterable
from logging.config import fileConfig
from typing import Optional, Union

from alembic import context
from alembic.migration import MigrationContext
Expand Down Expand Up @@ -67,7 +66,7 @@ def run_migrations_offline() -> None:
def do_run_migrations(connection: Connection) -> None:
def process_revision_directives(
context: MigrationContext,
revision: Union[str, Iterable[Optional[str]], Iterable[str]],
revision: str | Iterable[str | None] | Iterable[str],
directives: list[MigrationScript],
) -> None:
script = directives[0]
Expand Down
6 changes: 3 additions & 3 deletions ruoyi-fastapi-backend/common/annotation/log_annotation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import inspect
import json
import time
from collections.abc import Awaitable
from collections.abc import Awaitable, Callable
from datetime import datetime
from functools import wraps
from typing import Any, Callable, Literal, Optional, TypeVar
from typing import Any, Literal, TypeVar

import httpx
from async_lru import alru_cache
Expand Down Expand Up @@ -38,7 +38,7 @@ def __init__(
self,
title: str,
business_type: BusinessType,
log_type: Optional[Literal['login', 'operation']] = 'operation',
log_type: Literal['login', 'operation'] | None = 'operation',
) -> None:
"""
日志装饰器
Expand Down
10 changes: 4 additions & 6 deletions ruoyi-fastapi-backend/common/aspect/data_scope.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from fastapi import Depends, Request, params
from sqlalchemy import ColumnElement, func, or_, select

Expand All @@ -24,8 +22,8 @@ class GetDataScope:
def __init__(
self,
query_alias: Base,
user_alias: Optional[str] = 'user_id',
dept_alias: Optional[str] = 'dept_id',
user_alias: str | None = 'user_id',
dept_alias: str | None = 'dept_id',
) -> None:
"""
获取当前用户数据权限对应的查询sql语句
Expand Down Expand Up @@ -100,8 +98,8 @@ def __call__(self, request: Request) -> ColumnElement:

def DataScopeDependency( # noqa: N802
query_alias: Base,
user_alias: Optional[str] = 'user_id',
dept_alias: Optional[str] = 'dept_id',
user_alias: str | None = 'user_id',
dept_alias: str | None = 'dept_id',
) -> params.Depends:
"""
当前用户数据权限依赖
Expand Down
10 changes: 4 additions & 6 deletions ruoyi-fastapi-backend/common/aspect/interface_auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Union

from fastapi import Depends, Request, params

from common.context import RequestContext
Expand All @@ -12,7 +10,7 @@ class CheckUserInterfaceAuth:
校验当前用户是否具有相应的接口权限
"""

def __init__(self, perm: Union[str, list], is_strict: bool = False) -> None:
def __init__(self, perm: str | list, is_strict: bool = False) -> None:
"""
校验当前用户是否具有相应的接口权限

Expand Down Expand Up @@ -46,7 +44,7 @@ class CheckRoleInterfaceAuth:
根据角色校验当前用户是否具有相应的接口权限
"""

def __init__(self, role_key: Union[str, list], is_strict: bool = False) -> None:
def __init__(self, role_key: str | list, is_strict: bool = False) -> None:
"""
根据角色校验当前用户是否具有相应的接口权限

Expand Down Expand Up @@ -74,7 +72,7 @@ def __call__(self, request: Request) -> bool:
raise PermissionException(data='', message='该用户无此接口权限')


def UserInterfaceAuthDependency(perm: Union[str, list], is_strict: bool = False) -> params.Depends: # noqa: N802
def UserInterfaceAuthDependency(perm: str | list, is_strict: bool = False) -> params.Depends: # noqa: N802
"""
根据权限标识校验当前用户接口权限依赖

Expand All @@ -85,7 +83,7 @@ def UserInterfaceAuthDependency(perm: Union[str, list], is_strict: bool = False)
return Depends(CheckUserInterfaceAuth(perm, is_strict))


def RoleInterfaceAuthDependency(role_key: Union[str, list], is_strict: bool = False) -> params.Depends: # noqa: N802
def RoleInterfaceAuthDependency(role_key: str | list, is_strict: bool = False) -> params.Depends: # noqa: N802
"""
根据角色校验当前用户接口权限依赖

Expand Down
8 changes: 4 additions & 4 deletions ruoyi-fastapi-backend/common/aspect/pre_auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Literal, Optional, TypedDict, Union
from typing import Literal, TypedDict

from fastapi import Depends, Request, params
from fastapi.security import OAuth2PasswordBearer
Expand Down Expand Up @@ -37,7 +37,7 @@ class PreAuth:
登录认证前置校验依赖类
"""

def __init__(self, exclude_routes: Optional[list[ExcludeRoute]] = None) -> None:
def __init__(self, exclude_routes: list[ExcludeRoute] | None = None) -> None:
"""
初始化登录认证前置校验依赖

Expand Down Expand Up @@ -80,7 +80,7 @@ def _compile_path_pattern(self, path: str) -> re.Pattern:
# 添加开始和结束锚点,确保精确匹配
return re.compile(f'^{pattern_str}$')

async def __call__(self, request: Request, db: AsyncSession = Depends(get_db)) -> Union[CurrentUserModel, None]:
async def __call__(self, request: Request, db: AsyncSession = Depends(get_db)) -> CurrentUserModel | None:
"""
执行登录认证校验

Expand Down Expand Up @@ -125,7 +125,7 @@ async def __call__(self, request: Request, db: AsyncSession = Depends(get_db)) -
return current_user


def PreAuthDependency(exclude_routes: Optional[list[ExcludeRoute]] = None) -> params.Depends: # noqa: N802
def PreAuthDependency(exclude_routes: list[ExcludeRoute] | None = None) -> params.Depends: # noqa: N802
"""
登录认证前置校验依赖

Expand Down
14 changes: 5 additions & 9 deletions ruoyi-fastapi-backend/common/context.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import re
from contextvars import ContextVar, Token
from typing import Literal, Optional, Union
from typing import Literal

from exceptions.exception import LoginException
from module_admin.entity.vo.user_vo import CurrentUserModel

# 定义上下文变量
# 存储当前请求的编译后的排除路由模式列表
current_exclude_patterns: ContextVar[
Optional[
list[
dict[str, Union[str, list[Literal['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']], re.Pattern]]
]
]
list[dict[str, str | list[Literal['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']] | re.Pattern]] | None
] = ContextVar('current_exclude_patterns', default=None)
# 存储当前用户信息
current_user: ContextVar[Optional[CurrentUserModel]] = ContextVar('current_user', default=None)
current_user: ContextVar[CurrentUserModel | None] = ContextVar('current_user', default=None)


class RequestContext:
Expand All @@ -26,7 +22,7 @@ class RequestContext:
@staticmethod
def set_current_exclude_patterns(
exclude_patterns: list[
dict[str, Union[str, list[Literal['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']], re.Pattern]]
dict[str, str | list[Literal['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']] | re.Pattern]
],
) -> Token:
"""
Expand All @@ -39,7 +35,7 @@ def set_current_exclude_patterns(

@staticmethod
def get_current_exclude_patterns() -> list[
dict[str, Union[str, list[Literal['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']], re.Pattern]]
dict[str, str | list[Literal['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']] | re.Pattern]
]:
"""
获取当前请求的编译后的排除路由模式列表
Expand Down
5 changes: 2 additions & 3 deletions ruoyi-fastapi-backend/common/enums.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from enum import Enum
from typing import Union


class BusinessType(Enum):
Expand Down Expand Up @@ -36,11 +35,11 @@ class RedisInitKeyConfig(Enum):
"""

@property
def key(self) -> Union[str, None]:
def key(self) -> str | None:
return self.value.get('key')

@property
def remark(self) -> Union[str, None]:
def remark(self) -> str | None:
return self.value.get('remark')

ACCESS_TOKEN = {'key': 'access_token', 'remark': '登录令牌信息'}
Expand Down
28 changes: 14 additions & 14 deletions ruoyi-fastapi-backend/common/router.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import importlib
import os
import sys
from collections.abc import Sequence
from collections.abc import Callable, Sequence
from enum import Enum
from typing import Annotated, Any, Callable, Literal, Optional, Union
from typing import Annotated, Any, Literal

from annotated_doc import Doc
from fastapi import FastAPI, params
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__( # noqa: PLR0913
order_num: Annotated[int, Doc('An optional order number for the router.')] = 100,
auto_register: Annotated[bool, Doc('An optional auto register flag for the router.')] = True,
tags: Annotated[
Optional[list[Union[str, Enum]]],
list[str | Enum] | None,
Doc(
"""
A list of tags to be applied to all the *path operations* in this
Expand All @@ -65,7 +65,7 @@ def __init__( # noqa: PLR0913
),
] = None,
dependencies: Annotated[
Optional[Sequence[params.Depends]],
Sequence[params.Depends] | None,
Doc(
"""
A list of dependencies (using `Depends()`) to be applied to all the
Expand All @@ -88,7 +88,7 @@ def __init__( # noqa: PLR0913
),
] = Default(JSONResponse),
responses: Annotated[
Optional[dict[Union[int, str], dict[str, Any]]],
dict[int | str, dict[str, Any]] | None,
Doc(
"""
Additional responses to be shown in OpenAPI.
Expand All @@ -104,7 +104,7 @@ def __init__( # noqa: PLR0913
),
] = None,
callbacks: Annotated[
Optional[list[BaseRoute]],
list[BaseRoute] | None,
Doc(
"""
OpenAPI callbacks that should apply to all *path operations* in this
Expand All @@ -118,7 +118,7 @@ def __init__( # noqa: PLR0913
),
] = None,
routes: Annotated[
Optional[list[BaseRoute]],
list[BaseRoute] | None,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited
Expand Down Expand Up @@ -149,7 +149,7 @@ def __init__( # noqa: PLR0913
),
] = True,
default: Annotated[
Optional[ASGIApp],
ASGIApp | None,
Doc(
"""
Default function handler for this router. Used to handle
Expand All @@ -158,7 +158,7 @@ def __init__( # noqa: PLR0913
),
] = None,
dependency_overrides_provider: Annotated[
Optional[Any],
Any | None,
Doc(
"""
Only used internally by FastAPI to handle dependency overrides.
Expand All @@ -180,7 +180,7 @@ def __init__( # noqa: PLR0913
),
] = APIRoute,
on_startup: Annotated[
Optional[Sequence[Callable[[], Any]]],
Sequence[Callable[[], Any]] | None,
Doc(
"""
A list of startup event handler functions.
Expand All @@ -192,7 +192,7 @@ def __init__( # noqa: PLR0913
),
] = None,
on_shutdown: Annotated[
Optional[Sequence[Callable[[], Any]]],
Sequence[Callable[[], Any]] | None,
Doc(
"""
A list of shutdown event handler functions.
Expand All @@ -207,7 +207,7 @@ def __init__( # noqa: PLR0913
# the generic to Lifespan[AppType] is the type of the top level application
# which the router cannot know statically, so we use typing.Any
lifespan: Annotated[
Optional[Lifespan[Any]],
Lifespan[Any] | None,
Doc(
"""
A `Lifespan` context manager handler. This replaces `startup` and
Expand All @@ -219,7 +219,7 @@ def __init__( # noqa: PLR0913
),
] = None,
deprecated: Annotated[
Optional[bool],
bool | None,
Doc(
"""
Mark all *path operations* in this router as deprecated.
Expand Down Expand Up @@ -357,7 +357,7 @@ def _sort_routers(self, routers: list[tuple[str, APIRouter]]) -> list[tuple[str,
"""

# 按规则排序路由
def sort_key(item: tuple[str, APIRouter]) -> Union[tuple[Literal[0], int, str], tuple[Literal[1], str]]:
def sort_key(item: tuple[str, APIRouter]) -> tuple[Literal[0], int, str] | tuple[Literal[1], str]:
attr_name, router = item
# APIRouterPro实例按order_num排序,序号越小越靠前
if isinstance(router, APIRouterPro):
Expand Down
6 changes: 3 additions & 3 deletions ruoyi-fastapi-backend/common/vo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Generic, Optional, TypeVar, Union
from typing import Any, Generic, TypeVar

from pydantic import BaseModel, ConfigDict, Field, create_model
from pydantic.alias_generators import to_camel
Expand All @@ -17,7 +17,7 @@ class CrudResponseModel(BaseModel):

is_success: bool = Field(description='操作是否成功')
message: str = Field(description='响应信息')
result: Optional[Any] = Field(default=None, description='响应结果')
result: Any | None = Field(default=None, description='响应结果')


class ResponseBaseModel(BaseModel):
Expand All @@ -38,7 +38,7 @@ class DynamicResponseModel(ResponseBaseModel, Generic[T]):

model_config = ConfigDict(alias_generator=to_camel)

def __class_getitem__(cls, item: Any) -> Union[Any, Self]:
def __class_getitem__(cls, item: Any) -> Any | Self:
"""
当使用 DynamicResponseModel[Item] 语法时,动态创建一个包含所有字段的新模型
"""
Expand Down
9 changes: 5 additions & 4 deletions ruoyi-fastapi-backend/config/get_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import importlib
import json
from asyncio import iscoroutinefunction
from collections.abc import Callable
from datetime import datetime, timedelta
from typing import Any, Callable, Optional, Union
from typing import Any

from apscheduler.events import EVENT_ALL, SchedulerEvent
from apscheduler.executors.asyncio import AsyncIOExecutor
Expand Down Expand Up @@ -34,7 +35,7 @@ class MyCronTrigger(CronTrigger):
WEEKDAY_COUNT = 5

@classmethod
def from_crontab(cls, expr: str, timezone: Optional[str] = None) -> 'MyCronTrigger':
def from_crontab(cls, expr: str, timezone: str | None = None) -> 'MyCronTrigger':
values = expr.split()
if len(values) != cls.CRON_EXPRESSION_LENGTH_MIN and len(values) != cls.CRON_EXPRESSION_LENGTH_MAX:
raise ValueError(f'Wrong number of fields; got {len(values)}, expected 6 or 7')
Expand Down Expand Up @@ -166,7 +167,7 @@ def _import_function(cls, func_path: str) -> Callable[..., Any]:
return getattr(module, func_name)

@classmethod
def get_scheduler_job(cls, job_id: Union[str, int]) -> Job:
def get_scheduler_job(cls, job_id: str | int) -> Job:
"""
根据任务id获取任务对象

Expand Down Expand Up @@ -233,7 +234,7 @@ def execute_scheduler_job_once(cls, job_info: JobModel) -> None:
)

@classmethod
def remove_scheduler_job(cls, job_id: Union[str, int]) -> None:
def remove_scheduler_job(cls, job_id: str | int) -> None:
"""
根据任务id移除任务

Expand Down
Loading