Skip to content

Commit

Permalink
💥 Remove: 移除 Python 3.8 支持 (#2641)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Apr 15, 2024
1 parent e93ee1f commit 4a02dde
Show file tree
Hide file tree
Showing 69 changed files with 1,811 additions and 1,848 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
cancel-in-progress: true
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
env: [pydantic-v1, pydantic-v2]
fail-fast: false
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
rev: v0.3.7
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -20,7 +20,7 @@ repos:
stages: [commit]

- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.4.0
hooks:
- id: black
stages: [commit]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _✨ 跨平台 Python 异步机器人框架 ✨_
<a href="https://pypi.python.org/pypi/nonebot2">
<img src="https://img.shields.io/pypi/v/nonebot2?logo=python&logoColor=edb641" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.8+-blue?logo=python&logoColor=edb641" alt="python">
<img src="https://img.shields.io/badge/python-3.9+-blue?logo=python&logoColor=edb641" alt="python">
<a href="https://github.com/psf/black">
<img src="https://img.shields.io/badge/code%20style-black-000000.svg?logo=python&logoColor=edb641" alt="black">
</a>
Expand Down
510 changes: 255 additions & 255 deletions envs/pydantic-v1/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion envs/pydantic-v1/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["yanyongyu <yyy@nonebot.dev>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.9"

[tool.poetry.group.dev.dependencies]
pydantic = "^1.0.0"
Expand Down
609 changes: 303 additions & 306 deletions envs/pydantic-v2/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion envs/pydantic-v2/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["yanyongyu <yyy@nonebot.dev>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.9"

[tool.poetry.group.dev.dependencies]
pydantic = "^2.0.0"
Expand Down
393 changes: 195 additions & 198 deletions envs/test/poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions envs/test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ license = "MIT"
packages = [{ include = "nonebot-test.py" }]

[tool.poetry.dependencies]
python = "^3.8"
nonebug = "^0.3.0"
python = "^3.9"
nonebug = "^0.3.7"
wsproto = "^1.2.0"
pytest-cov = "^4.0.0"
pytest-cov = "^5.0.0"
pytest-xdist = "^3.0.2"
pytest-asyncio = "^0.23.2"
werkzeug = ">=2.3.6,<4.0.0"
Expand Down
12 changes: 6 additions & 6 deletions nonebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

import os
from importlib.metadata import version
from typing import Any, Dict, Type, Union, TypeVar, Optional, overload
from typing import Any, Union, TypeVar, Optional, overload

import loguru

Expand Down Expand Up @@ -100,7 +100,7 @@ def get_adapter(name: str) -> Adapter:


@overload
def get_adapter(name: Type[A]) -> A:
def get_adapter(name: type[A]) -> A:
"""
参数:
name: 适配器类型
Expand All @@ -110,7 +110,7 @@ def get_adapter(name: Type[A]) -> A:
"""


def get_adapter(name: Union[str, Type[Adapter]]) -> Adapter:
def get_adapter(name: Union[str, type[Adapter]]) -> Adapter:
"""获取已注册的 {ref}`nonebot.adapters.Adapter` 实例。
异常:
Expand All @@ -131,7 +131,7 @@ def get_adapter(name: Union[str, Type[Adapter]]) -> Adapter:
return adapters[target]


def get_adapters() -> Dict[str, Adapter]:
def get_adapters() -> dict[str, Adapter]:
"""获取所有已注册的 {ref}`nonebot.adapters.Adapter` 实例。
返回:
Expand Down Expand Up @@ -230,7 +230,7 @@ def get_bot(self_id: Optional[str] = None) -> Bot:
raise ValueError("There are no bots to get.")


def get_bots() -> Dict[str, Bot]:
def get_bots() -> dict[str, Bot]:
"""获取所有连接到 NoneBot 的 {ref}`nonebot.adapters.Bot` 对象。
返回:
Expand All @@ -249,7 +249,7 @@ def get_bots() -> Dict[str, Bot]:
return get_driver().bots


def _resolve_combine_expr(obj_str: str) -> Type[Driver]:
def _resolve_combine_expr(obj_str: str) -> type[Driver]:
drivers = obj_str.split("+")
DriverClass = resolve_dot_notation(
drivers[0], "Driver", default_prefix="nonebot.drivers."
Expand Down
51 changes: 24 additions & 27 deletions nonebot/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@
description: nonebot.compat 模块
"""

from collections.abc import Generator
from dataclasses import dataclass, is_dataclass
from typing_extensions import Self, Annotated, get_args, get_origin, is_typeddict
from typing_extensions import Self, get_args, get_origin, is_typeddict
from typing import (
TYPE_CHECKING,
Any,
Set,
Dict,
List,
Type,
Union,
TypeVar,
Callable,
Optional,
Protocol,
Generator,
Annotated,
)

from pydantic import VERSION, BaseModel
Expand Down Expand Up @@ -94,7 +91,7 @@ def __init__(self, default: Any = PydanticUndefined, **kwargs: Any) -> None:
super().__init__(default=default, **kwargs)

@property
def extra(self) -> Dict[str, Any]:
def extra(self) -> dict[str, Any]:
"""Extra data that is not part of the standard pydantic fields.
For compatibility with pydantic v1.
Expand Down Expand Up @@ -160,7 +157,7 @@ def __hash__(self) -> int:
# to allow store them in a set.
return id(self)

def extract_field_info(field_info: BaseFieldInfo) -> Dict[str, Any]:
def extract_field_info(field_info: BaseFieldInfo) -> dict[str, Any]:
"""Get FieldInfo init kwargs from a FieldInfo instance."""

kwargs = field_info._attributes_set.copy()
Expand All @@ -176,7 +173,7 @@ def model_field_validate(
type, config=None if model_field._annotation_has_config() else config
).validate_python(value)

def model_fields(model: Type[BaseModel]) -> List[ModelField]:
def model_fields(model: type[BaseModel]) -> list[ModelField]:
"""Get field list of a model."""

return [
Expand All @@ -188,19 +185,19 @@ def model_fields(model: Type[BaseModel]) -> List[ModelField]:
for name, field_info in model.model_fields.items()
]

def model_config(model: Type[BaseModel]) -> Any:
def model_config(model: type[BaseModel]) -> Any:
"""Get config of a model."""
return model.model_config

def model_dump(
model: BaseModel,
include: Optional[Set[str]] = None,
exclude: Optional[Set[str]] = None,
include: Optional[set[str]] = None,
exclude: Optional[set[str]] = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
) -> Dict[str, Any]:
) -> dict[str, Any]:
return model.model_dump(
include=include,
exclude=exclude,
Expand All @@ -210,16 +207,16 @@ def model_dump(
exclude_none=exclude_none,
)

def type_validate_python(type_: Type[T], data: Any) -> T:
def type_validate_python(type_: type[T], data: Any) -> T:
"""Validate data with given type."""
return TypeAdapter(type_).validate_python(data)

def type_validate_json(type_: Type[T], data: Union[str, bytes]) -> T:
def type_validate_json(type_: type[T], data: Union[str, bytes]) -> T:
"""Validate JSON with given type."""
return TypeAdapter(type_).validate_json(data)

def __get_pydantic_core_schema__(
cls: Type["_CustomValidationClass"],
cls: type["_CustomValidationClass"],
source_type: Any,
handler: GetCoreSchemaHandler,
) -> CoreSchema:
Expand All @@ -230,7 +227,7 @@ def __get_pydantic_core_schema__(
[core_schema.no_info_plain_validator_function(func) for func in validators]
)

def custom_validation(class_: Type["CVC"]) -> Type["CVC"]:
def custom_validation(class_: type["CVC"]) -> type["CVC"]:
"""Use pydantic v1 like validator generator in pydantic v2"""

setattr(
Expand Down Expand Up @@ -308,7 +305,7 @@ def construct(
)
return cls._construct(name, annotation, field_info or FieldInfo())

def extract_field_info(field_info: BaseFieldInfo) -> Dict[str, Any]:
def extract_field_info(field_info: BaseFieldInfo) -> dict[str, Any]:
"""Get FieldInfo init kwargs from a FieldInfo instance."""

kwargs = {
Expand All @@ -318,7 +315,7 @@ def extract_field_info(field_info: BaseFieldInfo) -> Dict[str, Any]:
return kwargs

def model_field_validate(
model_field: ModelField, value: Any, config: Optional[Type[ConfigDict]] = None
model_field: ModelField, value: Any, config: Optional[type[ConfigDict]] = None
) -> Any:
"""Validate the value pass to the field.
Expand All @@ -333,7 +330,7 @@ def model_field_validate(
raise ValueError(value, model_field)
return v

def model_fields(model: Type[BaseModel]) -> List[ModelField]:
def model_fields(model: type[BaseModel]) -> list[ModelField]:
"""Get field list of a model."""

# construct the model field without preprocess to avoid error
Expand All @@ -348,19 +345,19 @@ def model_fields(model: Type[BaseModel]) -> List[ModelField]:
for model_field in model.__fields__.values()
]

def model_config(model: Type[BaseModel]) -> Any:
def model_config(model: type[BaseModel]) -> Any:
"""Get config of a model."""
return model.__config__

def model_dump(
model: BaseModel,
include: Optional[Set[str]] = None,
exclude: Optional[Set[str]] = None,
include: Optional[set[str]] = None,
exclude: Optional[set[str]] = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
) -> Dict[str, Any]:
) -> dict[str, Any]:
return model.dict(
include=include,
exclude=exclude,
Expand All @@ -370,14 +367,14 @@ def model_dump(
exclude_none=exclude_none,
)

def type_validate_python(type_: Type[T], data: Any) -> T:
def type_validate_python(type_: type[T], data: Any) -> T:
"""Validate data with given type."""
return parse_obj_as(type_, data)

def type_validate_json(type_: Type[T], data: Union[str, bytes]) -> T:
def type_validate_json(type_: type[T], data: Union[str, bytes]) -> T:
"""Validate JSON with given type."""
return parse_raw_as(type_, data)

def custom_validation(class_: Type["CVC"]) -> Type["CVC"]:
def custom_validation(class_: type["CVC"]) -> type["CVC"]:
"""Do nothing in pydantic v1"""
return class_
Loading

0 comments on commit 4a02dde

Please sign in to comment.