mirror of
https://github.com/nonebot/nonebot2.git
synced 2026-01-10 22:02:22 +00:00
🐛 Fix: log level 配置项无法使用 int 类型配置 (#3732)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
SIMPLE=simple
|
||||
int_str=123
|
||||
COMPLEX='
|
||||
[1, 2, 3]
|
||||
'
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Optional, Union
|
||||
from pydantic import BaseModel, Field
|
||||
import pytest
|
||||
|
||||
from nonebot.compat import PYDANTIC_V2
|
||||
from nonebot.compat import PYDANTIC_V2, LegacyUnionField
|
||||
from nonebot.config import DOTENV_TYPE, BaseSettings, SettingsConfig, SettingsError
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ class Example(BaseSettings):
|
||||
env_nested_delimiter = "__"
|
||||
|
||||
simple: str = ""
|
||||
int_str: Union[int, str] = LegacyUnionField(default="")
|
||||
complex: list[int] = Field(default=[1])
|
||||
complex_none: Optional[list[int]] = None
|
||||
complex_union: Union[int, list[int]] = 1
|
||||
@@ -62,6 +63,8 @@ def test_config_with_env():
|
||||
config = Example(_env_file=(".env", ".env.example"))
|
||||
assert config.simple == "simple"
|
||||
|
||||
assert config.int_str == 123
|
||||
|
||||
assert config.complex == [1, 2, 3]
|
||||
|
||||
assert config.complex_none is None
|
||||
|
||||
3
tests/uv.lock
generated
Normal file
3
tests/uv.lock
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
version = 1
|
||||
revision = 3
|
||||
requires-python = ">=3.12"
|
||||
Reference in New Issue
Block a user