Skip to content
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

upgrade mypy to latest #4486

Closed
wants to merge 8 commits into from
Closed
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
14 changes: 7 additions & 7 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

import agate
import pytz
import pytz # type: ignore[import]

from dbt.exceptions import (
raise_database_error, raise_compiler_error, invalid_type_error,
Expand Down Expand Up @@ -275,8 +275,8 @@ def load_macro_manifest(self) -> MacroManifest:
manifest = ManifestLoader.load_macros(
self.config, self.connections.set_query_header
)
self._macro_manifest_lazy = manifest
return self._macro_manifest_lazy
self._macro_manifest_lazy = manifest # type: ignore[assignment]
return self._macro_manifest_lazy # type: ignore[return-value]

def clear_macro_manifest(self):
if self._macro_manifest_lazy is not None:
Expand Down Expand Up @@ -959,10 +959,10 @@ def execute_macro(
if context_override is None:
context_override = {}

if manifest is None:
manifest = self._macro_manifest
# manifest has type Optional[Manifest]. working_manifest is not optional.
working_manifest: Union[Manifest, MacroManifest] = manifest or self._macro_manifest

macro = manifest.find_macro_by_name(
macro = working_manifest.find_macro_by_name(
macro_name, self.config.project_name, project
)
if macro is None:
Expand All @@ -981,7 +981,7 @@ def execute_macro(
macro_context = generate_runtime_macro_context(
macro=macro,
config=self.config,
manifest=manifest,
manifest=working_manifest, # type: ignore[arg-type]
package_name=project
)
macro_context.update(context_override)
Expand Down
7 changes: 5 additions & 2 deletions core/dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ def matches(
if not self._is_exactish_match(k, v):
exact_match = False

if (
self.path.get_lowered_part(k).strip(self.quote_character) !=
lowered_part: Optional[str] = self.path.get_lowered_part(k)
if lowered_part is None:
approximate_match = False
elif (
lowered_part.strip(self.quote_character) !=
v.lower().strip(self.quote_character)
):
approximate_match = False
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/adapters/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def compile_node(
Compiler_T = TypeVar('Compiler_T', bound=CompilerProtocol)


class AdapterProtocol(
class AdapterProtocol( # type: ignore[misc]
Protocol,
Generic[
AdapterConfig_T,
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/adapters/sql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ def get_response(cls, cursor: Any) -> Union[AdapterResponse, str]:
@classmethod
def process_results(
cls,
column_names: Iterable[str],
column_names: List[str],
rows: Iterable[Any]
) -> List[Dict[str, Any]]:
unique_col_names = dict()
unique_col_names: Dict[str, int] = dict()
for idx in range(len(column_names)):
col_name = column_names[idx]
if col_name in unique_col_names:
unique_col_names[col_name] += 1
column_names[idx] = f'{col_name}_{unique_col_names[col_name]}'
else:
unique_col_names[column_names[idx]] = 1
unique_col_names[col_name] = 1
return [dict(zip(column_names, row)) for row in rows]

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/adapters/sql/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def convert_text_type(cls, agate_table: agate.Table, col_idx: int) -> str:
def convert_number_type(
cls, agate_table: agate.Table, col_idx: int
) -> str:
decimals = agate_table.aggregate(agate.MaxPrecision(col_idx))
decimals = agate_table.aggregate(agate.MaxPrecision(col_idx)) # type: ignore[attr-defined]
return "float8" if decimals else "integer"

@classmethod
Expand Down
12 changes: 6 additions & 6 deletions core/dbt/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
Callable
)

import jinja2
import jinja2.ext
import jinja2.nativetypes # type: ignore
import jinja2.nodes
import jinja2.parser
import jinja2.sandbox
import jinja2 # type: ignore[import]
import jinja2.ext # type: ignore[import]
import jinja2.nativetypes # type: ignore[import]
import jinja2.nodes # type: ignore[import]
import jinja2.parser # type: ignore[import]
import jinja2.sandbox # type: ignore[import]

from dbt.utils import (
get_dbt_macro_name, get_docs_macro_name, get_materialization_macro_name,
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/clients/jinja_static.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jinja2
import jinja2 # type: ignore[import]
from dbt.clients.jinja import get_environment
from dbt.exceptions import raise_compiler_error

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/clients/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import functools
import requests
import requests # type: ignore[import]
from dbt.events.functions import fire_event
from dbt.events.types import (
RegistryProgressMakingGETRequest,
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/clients/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import subprocess
import sys
import tarfile
import requests
import requests # type: ignore[import]
import stat
from typing import (
Type, NoReturn, List, Optional, Dict, Any, Tuple, Callable, Union
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/clients/yaml_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dbt.exceptions
from typing import Any, Dict, Optional
import yaml
import yaml # type: ignore[import]

# the C version is faster, but it doesn't always exist
try:
Expand Down
Empty file added core/dbt/context/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions core/dbt/context/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# These modules are added to the context. Consider alternative
# approaches which will extend well to potentially many modules
import pytz
import pytz # type: ignore[import]
import datetime
import re

Expand Down Expand Up @@ -82,7 +82,7 @@ def get_datetime_module_context() -> Dict[str, Any]:


def get_re_module_context() -> Dict[str, Any]:
context_exports = re.__all__
context_exports = re.__all__ # type: ignore[attr-defined]

return {
name: getattr(re, name) for name in context_exports
Expand Down
8 changes: 4 additions & 4 deletions core/dbt/context/context_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def calculate_node_config(
result = self._update_from_config(result, fqn_config)

# this is mostly impactful in the snapshot config case
return result
return result # type: ignore[return-value]

@abstractmethod
def calculate_node_config_dict(
Expand Down Expand Up @@ -227,7 +227,7 @@ def calculate_node_config_dict(
base: bool,
patch_config_dict: dict = None
) -> Dict[str, Any]:
return self.calculate_node_config(
return self.calculate_node_config( # type: ignore[return-value]
config_call_dict=config_call_dict,
fqn=fqn,
resource_type=resource_type,
Expand Down Expand Up @@ -299,9 +299,9 @@ def build_config_dict(
patch_config_dict: dict = None
) -> Dict[str, Any]:
if rendered:
src = ContextConfigGenerator(self._active_project)
src = ContextConfigGenerator(self._active_project) # type: ignore[var-annotated]
else:
src = UnrenderedConfigGenerator(self._active_project)
src = UnrenderedConfigGenerator(self._active_project) # type: ignore[assignment]

return src.calculate_node_config_dict(
config_call_dict=self._config_call_dict,
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/context/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def doc(self, *args: str) -> str:
file_id = target_doc.file_id
if file_id in self.manifest.files:
source_file = self.manifest.files[file_id]
source_file.add_node(self.node.unique_id)
source_file.add_node(self.node.unique_id) # type: ignore[union-attr]
else:
doc_target_not_found(self.node, doc_name, doc_package_name)

Expand Down
8 changes: 4 additions & 4 deletions core/dbt/context/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def __init__(
self.global_project_namespace: FlatNamespace = global_project_namespace

def _search_order(self) -> Iterable[Union[FullNamespace, FlatNamespace]]:
yield self.local_namespace # local package
yield self.global_namespace # root package
yield self.packages # non-internal packages
yield {
yield self.local_namespace # local package
yield self.global_namespace # type: ignore[misc] # root package
yield self.packages # type: ignore[misc] # non-internal packages
yield { # type: ignore[misc]
GLOBAL_PROJECT_NAME: self.global_project_namespace, # dbt
}
yield self.global_project_namespace # other internal project besides dbt
Expand Down
22 changes: 15 additions & 7 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .macros import MacroNamespaceBuilder, MacroNamespace
from .manifest import ManifestContext
from dbt.contracts.connection import AdapterResponse
from dbt.contracts.files import SchemaSourceFile
from dbt.contracts.graph.manifest import (
Manifest, Disabled
)
Expand Down Expand Up @@ -1189,7 +1190,7 @@ def env_var(self, var: str, default: Optional[str] = None) -> str:
source_file = self.manifest.files[self.model.file_id]
# Schema files should never get here
if source_file.parse_file_type != 'schema':
source_file.env_vars.append(var)
source_file.env_vars.append(var) # type: ignore[union-attr]
return return_value
else:
msg = f"Env var required but not provided: '{var}'"
Expand Down Expand Up @@ -1230,21 +1231,23 @@ def pre_hooks(self) -> List[Dict[str, Any]]:
if self.model.resource_type in [NodeType.Source, NodeType.Test]:
return []
return [
h.to_dict(omit_none=True) for h in self.model.config.pre_hook
h.to_dict(omit_none=True)
for h in self.model.config.pre_hook # type: ignore[union-attr]
]

@contextproperty
def post_hooks(self) -> List[Dict[str, Any]]:
if self.model.resource_type in [NodeType.Source, NodeType.Test]:
return []
return [
h.to_dict(omit_none=True) for h in self.model.config.post_hook
h.to_dict(omit_none=True)
for h in self.model.config.post_hook # type: ignore[union-attr]
]

@contextproperty
def sql(self) -> Optional[str]:
if getattr(self.model, 'extra_ctes_injected', None):
return self.model.compiled_sql
return self.model.compiled_sql # type: ignore[union-attr]
return None

@contextproperty
Expand Down Expand Up @@ -1495,9 +1498,14 @@ def env_var(self, var: str, default: Optional[str] = None) -> str:
if self.model:
self.manifest.env_vars[var] = return_value
# the "model" should only be test nodes, but just in case, check
if self.model.resource_type == NodeType.Test and self.model.file_key_name:
source_file = self.manifest.files[self.model.file_id]
(yaml_key, name) = self.model.file_key_name.split('.')
if (
self.model.resource_type ==
NodeType.Test and self.model.file_key_name # type: ignore[union-attr]
):
source_file: SchemaSourceFile = \
self.manifest.files[self.model.file_id] # type: ignore[assignment]
(yaml_key, name) = \
self.model.file_key_name.split('.') # type: ignore[union-attr]
source_file.add_env_var(var, yaml_key, name)
return return_value
else:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_revisions(self) -> List[str]:
class RegistryPackage(Package):
package: str
version: Union[RawVersion, List[RawVersion]]
install_prerelease: Optional[bool] = False
install_prerelease: bool = False

def get_versions(self) -> List[str]:
if isinstance(self.version, list):
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/dataclass_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import fields
from enum import Enum
from datetime import datetime
from dateutil.parser import parse
from dateutil.parser import parse # type: ignore[import]

from hologram import JsonSchemaMixin, FieldEncoder, ValidationError

Expand Down
Empty file added core/dbt/deps/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion core/dbt/parser/generic_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Iterable, List

import jinja2
import jinja2 # type: ignore[import]

from dbt.exceptions import ParsingException
from dbt.clients import jinja
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/macros.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Iterable, List

import jinja2
import jinja2 # type: ignore[import]

from dbt.clients import jinja
from dbt.contracts.graph.unparsed import UnparsedMacro
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/task/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import shutil
from typing import Optional

import yaml
import yaml # type: ignore[import]
import click

import dbt.config
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from datetime import datetime

import logbook
import pytz
import pytz # type: ignore[import]
import platform
import uuid
import requests
import requests # type: ignore[import]
import os

sp_logger.setLevel(100)
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import functools
import hashlib
import itertools
import jinja2
import jinja2 # type: ignore[import]
import json
import os
import requests
import requests # type: ignore[import]
import time

from contextlib import contextmanager
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
from typing import Iterator

import requests
import requests # type: ignore[import]

import dbt.exceptions
import dbt.semver
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ flake8
flaky
freezegun==0.3.12
ipdb
mypy==0.782
mypy==0.910
pip-tools
pytest
pytest-dotenv
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ deps =
description = mypy static type checking
basepython = python3.8
skip_install = true
commands = mypy core/dbt
commands = mypy --show-error-codes core/dbt
deps =
-rdev-requirements.txt
-reditable-requirements.txt
Expand Down