Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add type hints to base.py #1302

Open
wants to merge 14 commits into
base: typehints
Choose a base branch
from
3 changes: 2 additions & 1 deletion plexapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from logging.handlers import RotatingFileHandler
from platform import uname
from typing import cast
from uuid import getnode

from plexapi.config import PlexConfig, reset_base_headers
Expand All @@ -18,7 +19,7 @@
PROJECT = 'PlexAPI'
VERSION = __version__ = const.__version__
TIMEOUT = CONFIG.get('plexapi.timeout', 30, int)
X_PLEX_CONTAINER_SIZE = CONFIG.get('plexapi.container_size', 100, int)
X_PLEX_CONTAINER_SIZE = cast(int, CONFIG.get('plexapi.container_size', 100, int))
X_PLEX_ENABLE_FAST_CONNECT = CONFIG.get('plexapi.enable_fast_connect', False, bool)

# Plex Header Configuration
Expand Down
20 changes: 13 additions & 7 deletions plexapi/audio.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import os
from pathlib import Path
from typing import TYPE_CHECKING
from urllib.parse import quote_plus

from typing import Any, Dict, List, Optional, TypeVar

from plexapi import media, utils
from plexapi.base import Playable, PlexPartialObject, PlexHistory, PlexSession
from plexapi.base import Playable, PlexHistory, PlexPartialObject, PlexSession
from plexapi.exceptions import BadRequest
from plexapi.mixins import (
AdvancedSettingsMixin, SplitMergeMixin, UnmatchMatchMixin, ExtrasMixin, HubsMixin, PlayedUnplayedMixin, RatingMixin,
Expand All @@ -15,6 +18,9 @@
)
from plexapi.playlist import Playlist

if TYPE_CHECKING:
from xml.etree.ElementTree import Element

Dr-Blank marked this conversation as resolved.
Show resolved Hide resolved

TAudio = TypeVar("TAudio", bound="Audio")

Expand Down Expand Up @@ -53,7 +59,7 @@ class Audio(PlexPartialObject, PlayedUnplayedMixin):
"""
METADATA_TYPE = 'track'

def _loadData(self, data):
def _loadData(self, data: Element):
""" Load attribute values from Plex XML response. """
self._data = data
self.addedAt = utils.toDatetime(data.attrib.get('addedAt'))
Expand Down Expand Up @@ -192,7 +198,7 @@ class Artist(
TAG = 'Directory'
TYPE = 'artist'

def _loadData(self, data):
def _loadData(self, data: Element):
""" Load attribute values from Plex XML response. """
Audio._loadData(self, data)
self.albumSort = utils.cast(int, data.attrib.get('albumSort', '-1'))
Expand Down Expand Up @@ -323,7 +329,7 @@ class Album(
TAG = 'Directory'
TYPE = 'album'

def _loadData(self, data):
def _loadData(self, data: Element):
""" Load attribute values from Plex XML response. """
Audio._loadData(self, data)
self.collections = self.findItems(data, media.Collection)
Expand Down Expand Up @@ -455,7 +461,7 @@ class Track(
TAG = 'Track'
TYPE = 'track'

def _loadData(self, data):
def _loadData(self, data: Element):
""" Load attribute values from Plex XML response. """
Audio._loadData(self, data)
Playable._loadData(self, data)
Expand Down Expand Up @@ -535,7 +541,7 @@ class TrackSession(PlexSession, Track):
"""
_SESSIONTYPE = True

def _loadData(self, data):
def _loadData(self, data: Element):
""" Load attribute values from Plex XML response. """
Track._loadData(self, data)
PlexSession._loadData(self, data)
Expand All @@ -548,7 +554,7 @@ class TrackHistory(PlexHistory, Track):
"""
_HISTORYTYPE = True

def _loadData(self, data):
def _loadData(self, data: Element):
""" Load attribute values from Plex XML response. """
Track._loadData(self, data)
PlexHistory._loadData(self, data)
Loading