Skip to content

Commit

Permalink
Merge pull request Tishka17#345 from Vladyslav49/develop
Browse files Browse the repository at this point in the history
add pathlib.Path support for path in media
  • Loading branch information
Tishka17 authored Dec 26, 2023
2 parents e71f047 + 0b31cba commit f381e4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/aiogram_dialog/api/entities/media.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from typing import Optional
from pathlib import Path
from typing import Optional, Union

from aiogram.types import ContentType

Expand All @@ -22,7 +23,7 @@ def __init__(
self,
type: ContentType,
url: Optional[str] = None,
path: Optional[str] = None,
path: Union[str, Path, None] = None,
file_id: Optional[MediaId] = None,
use_pipe: bool = False,
**kwargs,
Expand Down
7 changes: 5 additions & 2 deletions src/aiogram_dialog/widgets/media/static.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import Optional, Union

from aiogram.types import ContentType
Expand All @@ -13,7 +14,7 @@ class StaticMedia(Media):
def __init__(
self,
*,
path: Union[Text, str, None] = None,
path: Union[Text, str, Path, None] = None,
url: Union[Text, str, None] = None,
type: ContentType = ContentType.PHOTO,
use_pipe: bool = False,
Expand All @@ -24,7 +25,9 @@ def __init__(
if not (url or path):
raise ValueError("Neither url nor path are provided")
self.type = type
if isinstance(path, str):
if isinstance(path, Path):
path = Const(str(path))
elif isinstance(path, str):
path = Const(path)
self.path = path
if isinstance(url, str):
Expand Down

0 comments on commit f381e4a

Please sign in to comment.