Skip to content

Commit

Permalink
Get running with Python 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jtcohen6 committed Oct 29, 2022
1 parent 35f7975 commit 48e6f96
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
14 changes: 8 additions & 6 deletions core/dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Hashable
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Optional, TypeVar, Any, Type, Dict, Union, Iterator, Tuple, Set

from dbt.contracts.graph.compiled import CompiledNode
Expand Down Expand Up @@ -27,8 +27,10 @@ class BaseRelation(FakeAPIObject, Hashable):
path: Path
type: Optional[RelationType] = None
quote_character: str = '"'
include_policy: Policy = Policy()
quote_policy: Policy = Policy()
# Python 3.11 requires that these use default_factory instead of simple default
# ValueError: mutable default <class 'dbt.contracts.relation.Policy'> for field include_policy is not allowed: use default_factory
include_policy: Policy = field(default_factory=Policy)
quote_policy: Policy = field(default_factory=Policy)
dbt_created: bool = False

def _is_exactish_match(self, field: ComponentName, value: str) -> bool:
Expand All @@ -52,11 +54,11 @@ def __eq__(self, other):

@classmethod
def get_default_quote_policy(cls) -> Policy:
return cls._get_field_named("quote_policy").default
return cls._get_field_named("quote_policy").default_factory

@classmethod
def get_default_include_policy(cls) -> Policy:
return cls._get_field_named("include_policy").default
return cls._get_field_named("include_policy").default_factory

def get(self, key, default=None):
"""Override `.get` to return a metadata object so we don't break
Expand Down Expand Up @@ -188,7 +190,7 @@ def create_from_source(cls: Type[Self], source: ParsedSourceDefinition, **kwargs
source_quoting = source.quoting.to_dict(omit_none=True)
source_quoting.pop("column", None)
quote_policy = deep_merge(
cls.get_default_quote_policy().to_dict(omit_none=True),
cls.get_default_quote_policy()().to_dict(omit_none=True), # mypy doesn't like this
source_quoting,
kwargs.get("quote_policy", {}),
)
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/config/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def from_parts(
"""
quoting: Dict[str, Any] = (
get_relation_class_by_name(profile.credentials.type)
.get_default_quote_policy()
.get_default_quote_policy()() # mypy doesn't like this
.replace_dict(_project_quoting_dict(project, profile))
).to_dict(omit_none=True)

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 @@ -218,7 +218,7 @@ class Project(HyphenatedDbtClassMixin, Replaceable):
),
)
packages: List[PackageSpec] = field(default_factory=list)
query_comment: Optional[Union[QueryComment, NoValue, str]] = NoValue()
query_comment: Optional[Union[QueryComment, NoValue, str]] = field(default_factory=NoValue)

@classmethod
def validate(cls, data):
Expand Down
7 changes: 5 additions & 2 deletions core/dbt/helper_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# necessary for annotating constructors
from __future__ import annotations

from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import timedelta
from pathlib import Path
from typing import Tuple, AbstractSet, Union
Expand Down Expand Up @@ -80,12 +80,15 @@ class NVEnum(StrEnum):
def __eq__(self, other):
return isinstance(other, NVEnum)

def __call__(self):
return self.novalue


@dataclass
class NoValue(dbtClassMixin):
"""Sometimes, you want a way to say none that isn't None"""

novalue: NVEnum = NVEnum.novalue
novalue: NVEnum = field(default_factory=NVEnum.novalue)


dbtClassMixin.register_field_encoders(
Expand Down
3 changes: 2 additions & 1 deletion core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"hologram>=0.0.14,<=0.0.15",
"isodate>=0.6,<0.7",
"logbook>=1.5,<1.6",
"mashumaro[msgpack]==3.0.4",
"mashumaro[msgpack]==3.1",
"minimal-snowplow-tracker==0.0.2",
"networkx>=2.3,<2.8.1;python_version<'3.8'",
"networkx>=2.3,<3;python_version>='3.8'",
Expand All @@ -81,6 +81,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
python_requires=">=3.7.2",
)

0 comments on commit 48e6f96

Please sign in to comment.