Skip to content

Add flake8-bugbear in pre-commit hooks #213

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

Merged
merged 1 commit into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ repos:
- flake8-assertive
- flake8-typing-imports
- flake8-logging-format
- flake8-bugbear

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
Expand Down
4 changes: 3 additions & 1 deletion astronomer/providers/amazon/aws/hooks/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def is_keys_unchanged(
prefix: str,
inactivity_period: float = 60 * 60,
min_objects: int = 1,
previous_objects: Set[str] = set(),
previous_objects: Optional[Set[str]] = None,
inactivity_seconds: int = 0,
allow_delete: bool = True,
last_activity_time: Optional[datetime] = None,
Expand All @@ -238,6 +238,8 @@ async def is_keys_unchanged(
:return: dictionary with status and message
:rtype: Dict
"""
if previous_objects is None:
previous_objects = set()
list_keys = await self._list_keys(client=client, bucket_name=bucket_name, prefix=prefix)
current_objects = set(list_keys)
current_num_objects = len(current_objects)
Expand Down
6 changes: 4 additions & 2 deletions astronomer/providers/amazon/aws/triggers/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __init__(
inactivity_period: float = 60 * 60,
min_objects: int = 1,
inactivity_seconds: int = 0,
previous_objects: Optional[Set[str]] = set(),
previous_objects: Optional[Set[str]] = None,
allow_delete: bool = True,
aws_conn_id: str = "aws_default",
last_activity_time: Optional[datetime] = None,
Expand All @@ -193,9 +193,11 @@ def __init__(
self.prefix = prefix
if inactivity_period < 0:
raise ValueError("inactivity_period must be non-negative")
if previous_objects is None:
previous_objects = set()
self.inactivity_period = inactivity_period
self.min_objects = min_objects
self.previous_objects = previous_objects or set()
self.previous_objects = previous_objects
self.inactivity_seconds = inactivity_seconds
self.allow_delete = allow_delete
self.aws_conn_id = aws_conn_id
Expand Down
24 changes: 14 additions & 10 deletions astronomer/providers/apache/livy/hooks/livy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import aiohttp
from aiohttp import ClientResponseError
from airflow.models import Connection
from airflow.providers.apache.livy.hooks.livy import BatchState
from airflow.utils.log.logging_mixin import LoggingMixin
from asgiref.sync import sync_to_async
Expand Down Expand Up @@ -76,16 +77,7 @@ async def _do_api_call_async(
if self.http_conn_id:
conn = await sync_to_async(self.get_connection)(self.http_conn_id)

if conn.host and "://" in conn.host:
self.base_url = conn.host
else:
# schema defaults to HTTP
schema = conn.schema if conn.schema else "http"
host = conn.host if conn.host else ""
self.base_url = schema + "://" + host

if conn.port:
self.base_url = self.base_url + ":" + str(conn.port)
self.base_url = self._generate_base_url(conn)
if conn.login:
auth = self.auth_type(conn.login, conn.password)
if conn.extra:
Expand Down Expand Up @@ -140,6 +132,18 @@ async def _do_api_call_async(
attempt_num += 1
await asyncio.sleep(self.retry_delay)

def _generate_base_url(self, conn: Connection) -> str:
if conn.host and "://" in conn.host:
base_url: str = conn.host
else:
# schema defaults to HTTP
schema = conn.schema if conn.schema else "http"
host = conn.host if conn.host else ""
base_url = f"{schema}://{host}"
if conn.port:
base_url = f"{base_url}:{conn.port}"
return base_url

async def run_method(
self,
endpoint: str,
Expand Down
3 changes: 2 additions & 1 deletion tests/apache/livy/hooks/test_livy.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,9 @@ def test_build_get_hook(self):
for conn_id, expected in connection_url_mapping.items():
with self.subTest(conn_id):
hook = LivyHookAsync(livy_conn_id=conn_id)
response_conn = hook.get_connection(conn_id=conn_id)
response_conn: Connection = hook.get_connection(conn_id=conn_id)
assert isinstance(response_conn, Connection)
assert hook._generate_base_url(response_conn) == expected

def test_build_body(self):
with self.subTest("minimal request"):
Expand Down
4 changes: 0 additions & 4 deletions tests/core/triggers/test_external_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,3 @@ def test_task_state_trigger_serialization():
"execution_dates": [DEFAULT_DATE],
"poll_interval": TEST_POLL_INTERVAL,
}


def hello(abc={}):
print(abc)