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

[Tidy first] Add some mypy types to parser files #10380

Merged
merged 6 commits into from
Jul 8, 2024
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
3 changes: 1 addition & 2 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
ManifestNode,
Metric,
ModelNode,
ResultNode,
SavedQuery,
SeedNode,
SemanticModel,
Expand Down Expand Up @@ -1586,7 +1585,7 @@ def add_disabled_nofile(self, node: GraphMemberNode):
else:
self.disabled[node.unique_id] = [node]

def add_disabled(self, source_file: AnySourceFile, node: ResultNode, test_from=None):
def add_disabled(self, source_file: AnySourceFile, node: GraphMemberNode, test_from=None):
self.add_disabled_nofile(node)
if isinstance(source_file, SchemaSourceFile):
if isinstance(node, GenericTestNode):
Expand Down
12 changes: 6 additions & 6 deletions core/dbt/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dbt.adapters.factory import get_adapter # noqa: F401
from dbt.artifacts.resources import Contract
from dbt.clients.jinja import MacroGenerator, get_rendered
from dbt.config import Project, RuntimeConfig
from dbt.config import RuntimeConfig
from dbt.context.context_config import ContextConfig
from dbt.context.providers import (
generate_generate_name_macro_context,
Expand Down Expand Up @@ -39,9 +39,9 @@


class BaseParser(Generic[FinalValue]):
def __init__(self, project: Project, manifest: Manifest) -> None:
self.project = project
self.manifest = manifest
def __init__(self, project: RuntimeConfig, manifest: Manifest) -> None:
self.project: RuntimeConfig = project
self.manifest: Manifest = manifest

@abc.abstractmethod
def parse_file(self, block: FileBlock) -> None:
Expand All @@ -63,7 +63,7 @@ def generate_unique_id(self, resource_name: str, hash: Optional[str] = None) ->
class Parser(BaseParser[FinalValue], Generic[FinalValue]):
def __init__(
self,
project: Project,
project: RuntimeConfig,
manifest: Manifest,
root_project: RuntimeConfig,
) -> None:
Expand Down Expand Up @@ -121,7 +121,7 @@ class ConfiguredParser(
):
def __init__(
self,
project: Project,
project: RuntimeConfig,
manifest: Manifest,
root_project: RuntimeConfig,
) -> None:
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ class ManifestLoader:
def __init__(
self,
root_project: RuntimeConfig,
all_projects: Mapping[str, Project],
all_projects: Mapping[str, RuntimeConfig],
macro_hook: Optional[Callable[[Manifest], Any]] = None,
file_diff: Optional[FileDiff] = None,
) -> None:
self.root_project: RuntimeConfig = root_project
self.all_projects: Mapping[str, Project] = all_projects
self.all_projects: Mapping[str, RuntimeConfig] = all_projects
self.file_diff = file_diff
self.manifest: Manifest = Manifest()
self.new_manifest = self.manifest
Expand Down Expand Up @@ -669,7 +669,7 @@ def load_and_parse_macros(self, project_parser_files):
# 'parser_types'
def parse_project(
self,
project: Project,
project: RuntimeConfig,
parser_files,
parser_types: List[Type[Parser]],
) -> None:
Expand Down
20 changes: 13 additions & 7 deletions core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
generate_parse_exposure,
generate_parse_semantic_models,
)
from dbt.contracts.files import SchemaSourceFile
from dbt.contracts.graph.nodes import Exposure, Group, Metric, SavedQuery, SemanticModel
from dbt.contracts.graph.unparsed import (
UnparsedConversionTypeParams,
Expand Down Expand Up @@ -83,7 +84,7 @@ def __init__(self, schema_parser: SchemaParser, yaml: YamlBlock) -> None:
self.schema_parser = schema_parser
self.yaml = yaml

def parse_exposure(self, unparsed: UnparsedExposure):
def parse_exposure(self, unparsed: UnparsedExposure) -> None:
package_name = self.project.project_name
unique_id = f"{NodeType.Exposure}.{package_name}.{unparsed.name}"
path = self.yaml.path.relative_path
Expand Down Expand Up @@ -141,6 +142,7 @@ def parse_exposure(self, unparsed: UnparsedExposure):
get_rendered(depends_on_jinja, ctx, parsed, capture_macros=True)
# parsed now has a populated refs/sources/metrics

assert isinstance(self.yaml.file, SchemaSourceFile)
if parsed.config.enabled:
self.manifest.add_exposure(self.yaml.file, parsed)
else:
Expand Down Expand Up @@ -169,7 +171,7 @@ def _generate_exposure_config(
patch_config_dict=precedence_configs,
)

def parse(self):
def parse(self) -> None:
for data in self.get_key_dicts():
try:
UnparsedExposure.validate(data)
Expand Down Expand Up @@ -335,7 +337,7 @@ def _get_metric_type_params(self, type_params: UnparsedMetricTypeParams) -> Metr
# input_measures=?,
)

def parse_metric(self, unparsed: UnparsedMetric, generated: bool = False):
def parse_metric(self, unparsed: UnparsedMetric, generated: bool = False) -> None:
package_name = self.project.project_name
unique_id = f"{NodeType.Metric}.{package_name}.{unparsed.name}"
path = self.yaml.path.relative_path
Expand Down Expand Up @@ -390,6 +392,7 @@ def parse_metric(self, unparsed: UnparsedMetric, generated: bool = False):
)

# if the metric is disabled we do not want it included in the manifest, only in the disabled dict
assert isinstance(self.yaml.file, SchemaSourceFile)
if parsed.config.enabled:
self.manifest.add_metric(self.yaml.file, parsed, generated)
else:
Expand Down Expand Up @@ -419,7 +422,7 @@ def _generate_metric_config(
)
return config

def parse(self):
def parse(self) -> None:
for data in self.get_key_dicts():
try:
UnparsedMetric.validate(data)
Expand All @@ -436,7 +439,7 @@ def __init__(self, schema_parser: SchemaParser, yaml: YamlBlock) -> None:
self.schema_parser = schema_parser
self.yaml = yaml

def parse_group(self, unparsed: UnparsedGroup):
def parse_group(self, unparsed: UnparsedGroup) -> None:
package_name = self.project.project_name
unique_id = f"{NodeType.Group}.{package_name}.{unparsed.name}"
path = self.yaml.path.relative_path
Expand All @@ -451,6 +454,7 @@ def parse_group(self, unparsed: UnparsedGroup):
owner=unparsed.owner,
)

assert isinstance(self.yaml.file, SchemaSourceFile)
self.manifest.add_group(self.yaml.file, parsed)

def parse(self):
Expand Down Expand Up @@ -583,7 +587,7 @@ def _generate_semantic_model_config(

return config

def parse_semantic_model(self, unparsed: UnparsedSemanticModel):
def parse_semantic_model(self, unparsed: UnparsedSemanticModel) -> None:
package_name = self.project.project_name
unique_id = f"{NodeType.SemanticModel}.{package_name}.{unparsed.name}"
path = self.yaml.path.relative_path
Expand Down Expand Up @@ -643,6 +647,7 @@ def parse_semantic_model(self, unparsed: UnparsedSemanticModel):

# if the semantic model is disabled we do not want it included in the manifest,
# only in the disabled dict
assert isinstance(self.yaml.file, SchemaSourceFile)
if parsed.config.enabled:
self.manifest.add_semantic_model(self.yaml.file, parsed)
else:
Expand All @@ -653,7 +658,7 @@ def parse_semantic_model(self, unparsed: UnparsedSemanticModel):
if measure.create_metric is True:
self._create_metric(measure=measure, enabled=parsed.config.enabled)

def parse(self):
def parse(self) -> None:
for data in self.get_key_dicts():
try:
UnparsedSemanticModel.validate(data)
Expand Down Expand Up @@ -779,6 +784,7 @@ def parse_saved_query(self, unparsed: UnparsedSavedQuery) -> None:
delattr(export, "relation_name")

# Only add thes saved query if it's enabled, otherwise we track it with other diabled nodes
assert isinstance(self.yaml.file, SchemaSourceFile)
if parsed.config.enabled:
self.manifest.add_saved_query(self.yaml.file, parsed)
else:
Expand Down
Loading
Loading