Skip to content

Commit

Permalink
appease flake8/mypy
Browse files Browse the repository at this point in the history
Change variables named `l` to `log`
Make IsFQNResource runtime type-checkable and use that to handle the FQN check
Make the GenerateNameProvider its own top-level Provider type
  • Loading branch information
Jacob Beck committed May 20, 2020
1 parent e2cd45b commit 715c886
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
9 changes: 7 additions & 2 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def packages_for_node(self) -> Iterable[Project]:

def _generate_merged(self) -> Mapping[str, Any]:
search_node: IsFQNResource
if hasattr(self.node, 'fqn'):
if isinstance(self.node, IsFQNResource):
search_node = self.node
else:
search_node = FQNLookup(self.node.package_name)
Expand Down Expand Up @@ -495,8 +495,13 @@ class ParseProvider(Provider):
source = ParseSourceResolver


class GenerateNameProvider(ParseProvider):
class GenerateNameProvider(Provider):
execute = False
Config = RuntimeConfigObject
DatabaseWrapper = ParseDatabaseWrapper
Var = RuntimeVar
ref = ParseRefResolver
source = ParseSourceResolver


class RuntimeProvider(Provider):
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/legacy_config_updater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TODO: rename this module.
from typing import Dict, Any, Mapping, List
from typing_extensions import Protocol
from typing_extensions import Protocol, runtime_checkable

import dbt.exceptions

Expand All @@ -16,6 +16,7 @@ class HasConfigFields(Protocol):
sources: Dict[str, Any]


@runtime_checkable
class IsFQNResource(Protocol):
fqn: List[str]
resource_type: NodeType
Expand Down
12 changes: 8 additions & 4 deletions core/dbt/rpc/builtins.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import signal
from datetime import datetime
from typing import Type, Union, Any, List
from typing import Type, Union, Any, List, Dict

import dbt.exceptions
from dbt.contracts.rpc import (
Expand Down Expand Up @@ -171,6 +171,10 @@ def poll_complete(
return cls.from_result(result, tags, timing, logs)


def _dict_logs(logs: List[LogMessage]) -> List[Dict[str, Any]]:
return [log.to_dict() for log in logs]


class Poll(RemoteBuiltinMethod[PollParameters, PollResult]):
METHOD_NAME = 'poll'

Expand Down Expand Up @@ -210,7 +214,7 @@ def handle_request(self) -> PollResult:
f'At end of task {task_id}, error state but error is None'
)
raise RPCException.from_error(
dbt_error(exc, logs=[l.to_dict() for l in task_logs])
dbt_error(exc, logs=_dict_logs(task_logs))
)
# the exception has logs already attached from the child, don't
# overwrite those
Expand All @@ -223,7 +227,7 @@ def handle_request(self) -> PollResult:
'None'
)
raise RPCException.from_error(
dbt_error(exc, logs=[l.to_dict() for l in task_logs])
dbt_error(exc, logs=_dict_logs(task_logs))
)
return poll_complete(
timing=timing,
Expand All @@ -245,5 +249,5 @@ def handle_request(self) -> PollResult:
f'Got unknown value state={state} for task {task_id}'
)
raise RPCException.from_error(
dbt_error(exc, logs=[l.to_dict() for l in task_logs])
dbt_error(exc, logs=_dict_logs(task_logs))
)
2 changes: 1 addition & 1 deletion core/dbt/rpc/task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def get_result(self) -> RemoteResult:
except RPCException as exc:
# RPC Exceptions come already preserialized for the jsonrpc
# framework
exc.logs = [l.to_dict() for l in self.logs]
exc.logs = [log.to_dict() for log in self.logs]
exc.tags = self.tags
raise

Expand Down
10 changes: 0 additions & 10 deletions core/dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,13 @@ class ExitCodes(int, Enum):
UnhandledError = 2


def to_bytes(s):
return s.encode('latin-1')


def coalesce(*args):
for arg in args:
if arg is not None:
return arg
return None


def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]


def get_profile_from_project(project):
target_name = project.get('target', {})
profile = project.get('outputs', {}).get(target_name, {})
Expand Down

0 comments on commit 715c886

Please sign in to comment.