mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-17 23:53:58 +02:00
Make proper use of function overloading
In preparation of the RUFF lint, I rewrote the function to use typing.overload. This is the proper way to accept either two arguments or one argument
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import re
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import overload
|
||||
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -192,11 +193,35 @@ class MovieService:
|
||||
result.append(movie_file)
|
||||
return result
|
||||
|
||||
@overload
|
||||
def check_if_movie_exists(
|
||||
self, *, external_id: int, metadata_provider: str
|
||||
) -> bool:
|
||||
"""
|
||||
Check if a movie exists in the database.
|
||||
|
||||
:param external_id: The external ID of the movie.
|
||||
:param metadata_provider: The metadata provider.
|
||||
:return: True if the movie exists, False otherwise.
|
||||
"""
|
||||
...
|
||||
|
||||
@overload
|
||||
def check_if_movie_exists(self, *, movie_id: MovieId) -> bool:
|
||||
"""
|
||||
Check if a movie exists in the database.
|
||||
|
||||
:param movie_id: The ID of the movie.
|
||||
:return: True if the movie exists, False otherwise.
|
||||
"""
|
||||
...
|
||||
|
||||
def check_if_movie_exists(
|
||||
self,
|
||||
external_id: int = None,
|
||||
metadata_provider: str = None,
|
||||
movie_id: MovieId = None,
|
||||
*,
|
||||
external_id=None,
|
||||
metadata_provider=None,
|
||||
movie_id=None,
|
||||
) -> bool:
|
||||
"""
|
||||
Check if a movie exists in the database.
|
||||
@@ -207,7 +232,7 @@ class MovieService:
|
||||
:return: True if the movie exists, False otherwise.
|
||||
:raises ValueError: If neither external ID and metadata provider nor movie ID are provided.
|
||||
"""
|
||||
if external_id and metadata_provider:
|
||||
if not (external_id is None or metadata_provider is None):
|
||||
try:
|
||||
self.movie_repository.get_movie_by_external_id(
|
||||
external_id=external_id, metadata_provider=metadata_provider
|
||||
@@ -215,17 +240,14 @@ class MovieService:
|
||||
return True
|
||||
except NotFoundError:
|
||||
return False
|
||||
elif movie_id:
|
||||
elif movie_id is not None:
|
||||
try:
|
||||
self.movie_repository.get_movie_by_id(movie_id=movie_id)
|
||||
return True
|
||||
except NotFoundError:
|
||||
return False
|
||||
|
||||
else:
|
||||
msg = (
|
||||
"Either external_id and metadata_provider or movie_id must be provided"
|
||||
)
|
||||
msg = "Use one of the provided overloads for this function!"
|
||||
raise ValueError(msg)
|
||||
|
||||
def get_all_available_torrents_for_movie(
|
||||
|
||||
@@ -2,6 +2,7 @@ import pprint
|
||||
import re
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import overload
|
||||
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
@@ -197,22 +198,31 @@ class TvService:
|
||||
result.append(season_file)
|
||||
return result
|
||||
|
||||
def check_if_show_exists(
|
||||
self,
|
||||
external_id: int = None,
|
||||
metadata_provider: str = None,
|
||||
show_id: ShowId = None,
|
||||
) -> bool:
|
||||
@overload
|
||||
def check_if_show_exists(self, *, external_id: int, metadata_provider: str) -> bool:
|
||||
"""
|
||||
Check if a show exists in the database.
|
||||
|
||||
:param external_id: The external ID of the show.
|
||||
:param metadata_provider: The metadata provider.
|
||||
:return: True if the show exists, False otherwise.
|
||||
"""
|
||||
...
|
||||
|
||||
@overload
|
||||
def check_if_show_exists(self, *, show_id: ShowId) -> bool:
|
||||
"""
|
||||
Check if a show exists in the database.
|
||||
|
||||
:param show_id: The ID of the show.
|
||||
:return: True if the show exists, False otherwise.
|
||||
:raises ValueError: If neither external ID and metadata provider nor show ID are provided.
|
||||
"""
|
||||
if external_id and metadata_provider:
|
||||
...
|
||||
|
||||
def check_if_show_exists(
|
||||
self, *, external_id=None, metadata_provider=None, show_id=None
|
||||
) -> bool:
|
||||
if not (external_id is None or metadata_provider is None):
|
||||
try:
|
||||
self.tv_repository.get_show_by_external_id(
|
||||
external_id=external_id, metadata_provider=metadata_provider
|
||||
|
||||
Reference in New Issue
Block a user