diff --git a/.changes/unreleased/Dependencies-20230222-162807.yaml b/.changes/unreleased/Dependencies-20230222-162807.yaml new file mode 100644 index 00000000000..0ab179931ac --- /dev/null +++ b/.changes/unreleased/Dependencies-20230222-162807.yaml @@ -0,0 +1,6 @@ +kind: "Dependencies" +body: "Bump mypy from 0.981 to 1.0.1" +time: 2023-02-22T16:28:07.00000Z +custom: + Author: dependabot[bot] + PR: 7027 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2c01d584893..040cf1051a3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,7 +37,7 @@ repos: alias: flake8-check stages: [manual] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.981 + rev: v1.3.0 hooks: - id: mypy # N.B.: Mypy is... a bit fragile. diff --git a/core/dbt/adapters/base/impl.py b/core/dbt/adapters/base/impl.py index 1fa2ce903f6..0ab265b43c8 100644 --- a/core/dbt/adapters/base/impl.py +++ b/core/dbt/adapters/base/impl.py @@ -415,7 +415,7 @@ def _get_catalog_schemas(self, manifest: Manifest) -> SchemaSearchMap: return info_schema_name_map def _relations_cache_for_schemas( - self, manifest: Manifest, cache_schemas: Set[BaseRelation] = None + self, manifest: Manifest, cache_schemas: Optional[Set[BaseRelation]] = None ) -> None: """Populate the relations cache for the given schemas. Returns an iterable of the schemas populated, as strings. @@ -451,7 +451,7 @@ def set_relations_cache( self, manifest: Manifest, clear: bool = False, - required_schemas: Set[BaseRelation] = None, + required_schemas: Optional[Set[BaseRelation]] = None, ) -> None: """Run a query that gets a populated cache of the relations in the database and set the cache on this adapter. @@ -986,7 +986,7 @@ def execute_macro( manifest: Optional[Manifest] = None, project: Optional[str] = None, context_override: Optional[Dict[str, Any]] = None, - kwargs: Dict[str, Any] = None, + kwargs: Optional[Dict[str, Any]] = None, text_only_columns: Optional[Iterable[str]] = None, ) -> AttrDict: """Look macro_name up in the manifest and execute its results. diff --git a/core/dbt/cli/flags.py b/core/dbt/cli/flags.py index d7178c0dedd..a16829fc79f 100644 --- a/core/dbt/cli/flags.py +++ b/core/dbt/cli/flags.py @@ -76,7 +76,9 @@ def args_to_context(args: List[str]) -> Context: class Flags: """Primary configuration artifact for running dbt""" - def __init__(self, ctx: Context = None, user_config: UserConfig = None) -> None: + def __init__( + self, ctx: Optional[Context] = None, user_config: Optional[UserConfig] = None + ) -> None: # Set the default flags. for key, value in FLAGS_DEFAULTS.items(): diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py index f91fbc29e3e..bd8d92a4d62 100644 --- a/core/dbt/cli/main.py +++ b/core/dbt/cli/main.py @@ -61,8 +61,8 @@ class dbtRunnerResult: class dbtRunner: def __init__( self, - manifest: Manifest = None, - callbacks: List[Callable[[EventMsg], None]] = None, + manifest: Optional[Manifest] = None, + callbacks: Optional[List[Callable[[EventMsg], None]]] = None, ): self.manifest = manifest diff --git a/core/dbt/context/configured.py b/core/dbt/context/configured.py index ddbfb60e91b..bb292a19565 100644 --- a/core/dbt/context/configured.py +++ b/core/dbt/context/configured.py @@ -119,7 +119,9 @@ def var(self) -> ConfiguredVar: def generate_schema_yml_context( - config: AdapterRequiredConfig, project_name: str, schema_yaml_vars: SchemaYamlVars = None + config: AdapterRequiredConfig, + project_name: str, + schema_yaml_vars: Optional[SchemaYamlVars] = None, ) -> Dict[str, Any]: ctx = SchemaYamlContext(config, project_name, schema_yaml_vars) return ctx.to_dict() diff --git a/core/dbt/context/context_config.py b/core/dbt/context/context_config.py index b497887ab45..437b47eb4b3 100644 --- a/core/dbt/context/context_config.py +++ b/core/dbt/context/context_config.py @@ -1,7 +1,7 @@ from abc import abstractmethod from copy import deepcopy from dataclasses import dataclass -from typing import List, Iterator, Dict, Any, TypeVar, Generic +from typing import List, Iterator, Dict, Any, TypeVar, Generic, Optional from dbt.config import RuntimeConfig, Project, IsFQNResource from dbt.contracts.graph.model_config import BaseConfig, get_config_for, _listify @@ -130,7 +130,7 @@ def calculate_node_config( resource_type: NodeType, project_name: str, base: bool, - patch_config_dict: Dict[str, Any] = None, + patch_config_dict: Optional[Dict[str, Any]] = None, ) -> BaseConfig: own_config = self.get_node_project(project_name) @@ -166,7 +166,7 @@ def calculate_node_config_dict( resource_type: NodeType, project_name: str, base: bool, - patch_config_dict: Dict[str, Any], + patch_config_dict: Optional[Dict[str, Any]] = None, ) -> Dict[str, Any]: ... @@ -200,7 +200,7 @@ def calculate_node_config_dict( resource_type: NodeType, project_name: str, base: bool, - patch_config_dict: dict = None, + patch_config_dict: Optional[dict] = None, ) -> Dict[str, Any]: config = self.calculate_node_config( config_call_dict=config_call_dict, @@ -225,7 +225,7 @@ def calculate_node_config_dict( resource_type: NodeType, project_name: str, base: bool, - patch_config_dict: dict = None, + patch_config_dict: Optional[dict] = None, ) -> Dict[str, Any]: # TODO CT-211 return self.calculate_node_config( @@ -318,7 +318,11 @@ def _add_config_call(cls, config_call_dict, opts: Dict[str, Any]) -> None: config_call_dict[k] = v def build_config_dict( - self, base: bool = False, *, rendered: bool = True, patch_config_dict: dict = None + self, + base: bool = False, + *, + rendered: bool = True, + patch_config_dict: Optional[dict] = None, ) -> Dict[str, Any]: if rendered: # TODO CT-211 diff --git a/core/dbt/context/providers.py b/core/dbt/context/providers.py index c4df007e806..e4bc2cde06a 100644 --- a/core/dbt/context/providers.py +++ b/core/dbt/context/providers.py @@ -285,6 +285,7 @@ def __call__(self, *args: str) -> RelationProxy: class BaseMetricResolver(BaseResolver): + @abc.abstractmethod def resolve(self, name: str, package: Optional[str] = None) -> MetricReference: ... diff --git a/core/dbt/events/base_types.py b/core/dbt/events/base_types.py index 94083c6dcb7..711a0bfad72 100644 --- a/core/dbt/events/base_types.py +++ b/core/dbt/events/base_types.py @@ -6,6 +6,7 @@ from google.protobuf.json_format import ParseDict, MessageToDict, MessageToJson from google.protobuf.message import Message from dbt.events.helpers import get_json_string_utcnow +from typing import Optional if sys.version_info >= (3, 8): from typing import Protocol @@ -126,7 +127,7 @@ class EventMsg(Protocol): data: Message -def msg_from_base_event(event: BaseEvent, level: EventLevel = None): +def msg_from_base_event(event: BaseEvent, level: Optional[EventLevel] = None): msg_class_name = f"{type(event).__name__}Msg" msg_cls = getattr(types_pb2, msg_class_name) diff --git a/core/dbt/events/eventmgr.py b/core/dbt/events/eventmgr.py index 03d490d5ab8..55dfbd203f0 100644 --- a/core/dbt/events/eventmgr.py +++ b/core/dbt/events/eventmgr.py @@ -185,7 +185,7 @@ def __init__(self) -> None: self.callbacks: List[Callable[[EventMsg], None]] = [] self.invocation_id: str = str(uuid4()) - def fire_event(self, e: BaseEvent, level: EventLevel = None) -> None: + def fire_event(self, e: BaseEvent, level: Optional[EventLevel] = None) -> None: msg = msg_from_base_event(e, level=level) if os.environ.get("DBT_TEST_BINARY_SERIALIZATION"): diff --git a/core/dbt/events/functions.py b/core/dbt/events/functions.py index a56fb24006a..21bc4d3c0b3 100644 --- a/core/dbt/events/functions.py +++ b/core/dbt/events/functions.py @@ -247,14 +247,16 @@ def warn_or_error(event, node=None): # an alternative to fire_event which only creates and logs the event value # if the condition is met. Does nothing otherwise. def fire_event_if( - conditional: bool, lazy_e: Callable[[], BaseEvent], level: EventLevel = None + conditional: bool, lazy_e: Callable[[], BaseEvent], level: Optional[EventLevel] = None ) -> None: if conditional: fire_event(lazy_e(), level=level) # a special case of fire_event_if, to only fire events in our unit/functional tests -def fire_event_if_test(lazy_e: Callable[[], BaseEvent], level: EventLevel = None) -> None: +def fire_event_if_test( + lazy_e: Callable[[], BaseEvent], level: Optional[EventLevel] = None +) -> None: fire_event_if(conditional=("pytest" in sys.modules), lazy_e=lazy_e, level=level) @@ -262,7 +264,7 @@ def fire_event_if_test(lazy_e: Callable[[], BaseEvent], level: EventLevel = None # this is where all the side effects happen branched by event type # (i.e. - mutating the event history, printing to stdout, logging # to files, etc.) -def fire_event(e: BaseEvent, level: EventLevel = None) -> None: +def fire_event(e: BaseEvent, level: Optional[EventLevel] = None) -> None: EVENT_MANAGER.fire_event(e, level=level) diff --git a/core/dbt/exceptions.py b/core/dbt/exceptions.py index b336776761d..21ed6c10720 100644 --- a/core/dbt/exceptions.py +++ b/core/dbt/exceptions.py @@ -419,7 +419,7 @@ def message(self): class SemverError(Exception): - def __init__(self, msg: str = None): + def __init__(self, msg: Optional[str] = None): self.msg = msg if msg is not None: super().__init__(msg) @@ -2419,7 +2419,7 @@ class RPCCompiling(DbtRuntimeError): CODE = 10010 MESSAGE = 'RPC server is compiling the project, call the "status" method for' " compile status" - def __init__(self, msg: str = None, node=None): + def __init__(self, msg: Optional[str] = None, node=None): if msg is None: msg = "compile in progress" super().__init__(msg, node) diff --git a/core/dbt/logger.py b/core/dbt/logger.py index 81e0e8871e7..d4095fb73bf 100644 --- a/core/dbt/logger.py +++ b/core/dbt/logger.py @@ -469,7 +469,7 @@ class ListLogHandler(LogMessageHandler): def __init__( self, level: int = logbook.NOTSET, - filter: Callable = None, + filter: Optional[Callable] = None, bubble: bool = False, lst: Optional[List[LogMessage]] = None, ) -> None: diff --git a/core/dbt/parser/generic_test_builders.py b/core/dbt/parser/generic_test_builders.py index 847f2b29f3c..69c86853162 100644 --- a/core/dbt/parser/generic_test_builders.py +++ b/core/dbt/parser/generic_test_builders.py @@ -113,7 +113,7 @@ def __init__( target: Testable, package_name: str, render_ctx: Dict[str, Any], - column_name: str = None, + column_name: Optional[str] = None, version: Optional[NodeVersion] = None, ) -> None: test_name, test_args = self.extract_test_args(test, column_name) diff --git a/core/dbt/parser/schema_generic_tests.py b/core/dbt/parser/schema_generic_tests.py index 590f946bbc7..29b71c21e92 100644 --- a/core/dbt/parser/schema_generic_tests.py +++ b/core/dbt/parser/schema_generic_tests.py @@ -61,7 +61,7 @@ def resource_type(self) -> NodeType: def get_compiled_path(cls, block: FileBlock) -> str: return block.path.relative_path - def parse_file(self, block: FileBlock, dct: Dict = None) -> None: + def parse_file(self, block: FileBlock, dct: Optional[Dict] = None) -> None: pass def parse_from_dict(self, dct, validate=True) -> GenericTestNode: diff --git a/core/dbt/parser/schemas.py b/core/dbt/parser/schemas.py index adf29b2a091..233b1da950c 100644 --- a/core/dbt/parser/schemas.py +++ b/core/dbt/parser/schemas.py @@ -147,7 +147,7 @@ def get_compiled_path(cls, block: FileBlock) -> str: def resource_type(self) -> NodeType: return NodeType.Test - def parse_file(self, block: FileBlock, dct: Dict = None) -> None: + def parse_file(self, block: FileBlock, dct: Optional[Dict] = None) -> None: assert isinstance(block.file, SchemaSourceFile) # If partially parsing, dct should be from pp_dict, otherwise diff --git a/core/dbt/task/runnable.py b/core/dbt/task/runnable.py index e3de59df771..b1a74fd1126 100644 --- a/core/dbt/task/runnable.py +++ b/core/dbt/task/runnable.py @@ -381,7 +381,9 @@ def _mark_dependent_errors(self, node_id, result, cause): for dep_node_id in self.graph.get_dependent_nodes(node_id): self._skipped_children[dep_node_id] = cause - def populate_adapter_cache(self, adapter, required_schemas: Set[BaseRelation] = None): + def populate_adapter_cache( + self, adapter, required_schemas: Optional[Set[BaseRelation]] = None + ): if not self.args.populate_cache: return diff --git a/core/dbt/tests/util.py b/core/dbt/tests/util.py index f770c8a28e9..e901d8b9d82 100644 --- a/core/dbt/tests/util.py +++ b/core/dbt/tests/util.py @@ -5,7 +5,7 @@ import json import warnings from datetime import datetime -from typing import Dict, List +from typing import Dict, List, Optional from contextlib import contextmanager from dbt.adapters.factory import Adapter @@ -71,9 +71,9 @@ # If the command is expected to fail, pass in "expect_pass=False"): # run_dbt("test"], expect_pass=False) def run_dbt( - args: List[str] = None, + args: Optional[List[str]] = None, expect_pass: bool = True, - publications: List[PublicationArtifact] = None, + publications: Optional[List[PublicationArtifact]] = None, ): # Ignore logbook warnings warnings.filterwarnings("ignore", category=DeprecationWarning, module="logbook") @@ -117,9 +117,9 @@ def run_dbt( # start with the "--debug" flag. The structured schema log CI test # will turn the logs into json, so you have to be prepared for that. def run_dbt_and_capture( - args: List[str] = None, + args: Optional[List[str]] = None, expect_pass: bool = True, - publications: List[PublicationArtifact] = None, + publications: Optional[List[PublicationArtifact]] = None, ): try: stringbuf = StringIO() diff --git a/dev-requirements.txt b/dev-requirements.txt index 033d798205b..2f1ed983f19 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -5,7 +5,7 @@ flake8 flaky freezegun==0.3.12 ipdb -mypy==0.981 +mypy==1.3.0 pip-tools pre-commit protobuf>=4.0.0