Skip to content

Commit

Permalink
Collection of nits (pypi#14860)
Browse files Browse the repository at this point in the history
  • Loading branch information
miketheman authored Nov 3, 2023
1 parent a5cdcde commit 9f11b57
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ updates:
- dependency-name: "botocore"
- dependency-name: "botocore-stubs"
groups:
celery:
# Keep both celery and kombu together
patterns:
- "celery"
- "kombu"
psycopg:
# Keep both psycopg and psycopg-c together
patterns:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.5.0
node-version: 20.9.0
cache: 'npm'
- name: Install Node dependencies
run: npm ci
Expand Down
1 change: 0 additions & 1 deletion warehouse/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def configure(settings=None):
maybe_set(settings, "oidc.jwk_cache_url", "REDIS_URL")
maybe_set(settings, "database.url", "DATABASE_URL")
maybe_set(settings, "elasticsearch.url", "ELASTICSEARCH_URL")
maybe_set(settings, "elasticsearch.url", "ELASTICSEARCH_SIX_URL")
maybe_set(settings, "sentry.dsn", "SENTRY_DSN")
maybe_set(settings, "sentry.transport", "SENTRY_TRANSPORT")
maybe_set(settings, "sessions.url", "REDIS_URL")
Expand Down
2 changes: 1 addition & 1 deletion warehouse/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from warehouse.metrics import IMetricsService
from warehouse.utils.attrs import make_repr

__all__ = ["includeme", "metadata", "ModelBase"]
__all__ = ["includeme", "metadata", "ModelBase", "Model"]


logger = logging.getLogger(__name__)
Expand Down
10 changes: 2 additions & 8 deletions warehouse/macaroons/caveats/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import json
import typing

from collections.abc import Mapping, Sequence
from collections.abc import Callable, Mapping, Sequence
from dataclasses import dataclass
from typing import Any, ClassVar, TypeVar

Expand Down Expand Up @@ -109,13 +109,7 @@ def lookup(self, /, tag: int) -> type[Caveat] | None:
_caveat_registry = _CaveatRegistry()


# TODO: The return signature detected is `"Union[Type[Dataclass], DataclassProxy]"`,
# but the expectation is `Type[Dataclass]`.
# See https://github.com/pydantic/pydantic/issues/4498 but not exactly the same.
# This might not be corrected in pydantic until 2.0.
# Original signature with type hints:
# def as_caveat(*, tag: int) -> Callable[[type[T]], type[T]]:
def as_caveat(*, tag: int):
def as_caveat(*, tag: int) -> Callable[[type[T]], type[T]]:
def deco(cls: type[T]) -> type[T]:
_caveat_registry.add(tag, typing.cast(type[Caveat], cls))
return cls
Expand Down
2 changes: 1 addition & 1 deletion warehouse/oidc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _invalid(errors):
)

try:
payload = TokenPayload.parse_raw(request.body)
payload = TokenPayload.model_validate_json(request.body)
unverified_jwt = payload.token
except ValidationError as exc:
return _invalid(errors=[{"code": "invalid-payload", "description": str(exc)}])
Expand Down
4 changes: 2 additions & 2 deletions warehouse/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import datetime


def now():
return datetime.datetime.utcnow()
def now() -> datetime.datetime:
return datetime.datetime.now(datetime.UTC)


def dotted_navigator(path):
Expand Down
2 changes: 1 addition & 1 deletion warehouse/utils/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
]


def random_token():
def random_token() -> str:
token = base64.urlsafe_b64encode(os.urandom(32)).rstrip(b"=")
return token.decode("utf8")

Expand Down
4 changes: 2 additions & 2 deletions warehouse/utils/gravatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import urllib.parse


def _hash(email):
def _hash(email: str | None) -> str:
if email is None:
email = ""

Expand All @@ -30,5 +30,5 @@ def gravatar(request, email, size=80):
return request.camo_url("?".join([url, urllib.parse.urlencode(params)]))


def profile(email):
def profile(email: str) -> str:
return f"https://gravatar.com/{_hash(email)}"
4 changes: 2 additions & 2 deletions warehouse/utils/webauthn.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def verify_registration_response(response, challenge, *, rp_id, origin):
# for the individual challenge.
encoded_challenge = _webauthn_b64encode(challenge)
try:
_credential = RegistrationCredential.parse_raw(response)
_credential = RegistrationCredential.model_validate_json(response)
return pywebauthn.verify_registration_response(
credential=_credential,
expected_challenge=encoded_challenge,
Expand Down Expand Up @@ -160,7 +160,7 @@ def verify_assertion_response(assertion, *, challenge, user, origin, rp_id):

for public_key, current_sign_count in webauthn_user_public_keys:
try:
_credential = AuthenticationCredential.parse_raw(assertion)
_credential = AuthenticationCredential.model_validate_json(assertion)
return pywebauthn.verify_authentication_response(
credential=_credential,
expected_challenge=encoded_challenge,
Expand Down

0 comments on commit 9f11b57

Please sign in to comment.