Skip to content

Commit

Permalink
style: enable pyright strict mode for craft_store
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Oct 23, 2023
1 parent a391b5d commit 71b8b33
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 63 deletions.
11 changes: 7 additions & 4 deletions craft_store/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def set_credentials(self, credentials: str, force: bool = False) -> None:
"Storing credentials for %r on %r in keyring %r.",
self.application_name,
self.host,
self._keyring.name,
self._keyring.name, # pyright: ignore
)
encoded_credentials = self.encode_credentials(credentials)
self._keyring.set_password(
Expand All @@ -170,7 +170,7 @@ def get_credentials(self) -> str:
"Retrieving credentials for %r on %r from keyring %r.",
self.application_name,
self.host,
self._keyring.name,
self._keyring.name, # pyright: ignore
)

try:
Expand All @@ -187,7 +187,10 @@ def get_credentials(self) -> str:
) from unknown_error

if encoded_credentials_string is None:
logger.debug("Credentials not found in the keyring %r", self._keyring.name)
logger.debug(
"Credentials not found in the keyring %r",
self._keyring.name # pyright: ignore
)
raise errors.CredentialsUnavailable(self.application_name, self.host)
return self.decode_credentials(encoded_credentials_string)

Expand All @@ -201,6 +204,6 @@ def del_credentials(self) -> None:
"Deleting credentials for %r on %r from keyring %r.",
self.application_name,
self.host,
self._keyring.name,
self._keyring.name, # pyright: ignore
)
self._keyring.delete_password(self.application_name, self.host)
7 changes: 5 additions & 2 deletions craft_store/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,18 @@ def progress_printer(monitor: requests_toolbelt.MultipartEncoderMonitor):

# create a monitor (so that progress can be displayed) as call the real pusher
if monitor_callback is not None:
monitor = MultipartEncoderMonitor(encoder, monitor_callback(encoder))
monitor = MultipartEncoderMonitor(
encoder,
monitor_callback(encoder) # pyright: ignore
)
else:
monitor = MultipartEncoderMonitor(encoder)

response = self.http_client.request(
"POST",
self._storage_base_url + self._endpoints.upload,
headers={
"Content-Type": monitor.content_type,
"Content-Type": monitor.content_type, # pyright: ignore
"Accept": "application/json",
},
data=monitor,
Expand Down
6 changes: 3 additions & 3 deletions craft_store/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import dataclasses
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, Final, Optional, Sequence, Type
from typing import Any, Dict, Final, Optional, Sequence, Type, Union

from overrides import overrides
from overrides import overrides # pyright: ignore

from craft_store.models import (
MarshableModel,
Expand Down Expand Up @@ -88,7 +88,7 @@ def get_token_request(
:param packages: a sequence of :attr:`Package` to limit the requested token to.
:param channels: a sequence of channels to limit the requested token to.
"""
token_request = {
token_request: Dict[str, Union[str, Sequence[str], int, Sequence[Dict[str, str]]]] = {
"permissions": permissions,
"description": description,
"ttl": ttl,
Expand Down
2 changes: 1 addition & 1 deletion craft_store/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __repr__(self) -> str:
for error in self._error_list:
code = error.get("code")
if code:
code_list.append(code)
code_list.append(code) # pyright: ignore

return "<StoreErrorList: {' '.join(code_list)}>"

Expand Down
2 changes: 1 addition & 1 deletion craft_store/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# pyright: reportUnknownArgumentType=false
"""Craft Store HTTPClient."""

import logging
Expand Down
10 changes: 5 additions & 5 deletions craft_store/store_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# pyright: reportUnknownMemberType=warning
"""Craft Store StoreClient."""

import base64
import json
from typing import Optional, Any

from macaroonbakery import bakery, httpbakery # type: ignore[import]
from overrides import overrides
from overrides import overrides # pyright: ignore[reportUnknownVariableType]
from pymacaroons import Macaroon # type: ignore[import]
from pymacaroons.serializers import json_serializer # type: ignore[import]

Expand All @@ -31,10 +31,10 @@


def _macaroon_to_json_string(macaroon: Macaroon) -> str:
json_string = macaroon.serialize(json_serializer.JsonSerializer())
json_string = macaroon.serialize(json_serializer.JsonSerializer()) # pyright: ignore
if json_string is None:
return ""
return str(json_string)
return str(json_string) # pyright: ignore[reportUnknownArgumentType]


class WebBrowserWaitingInteractor(httpbakery.WebBrowserInteractor): # type: ignore[misc]
Expand All @@ -47,7 +47,7 @@ class WebBrowserWaitingInteractor(httpbakery.WebBrowserInteractor): # type: ign
"""

def __init__(self, user_agent: str) -> None:
super().__init__()
super().__init__() # pyright: ignore
self.user_agent = user_agent

# TODO: transfer implementation to macaroonbakery.
Expand Down
6 changes: 3 additions & 3 deletions craft_store/ubuntu_one_store_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# pyright: reportUnknownMemberType=false, reportUnknownVariableType=false
"""Craft Store StoreClient."""

from typing import Dict, Optional, Any, cast
Expand Down Expand Up @@ -92,10 +92,10 @@ def _extract_caveat_id(self, root_macaroon: str) -> str:
# macaroons are all bytes, never strings
sso_host = urlparse(self._auth_url).netloc

for caveat in macaroon.caveats: # pyright: ignore[reportUnknownVariableType]
for caveat in macaroon.caveats:
location = cast(str, caveat.location)
if location == sso_host:
return str(caveat.caveat_id)
return str(caveat.caveat_id) # pyright: ignore[reportUnknownArgumentType]
raise errors.CraftStoreError("Invalid root macaroon")

def _discharge(
Expand Down
46 changes: 2 additions & 44 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,55 +146,13 @@ extension-pkg-whitelist = [
load-plugins = "pylint_fixme_info,pylint_pytest"

[tool.pyright]
#strict = ["craft_store"]
disableBytesTypePromotions = true
strictListInterface = true
strictDictionaryInterface = true
strictSetInterface = true
reportAssertAlwaysTrue = "error"
reportInvalidStringEscapeSequence = "error"
reportInvalidTypeVarUse = "error"
reportMissingTypeStubs = "error"
reportSelfClsParameterName = "error"
reportUnsupportedDunderAll = "error"
reportUnusedExpression = "error"
reportConstantRedefenition = "error"
reportDeprecated = "error"
reportDuplicateImport = "error"
reportFunctionMemberAccess = "error"
reportIncompleteVariableOverride = "error"
reportIncompleteStub = "error"
reportInconsistentConstructor = "error"
reportInvalidStubStatement = "error"
reportMatchNotExhaustive = "error"
reportMissingParameterType = "error"
reportMissingTypeArgument = "error"
reportOverlappingOverload = "error"
reportPrivateUsage = "error"
reportTypeCommentUsage = "error"
reportUnknownArgumentType = "warning" # Lots of pass-throughs of *args and **kwargs
reportUnknownLambdaType = "error"
reportUnknownMemberType = "none" # Too many uses in libraries to meaningfully enable this.
reportUnknownParameterType = "error"
reportUnknownVariableType = "warning" # Many instancess of this, will resolve next
reportUnnecessaryCast = "error"
reportUnnecessaryComparison = "error"
reportUnnecessaryContains = "error"
reportUnnecessaryIsInstance = "error"
reportUnusedClass = "error"
reportUnusedImpart = "error"
reportUnusedFunction = "error"
reportUnusedVariable = "error"
reportUntypedBaseClass = "error"
reportUntypedClassDecorator = "error"
reportUntypedFunctionDecorator = "error"
reportUntypedNamedTuple = "error"
strict = ["craft_store"]

pythonVersion = "3.8"
pythonPlatform = "Linux"
include = [
"craft_store",
# "tests"
"tests"
]
exclude = [
"**/.*",
Expand Down

0 comments on commit 71b8b33

Please sign in to comment.