Pylance typing
Fix Pylance warnings for typing
This commit is contained in:
parent
b438f81a43
commit
69fa1f3f09
|
@ -7,7 +7,7 @@ from praw.models import Comment, Submission
|
||||||
|
|
||||||
|
|
||||||
class BaseArchiveEntry(ABC):
|
class BaseArchiveEntry(ABC):
|
||||||
def __init__(self, source: (Comment, Submission)):
|
def __init__(self, source: Comment | Submission):
|
||||||
self.source = source
|
self.source = source
|
||||||
self.post_details: dict = {}
|
self.post_details: dict = {}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Archiver(RedditConnector):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _pull_lever_entry_factory(praw_item: (praw.models.Submission, praw.models.Comment)) -> BaseArchiveEntry:
|
def _pull_lever_entry_factory(praw_item: praw.models.Submission | praw.models.Comment) -> BaseArchiveEntry:
|
||||||
if isinstance(praw_item, praw.models.Submission):
|
if isinstance(praw_item, praw.models.Submission):
|
||||||
return SubmissionArchiveEntry(praw_item)
|
return SubmissionArchiveEntry(praw_item)
|
||||||
elif isinstance(praw_item, praw.models.Comment):
|
elif isinstance(praw_item, praw.models.Comment):
|
||||||
|
@ -73,7 +73,7 @@ class Archiver(RedditConnector):
|
||||||
else:
|
else:
|
||||||
raise ArchiverError(f'Factory failed to classify item of type {type(praw_item).__name__}')
|
raise ArchiverError(f'Factory failed to classify item of type {type(praw_item).__name__}')
|
||||||
|
|
||||||
def write_entry(self, praw_item: (praw.models.Submission, praw.models.Comment)):
|
def write_entry(self, praw_item: praw.models.Submission | praw.models.Comment):
|
||||||
if self.args.comment_context and isinstance(praw_item, praw.models.Comment):
|
if self.args.comment_context and isinstance(praw_item, praw.models.Comment):
|
||||||
logger.debug(f'Converting comment {praw_item.id} to submission {praw_item.submission.id}')
|
logger.debug(f'Converting comment {praw_item.id} to submission {praw_item.submission.id}')
|
||||||
praw_item = praw_item.submission
|
praw_item = praw_item.submission
|
||||||
|
|
|
@ -34,7 +34,7 @@ class FileNameFormatter:
|
||||||
self.directory_format_string: list[str] = directory_format_string.split('/')
|
self.directory_format_string: list[str] = directory_format_string.split('/')
|
||||||
self.time_format_string = time_format_string
|
self.time_format_string = time_format_string
|
||||||
|
|
||||||
def _format_name(self, submission: (Comment, Submission), format_string: str) -> str:
|
def _format_name(self, submission: Comment | Submission, format_string: str) -> str:
|
||||||
if isinstance(submission, Submission):
|
if isinstance(submission, Submission):
|
||||||
attributes = self._generate_name_dict_from_submission(submission)
|
attributes = self._generate_name_dict_from_submission(submission)
|
||||||
elif isinstance(submission, Comment):
|
elif isinstance(submission, Comment):
|
||||||
|
|
|
@ -6,7 +6,7 @@ import sys
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional, Type
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import praw.models
|
import praw.models
|
||||||
|
@ -33,7 +33,7 @@ def submission() -> MagicMock:
|
||||||
return test
|
return test
|
||||||
|
|
||||||
|
|
||||||
def do_test_string_equality(result: [Path, str], expected: str) -> bool:
|
def do_test_string_equality(result: Path | str, expected: str) -> bool:
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
expected = FileNameFormatter._format_for_windows(expected)
|
expected = FileNameFormatter._format_for_windows(expected)
|
||||||
return str(result).endswith(expected)
|
return str(result).endswith(expected)
|
||||||
|
@ -411,7 +411,7 @@ def test_windows_max_path(tmp_path: Path):
|
||||||
))
|
))
|
||||||
def test_name_submission(
|
def test_name_submission(
|
||||||
test_reddit_id: str,
|
test_reddit_id: str,
|
||||||
test_downloader: type(BaseDownloader),
|
test_downloader: Type[BaseDownloader],
|
||||||
expected_names: set[str],
|
expected_names: set[str],
|
||||||
reddit_instance: praw.reddit.Reddit,
|
reddit_instance: praw.reddit.Reddit,
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in a new issue