Fixes according to SonerLint

This commit is contained in:
kokarare1212 2021-07-31 20:42:13 +09:00
parent 3f81de1610
commit bee0ad3ec1
14 changed files with 57 additions and 59 deletions

View File

@ -12,7 +12,6 @@ class Version:
if platform.system() == "Darwin":
return Platform.PLATFORM_OSX_X86
return Platform.PLATFORM_LINUX_X86
pass
@staticmethod
def version_string():

View File

@ -61,10 +61,10 @@ class ZeroconfServer(Closeable):
)
class Inner:
device_type: Connect.DeviceType = None
device_name: str = None
device_id: str = None
preferred_locale: str = None
device_type: Connect.DeviceType
device_name: str
device_id: str
preferred_locale: str
conf = None
def __init__(

View File

@ -3,8 +3,8 @@ from librespot.proto import Metadata_pb2 as Metadata
class StreamId:
file_id: bytes = None
episode_gid: bytes = None
file_id: bytes
episode_gid: bytes
def __init__(self,
file: Metadata.AudioFile = None,

View File

@ -29,7 +29,7 @@ if typing.TYPE_CHECKING:
class CdnManager:
_LOGGER: logging = logging.getLogger(__name__)
_session: Session = None
_session: Session
def __init__(self, session: Session):
self._session = session
@ -118,14 +118,14 @@ class CdnManager:
self._headers = headers
class CdnUrl:
_cdnManager = None
_fileId: bytes
__cdnManager = None
__fileId: bytes
_expiration: int
_url: str
def __init__(self, cdn_manager, file_id: bytes, url: str):
self._cdnManager: CdnManager = cdn_manager
self._fileId = file_id
self.__cdnManager: CdnManager = cdn_manager
self.__fileId = file_id
self.set_url(url)
def url(self):
@ -133,14 +133,14 @@ class CdnManager:
return self._url
if self._expiration <= int(time.time() * 1000) + 5 * 60 * 1000:
self._url = self._cdnManager.get_audio_url(self._fileId)
self._url = self.__cdnManager.get_audio_url(self.__fileId)
return self.url
def set_url(self, url: str):
self._url = url
if self._fileId is not None:
if self.__fileId is not None:
token_url = urllib.parse.urlparse(url)
token_query = urllib.parse.parse_qs(token_url.query)
token_list = token_query.get("__token__")
@ -163,7 +163,7 @@ class CdnManager:
if expire_at is None:
self._expiration = -1
self._cdnManager._LOGGER.warning(
self.__cdnManager._LOGGER.warning(
"Invalid __token__ in CDN url: {}".format(url))
return
@ -173,8 +173,8 @@ class CdnManager:
i = token_url.query.index("_")
except ValueError:
self._expiration = -1
self._cdnManager._LOGGER.warning(
"Couldn't extract expiration, invalid parameter in CDN url: "
self.__cdnManager._LOGGER.warning(
"Couldn't extract expiration, invalid parameter in CDN url: {}"
.format(url))
return
@ -187,19 +187,19 @@ class CdnManager:
GeneralAudioStream.GeneralAudioStream,
GeneralWritableStream.GeneralWritableStream,
):
_session: Session = None
_streamId: StreamId.StreamId = None
_session: Session
_streamId: StreamId.StreamId
_executorService = concurrent.futures.ThreadPoolExecutor()
_audioFormat: SuperAudioFormat = None
_audioDecrypt: AudioDecrypt = None
_audioFormat: SuperAudioFormat
_audioDecrypt: AudioDecrypt
_cdnUrl = None
_size: int
_buffer: typing.List[bytearray]
_available: typing.List[bool]
_requested: typing.List[bool]
_chunks: int
_internalStream: CdnManager.Streamer.InternalStream = None
_haltListener: HaltListener = None
_internalStream: CdnManager.Streamer.InternalStream
_haltListener: HaltListener
def __init__(
self,

View File

@ -31,7 +31,7 @@ class AesAudioDecrypt(AudioDecrypt):
cipher = None
decrypt_count = 0
decrypt_total_time = 0
key: bytes = None
key: bytes
def __init__(self, key: bytes):
self.key = key
@ -57,7 +57,7 @@ class AesAudioDecrypt(AudioDecrypt):
iv += self.iv_diff
self.decrypt_total_time += time.time_ns()
self.decrypt_total_time += time.time_ns() - start
self.decrypt_count += 1
return new_buffer

View File

@ -55,7 +55,7 @@ class Base62:
if len(out) < estimated_length:
size = len(out)
for i in range(estimated_length - size):
for _ in range(estimated_length - size):
out += bytes([0])
return self.reverse(out)

View File

@ -42,7 +42,7 @@ class EventService:
elif type(event_or_builder) is EventService.EventBuilder:
builder = event_or_builder
else:
TypeError()
raise TypeError()
self._worker.submit(lambda: self._worker_callback(builder))
def language(self, lang: str):

View File

@ -331,7 +331,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
_search: SearchManager = None
_contentFeeder: PlayableContentFeeder.PlayableContentFeeder = None
_eventService: EventService = None
_countryCode: str = None
_countryCode: str
_closed: bool = False
_closing: bool = False
_scheduledReconnect: sched.Event = None
@ -869,10 +869,10 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
class Inner:
device_type: Connect.DeviceType = None
device_name: str = None
device_id: str = None
device_name: str
device_id: str
conf = None
preferred_locale: str = None
preferred_locale: str
def __init__(
self,
@ -1035,17 +1035,17 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
class Builder:
# Proxy
proxyEnabled: bool = False
proxyType: Proxy.Type = None
proxyAddress: str = None
proxyPort: int = None
proxyAuth: bool = None
proxyUsername: str = None
proxyPassword: str = None
proxyType: Proxy.Type
proxyAddress: str
proxyPort: int
proxyAuth: bool
proxyUsername: str
proxyPassword: str
# Cache
cache_enabled: bool = True
cache_dir: str = os.path.join(os.getcwd(), "cache")
do_cache_clean_up: bool = None
do_cache_clean_up: bool
# Stored credentials
store_credentials: bool = True
@ -1053,7 +1053,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
os.getcwd(), "credentials.json")
# Fetching
retry_on_chunk_error: bool = None
retry_on_chunk_error: bool
def set_proxy_enabled(
self,
@ -1230,7 +1230,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
return 2
class Receiver:
session: Session = None
session: Session
thread: threading.Thread
running: bool = True

View File

@ -17,7 +17,7 @@ from librespot.standard import Closeable
class ApiClient(Closeable):
_LOGGER: logging = logging.getLogger(__name__)
_session = None
_baseUrl: str = None
_baseUrl: str
def __init__(self, session):
self._session = session

View File

@ -249,7 +249,7 @@ class MercuryClient(PacketsReceiver.PacketsReceiver, Closeable):
code: int
def __init__(self, response):
super("status: {}".format(response.status_code))
super().__init__("status: {}".format(response.status_code))
self.code = response.status_code
class Response:

View File

@ -36,7 +36,6 @@ class PlayableId:
@staticmethod
def from_uri(uri: str) -> PlayableId:
pass
if not PlayableId.is_supported(uri):
return UnsupportedId(uri)
@ -167,7 +166,7 @@ class EpisodeId(SpotifyId, PlayableId):
episode_id = matcher.group(1)
return EpisodeId(
Utils.bytes_to_hex(PlayableId.BASE62.decode(episode_id, 16)))
TypeError("Not a Spotify episode ID: {}".format(uri))
raise TypeError("Not a Spotify episode ID: {}".format(uri))
@staticmethod
def from_base62(base62: str) -> EpisodeId:

View File

@ -19,15 +19,15 @@ class Player(Closeable, PlayerSession.Listener, AudioSink.Listener):
VOLUME_MAX: int = 65536
_LOGGER: logging = logging.getLogger(__name__)
_scheduler: sched.scheduler = sched.scheduler(time.time)
_session: Session = None
_conf: PlayerConfiguration = None
_events: Player.EventsDispatcher = None
_sink: AudioSink = None
_session: Session
_conf: PlayerConfiguration
_events: Player.EventsDispatcher
_sink: AudioSink
_metrics: typing.Dict[str, PlaybackMetrics] = {}
_state: StateWrapper = None
_playerSession: PlayerSession = None
_state: StateWrapper
_playerSession: PlayerSession
_releaseLineFuture = None
_deviceStateListener: DeviceStateHandler.Listener = None
_deviceStateListener: DeviceStateHandler.Listener
def __init__(self, conf: PlayerConfiguration, session: Session):
self._conf = conf

View File

@ -17,13 +17,13 @@ from librespot.proto import Player_pb2 as Player
class DeviceStateHandler:
_LOGGER: logging = logging.getLogger(__name__)
_session: Session = None
_deviceInfo: Connect.DeviceInfo = None
_session: Session
_deviceInfo: Connect.DeviceInfo
_listeners: typing.List[DeviceStateHandler.Listener] = []
_putState: Connect.PutStateRequest = None
_putState: Connect.PutStateRequest
_putStateWorker: concurrent.futures.ThreadPoolExecutor = (
concurrent.futures.ThreadPoolExecutor())
_connectionId: str = None
_connectionId: str
def __init__(self, session: Session, player, conf: PlayerConfiguration):
self._session = session
@ -101,9 +101,9 @@ class DeviceStateHandler:
pass
class CommandBody:
_obj: typing.Any = None
_data: bytes = None
_value: str = None
_obj: typing.Any
_data: bytes
_value: str
def __init__(self, obj: typing.Any):
self._obj = obj

View File

@ -24,7 +24,7 @@ class Zeroconf(Closeable):
self.__BROADCAST6 = socket.socket(socket.AF_INET6,
socket.SOCK_DGRAM)
self.__BROADCAST6.connect(("FF02::FB", 5353))
except Exception as e:
except Exception:
pass
self.set_domain(".local")
self.set_local_host_name(Zeroconf.get_or_create_local_host_name())