mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
#1370 added possibility to check X | None on Python >= 3.10
This commit is contained in:
parent
e17e3bc71c
commit
ce4e1a706d
2 changed files with 19 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import types
|
||||
import typing
|
||||
from decimal import Decimal
|
||||
from enum import Enum
|
||||
|
|
@ -29,6 +31,11 @@ T = TypeVar("T", bound="CallbackData")
|
|||
MAX_CALLBACK_LENGTH: int = 64
|
||||
|
||||
|
||||
_UNION_TYPES = {typing.Union}
|
||||
if sys.version_info >= (3, 10): # pragma: no cover
|
||||
_UNION_TYPES.add(types.UnionType)
|
||||
|
||||
|
||||
class CallbackDataException(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -195,6 +202,6 @@ def _check_field_is_nullable(field: FieldInfo) -> bool:
|
|||
if not field.is_required():
|
||||
return True
|
||||
|
||||
return typing.get_origin(field.annotation) is typing.Union and type(None) in typing.get_args(
|
||||
return typing.get_origin(field.annotation) in _UNION_TYPES and type(None) in typing.get_args(
|
||||
field.annotation
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue