Skip to content

Commit

Permalink
chore(deps-dev): Bump flake8-annotations from 2.7.0 to 2.9.0 (#695)
Browse files Browse the repository at this point in the history
* Bump flake8-annotations from 2.7.0 to 2.9.0

Bumps [flake8-annotations](https://github.com/sco1/flake8-annotations) from 2.7.0 to 2.9.0.
- [Release notes](https://github.com/sco1/flake8-annotations/releases)
- [Changelog](https://github.com/sco1/flake8-annotations/blob/main/CHANGELOG.md)
- [Commits](sco1/flake8-annotations@v2.7.0...v2.9.0)

---
updated-dependencies:
- dependency-name: flake8-annotations
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update types to make flake8 happy

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Edgar Ramírez Mondragón <[email protected]>
  • Loading branch information
dependabot[bot] and edgarrmondragon authored Jun 14, 2022
1 parent 4e60670 commit 2166416
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 126 deletions.
13 changes: 7 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ numpy = ">=1.20.0"
tox = "^3.25.0"
freezegun = "^1.2.1"
viztracer = "^0.15.3"
flake8-annotations = "^2.6.2"
flake8-annotations = "^2.9.0"
darglint = "^1.8.0"
isort = "^5.9.3"
pyupgrade = "^2.34.0"
Expand Down
65 changes: 35 additions & 30 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Classes to assist in authenticating to APIs."""

from __future__ import annotations

import base64
import logging
import math
from datetime import datetime, timedelta
from types import MappingProxyType
from typing import Any, Dict, Mapping, Optional, Tuple, Type, Union
from typing import Any, Mapping

import jwt
import requests
Expand All @@ -20,7 +22,7 @@
class SingletonMeta(type):
"""A general purpose singleton metaclass."""

def __init__(cls, name: str, bases: Tuple[type], dic: dict) -> None:
def __init__(cls, name: str, bases: tuple[type], dic: dict) -> None:
"""Init metaclass.
The single instance is saved as an attribute of the the metaclass.
Expand All @@ -33,7 +35,7 @@ def __init__(cls, name: str, bases: Tuple[type], dic: dict) -> None:
cls.__single_instance = None
super().__init__(name, bases, dic)

def __call__(cls, *args: Any, **kwargs: Dict[str, Any]) -> Any:
def __call__(cls, *args: Any, **kwargs: Any) -> Any: # noqa: ANN401
"""Create or reuse the singleton.
Args:
Expand Down Expand Up @@ -61,9 +63,9 @@ def __init__(self, stream: RESTStreamBase) -> None:
stream: A stream for a RESTful endpoint.
"""
self.tap_name: str = stream.tap_name
self._config: Dict[str, Any] = dict(stream.config)
self._auth_headers: Dict[str, Any] = {}
self._auth_params: Dict[str, Any] = {}
self._config: dict[str, Any] = dict(stream.config)
self._auth_headers: dict[str, Any] = {}
self._auth_params: dict[str, Any] = {}
self.logger: logging.Logger = stream.logger

@property
Expand Down Expand Up @@ -104,7 +106,7 @@ class SimpleAuthenticator(APIAuthenticatorBase):
def __init__(
self,
stream: RESTStreamBase,
auth_headers: Optional[Dict] = None,
auth_headers: dict | None = None,
) -> None:
"""Create a new authenticator.
Expand Down Expand Up @@ -166,12 +168,12 @@ def __init__(

@classmethod
def create_for_stream(
cls: Type["APIKeyAuthenticator"],
cls: type[APIKeyAuthenticator],
stream: RESTStreamBase,
key: str,
value: str,
location: str,
) -> "APIKeyAuthenticator":
) -> APIKeyAuthenticator:
"""Create an Authenticator object specific to the Stream class.
Args:
Expand All @@ -181,7 +183,8 @@ def create_for_stream(
location: Where the API key is to be added. Either 'header' or 'params'.
Returns:
A new :class:`singer_sdk.authenticators.APIKeyAuthenticator` instance.
APIKeyAuthenticator: A new
:class:`singer_sdk.authenticators.APIKeyAuthenticator` instance.
"""
return cls(stream=stream, key=key, value=value, location=location)

Expand Down Expand Up @@ -210,16 +213,17 @@ def __init__(self, stream: RESTStreamBase, token: str) -> None:

@classmethod
def create_for_stream(
cls: Type["BearerTokenAuthenticator"], stream: RESTStreamBase, token: str
) -> "BearerTokenAuthenticator":
cls: type[BearerTokenAuthenticator], stream: RESTStreamBase, token: str
) -> BearerTokenAuthenticator:
"""Create an Authenticator object specific to the Stream class.
Args:
stream: The stream instance to use with this authenticator.
token: Authentication token.
Returns:
A new :class:`singer_sdk.authenticators.BearerTokenAuthenticator` instance.
BearerTokenAuthenticator: A new
:class:`singer_sdk.authenticators.BearerTokenAuthenticator` instance.
"""
return cls(stream=stream, token=token)

Expand Down Expand Up @@ -256,11 +260,11 @@ def __init__(

@classmethod
def create_for_stream(
cls: Type["BasicAuthenticator"],
cls: type[BasicAuthenticator],
stream: RESTStreamBase,
username: str,
password: str,
) -> "BasicAuthenticator":
) -> BasicAuthenticator:
"""Create an Authenticator object specific to the Stream class.
Args:
Expand All @@ -269,7 +273,8 @@ def create_for_stream(
password: API password.
Returns:
A new :class:`singer_sdk.authenticators.BasicAuthenticator` instance.
BasicAuthenticator: A new
:class:`singer_sdk.authenticators.BasicAuthenticator` instance.
"""
return cls(stream=stream, username=username, password=password)

Expand All @@ -280,9 +285,9 @@ class OAuthAuthenticator(APIAuthenticatorBase):
def __init__(
self,
stream: RESTStreamBase,
auth_endpoint: Optional[str] = None,
oauth_scopes: Optional[str] = None,
default_expiration: Optional[int] = None,
auth_endpoint: str | None = None,
oauth_scopes: str | None = None,
default_expiration: int | None = None,
) -> None:
"""Create a new authenticator.
Expand All @@ -298,10 +303,10 @@ def __init__(
self._oauth_scopes = oauth_scopes

# Initialize internal tracking attributes
self.access_token: Optional[str] = None
self.refresh_token: Optional[str] = None
self.last_refreshed: Optional[datetime] = None
self.expires_in: Optional[int] = None
self.access_token: str | None = None
self.refresh_token: str | None = None
self.last_refreshed: datetime | None = None
self.expires_in: int | None = None

@property
def auth_headers(self) -> dict:
Expand Down Expand Up @@ -333,7 +338,7 @@ def auth_endpoint(self) -> str:
return self._auth_endpoint

@property
def oauth_scopes(self) -> Optional[str]:
def oauth_scopes(self) -> str | None:
"""Get OAuth scopes.
Returns:
Expand Down Expand Up @@ -378,7 +383,7 @@ def oauth_request_body(self) -> dict:
)

@property
def client_id(self) -> Optional[str]:
def client_id(self) -> str | None:
"""Get client ID string to be used in authentication.
Returns:
Expand All @@ -389,7 +394,7 @@ def client_id(self) -> Optional[str]:
return None

@property
def client_secret(self) -> Optional[str]:
def client_secret(self) -> str | None:
"""Get client secret to be used in authentication.
Returns:
Expand Down Expand Up @@ -446,7 +451,7 @@ class OAuthJWTAuthenticator(OAuthAuthenticator):
"""API Authenticator for OAuth 2.0 flows which utilize a JWT refresh token."""

@property
def private_key(self) -> Optional[str]:
def private_key(self) -> str | None:
"""Return the private key to use in encryption.
Returns:
Expand All @@ -455,7 +460,7 @@ def private_key(self) -> Optional[str]:
return self.config.get("private_key", None)

@property
def private_key_passphrase(self) -> Optional[str]:
def private_key_passphrase(self) -> str | None:
"""Return the private key passphrase to use in encryption.
Returns:
Expand Down Expand Up @@ -492,15 +497,15 @@ def oauth_request_payload(self) -> dict:
if not self.private_key:
raise ValueError("Missing 'private_key' property for OAuth payload.")

private_key: Union[bytes, Any] = bytes(self.private_key, "UTF-8")
private_key: bytes | Any = bytes(self.private_key, "UTF-8")
if self.private_key_passphrase:
passphrase = bytes(self.private_key_passphrase, "UTF-8")
private_key = serialization.load_pem_private_key(
private_key,
password=passphrase,
backend=default_backend(),
)
private_key_string: Union[str, Any] = private_key.decode("UTF-8")
private_key_string: str | Any = private_key.decode("UTF-8")
return {
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": jwt.encode(
Expand Down
16 changes: 11 additions & 5 deletions singer_sdk/helpers/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from enum import Enum, EnumMeta
from typing import Any
from typing import Any, TypeVar
from warnings import warn

from singer_sdk.typing import (
Expand All @@ -14,6 +14,8 @@
Property,
)

_EnumMemberT = TypeVar("_EnumMemberT")

# Default JSON Schema to support config for built-in capabilities:

STREAM_MAPS_CONFIG = PropertiesList(
Expand Down Expand Up @@ -48,7 +50,11 @@
class DeprecatedEnum(Enum):
"""Base class for capabilities enumeration."""

def __new__(cls, value: Any, deprecation: str | None = None) -> DeprecatedEnum:
def __new__(
cls,
value: _EnumMemberT,
deprecation: str | None = None,
) -> DeprecatedEnum:
"""Create a new enum member.
Args:
Expand Down Expand Up @@ -85,7 +91,7 @@ def emit_warning(self) -> None:
class DeprecatedEnumMeta(EnumMeta):
"""Metaclass for enumeration with deprecation support."""

def __getitem__(self, name: str) -> Any:
def __getitem__(self, name: str) -> Any: # noqa: ANN401
"""Retrieve mapping item.
Args:
Expand All @@ -99,7 +105,7 @@ def __getitem__(self, name: str) -> Any:
obj.emit_warning()
return obj

def __getattribute__(cls, name: str) -> Any:
def __getattribute__(cls, name: str) -> Any: # noqa: ANN401
"""Retrieve enum attribute.
Args:
Expand All @@ -113,7 +119,7 @@ def __getattribute__(cls, name: str) -> Any:
obj.emit_warning()
return obj

def __call__(self, *args: Any, **kwargs: Any) -> Any:
def __call__(self, *args: Any, **kwargs: Any) -> Any: # noqa: ANN401
"""Call enum member.
Args:
Expand Down
Loading

0 comments on commit 2166416

Please sign in to comment.