Skip to content

Commit

Permalink
fixing types
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoop committed Jan 12, 2024
1 parent caaf604 commit 4ddbdcd
Show file tree
Hide file tree
Showing 37 changed files with 1,117 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dbt_common/exceptions/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def get_message(self) -> str:
message_addendum = ""

msg = (
f"in rename, new key {self.new_key} already in ",
f"cache: {list(self.relations.keys())}{message_addendum}",
f"in rename, new key {self.new_key} already in "
f"cache: {list(self.relations.keys())}{message_addendum}"
)

return msg
Expand Down
4 changes: 2 additions & 2 deletions dbt_common/exceptions/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def __init__(self, block_type_name: str, linecount: int) -> None:

def get_message(self) -> str:
msg = (
"Reached EOF without finding a close tag for ",
f"{self.block_type_name} (searched from line {self.linecount})",
"Reached EOF without finding a close tag for "
f"{self.block_type_name} (searched from line {self.linecount})"
)
return msg

Expand Down
4 changes: 2 additions & 2 deletions dbt_common/exceptions/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def __init__(self, freshness_macro_name: str, table):

def get_message(self) -> str:
msg = (
f'Got an invalid result from "{self.freshness_macro_name}" ',
f"macro: {[tuple(r) for r in self.table]}",
f'Got an invalid result from "{self.freshness_macro_name}" '
f"macro: {[tuple(r) for r in self.table]}"
)

return msg
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ mypy_path = "third-party-stubs/"
namespace_packages = true
warn_unused_configs = true
show_error_codes = true
# disallow_untyped_defs = true # TODO: add type annotations everywhere
disable_error_code = "attr-defined" # TODO: revisit once other mypy errors resolved
disallow_untyped_defs = false # TODO: add type annotations everywhere
warn_redundant_casts = true

# Don't run the extensive mypy checks on custom stubs
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions third-party-stubs/mashumaro/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from mashumaro.exceptions import MissingField as MissingField
from mashumaro.helper import field_options as field_options, pass_through as pass_through
from mashumaro.mixins.dict import DataClassDictMixin as DataClassDictMixin
26 changes: 26 additions & 0 deletions third-party-stubs/mashumaro/config.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from mashumaro.core.const import Sentinel
from mashumaro.dialect import Dialect
from mashumaro.types import Discriminator, SerializationStrategy
from typing import Any, Callable, Dict, List, Optional, Type, Union
from typing_extensions import Literal

TO_DICT_ADD_BY_ALIAS_FLAG: str
TO_DICT_ADD_OMIT_NONE_FLAG: str
ADD_DIALECT_SUPPORT: str
ADD_SERIALIZATION_CONTEXT: str
SerializationStrategyValueType = Union[SerializationStrategy, Dict[str, Union[str, Callable]]]

class BaseConfig:
debug: bool
code_generation_options: List[str]
serialization_strategy: Dict[Any, SerializationStrategyValueType]
aliases: Dict[str, str]
serialize_by_alias: bool
namedtuple_as_dict: bool
allow_postponed_evaluation: bool
dialect: Optional[Type[Dialect]]
omit_none: Union[bool, Sentinel.MISSING]
orjson_options: Optional[int]
json_schema: Dict[str, Any]
discriminator: Optional[Discriminator]
lazy_compilation: bool
Empty file.
17 changes: 17 additions & 0 deletions third-party-stubs/mashumaro/core/const.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import enum
from _typeshed import Incomplete

PY_37: Incomplete
PY_38: Incomplete
PY_39: Incomplete
PY_310: Incomplete
PY_311_MIN: Incomplete
PY_310_MIN: Incomplete
PY_39_MIN: Incomplete
PY_38_MIN: Incomplete
PY_37_MIN: Incomplete
PEP_585_COMPATIBLE = PY_39_MIN
PEP_586_COMPATIBLE = PY_38_MIN

class Sentinel(enum.Enum):
MISSING: Incomplete
10 changes: 10 additions & 0 deletions third-party-stubs/mashumaro/core/helpers.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import datetime
from _typeshed import Incomplete

UTC_OFFSET_PATTERN: str

def parse_timezone(s: str) -> datetime.timezone: ...

class ConfigValue:
name: Incomplete
def __init__(self, name: str) -> None: ...
Empty file.
Empty file.
146 changes: 146 additions & 0 deletions third-party-stubs/mashumaro/core/meta/code/builder.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import types
import typing
from _typeshed import Incomplete
from collections.abc import Generator
from dataclasses import Field
from mashumaro.config import (
ADD_DIALECT_SUPPORT as ADD_DIALECT_SUPPORT,
ADD_SERIALIZATION_CONTEXT as ADD_SERIALIZATION_CONTEXT,
BaseConfig as BaseConfig,
SerializationStrategyValueType as SerializationStrategyValueType,
TO_DICT_ADD_BY_ALIAS_FLAG as TO_DICT_ADD_BY_ALIAS_FLAG,
TO_DICT_ADD_OMIT_NONE_FLAG as TO_DICT_ADD_OMIT_NONE_FLAG,
)
from mashumaro.core.const import Sentinel as Sentinel
from mashumaro.core.helpers import ConfigValue as ConfigValue
from mashumaro.core.meta.code.lines import CodeLines as CodeLines
from mashumaro.core.meta.helpers import (
get_args as get_args,
get_class_that_defines_field as get_class_that_defines_field,
get_class_that_defines_method as get_class_that_defines_method,
get_literal_values as get_literal_values,
get_name_error_name as get_name_error_name,
hash_type_args as hash_type_args,
is_class_var as is_class_var,
is_dataclass_dict_mixin as is_dataclass_dict_mixin,
is_dialect_subclass as is_dialect_subclass,
is_init_var as is_init_var,
is_literal as is_literal,
is_optional as is_optional,
is_type_var_any as is_type_var_any,
resolve_type_params as resolve_type_params,
substitute_type_params as substitute_type_params,
type_name as type_name,
)
from mashumaro.core.meta.types.common import FieldContext as FieldContext, ValueSpec as ValueSpec
from mashumaro.core.meta.types.pack import PackerRegistry as PackerRegistry
from mashumaro.core.meta.types.unpack import (
SubtypeUnpackerBuilder as SubtypeUnpackerBuilder,
UnpackerRegistry as UnpackerRegistry,
)
from mashumaro.dialect import Dialect as Dialect
from mashumaro.exceptions import (
BadDialect as BadDialect,
BadHookSignature as BadHookSignature,
InvalidFieldValue as InvalidFieldValue,
MissingDiscriminatorError as MissingDiscriminatorError,
MissingField as MissingField,
SuitableVariantNotFoundError as SuitableVariantNotFoundError,
ThirdPartyModuleNotFoundError as ThirdPartyModuleNotFoundError,
UnresolvedTypeReferenceError as UnresolvedTypeReferenceError,
UnserializableDataError as UnserializableDataError,
UnserializableField as UnserializableField,
UnsupportedDeserializationEngine as UnsupportedDeserializationEngine,
UnsupportedSerializationEngine as UnsupportedSerializationEngine,
)
from mashumaro.types import Discriminator as Discriminator

__PRE_SERIALIZE__: str
__PRE_DESERIALIZE__: str
__POST_SERIALIZE__: str
__POST_DESERIALIZE__: str

class CodeBuilder:
cls: Incomplete
lines: Incomplete
globals: Incomplete
resolved_type_params: Incomplete
field_classes: Incomplete
initial_type_args: Incomplete
dialect: Incomplete
default_dialect: Incomplete
allow_postponed_evaluation: Incomplete
format_name: Incomplete
decoder: Incomplete
encoder: Incomplete
encoder_kwargs: Incomplete
def __init__(
self,
cls: typing.Type,
type_args: typing.Tuple[typing.Type, ...] = ...,
dialect: typing.Optional[typing.Type[Dialect]] = ...,
first_method: str = ...,
allow_postponed_evaluation: bool = ...,
format_name: str = ...,
decoder: typing.Optional[typing.Any] = ...,
encoder: typing.Optional[typing.Any] = ...,
encoder_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = ...,
default_dialect: typing.Optional[typing.Type[Dialect]] = ...,
) -> None: ...
def reset(self) -> None: ...
@property
def namespace(self) -> typing.Mapping[typing.Any, typing.Any]: ...
@property
def annotations(self) -> typing.Dict[str, typing.Any]: ...
def get_field_resolved_type_params(
self, field_name: str
) -> typing.Dict[typing.Type, typing.Type]: ...
def get_field_types(self, include_extras: bool = ...) -> typing.Dict[str, typing.Any]: ...
@property
def dataclass_fields(self) -> typing.Dict[str, Field]: ...
@property
def metadatas(self) -> typing.Dict[str, typing.Mapping[str, typing.Any]]: ...
def get_field_default(self, name: str) -> typing.Any: ...
def add_type_modules(self, *types_: typing.Type) -> None: ...
def ensure_module_imported(self, module: types.ModuleType) -> None: ...
def ensure_object_imported(
self, obj: typing.Any, name: typing.Optional[str] = ...
) -> None: ...
def add_line(self, line: str) -> None: ...
def indent(self, expr: typing.Optional[str] = ...) -> typing.Generator[None, None, None]: ...
def compile(self) -> None: ...
def get_declared_hook(self, method_name: str) -> typing.Any: ...
def add_unpack_method(self) -> None: ...
def get_config(self, cls: Incomplete | None = ..., look_in_parents: bool = ...): ...
def get_discriminator(self) -> typing.Optional[Discriminator]: ...
def get_pack_method_flags(
self, cls: typing.Optional[typing.Type] = ..., pass_encoder: bool = ...
) -> str: ...
def get_unpack_method_flags(
self, cls: typing.Optional[typing.Type] = ..., pass_decoder: bool = ...
) -> str: ...
def get_pack_method_default_flag_values(
self, cls: typing.Optional[typing.Type] = ..., pass_encoder: bool = ...
) -> str: ...
def get_unpack_method_default_flag_values(self, pass_decoder: bool = ...) -> str: ...
def is_code_generation_option_enabled(
self, option: str, cls: typing.Optional[typing.Type] = ...
) -> bool: ...
@classmethod
def get_unpack_method_name(
cls,
type_args: typing.Iterable = ...,
format_name: str = ...,
decoder: typing.Optional[typing.Any] = ...,
) -> str: ...
@classmethod
def get_pack_method_name(
cls,
type_args: typing.Tuple[typing.Type, ...] = ...,
format_name: str = ...,
encoder: typing.Optional[typing.Any] = ...,
) -> str: ...
def add_pack_method(self) -> None: ...
def iter_serialization_strategies(
self, metadata, ftype
) -> Generator[Incomplete, None, None]: ...
8 changes: 8 additions & 0 deletions third-party-stubs/mashumaro/core/meta/code/lines.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Generator, Optional

class CodeLines:
def __init__(self) -> None: ...
def append(self, line: str) -> None: ...
def indent(self, expr: Optional[str] = ...) -> Generator[None, None, None]: ...
def as_text(self) -> str: ...
def reset(self) -> None: ...
58 changes: 58 additions & 0 deletions third-party-stubs/mashumaro/core/meta/helpers.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import typing
from typing import Any, Dict, Optional, Sequence, Tuple, Type

def get_type_origin(typ: Type) -> Type: ...
def get_generic_name(typ: Type, short: bool = ...) -> str: ...
def get_args(typ: Optional[Type]) -> Tuple[Type, ...]: ...
def get_literal_values(typ: Type) -> Tuple[Any, ...]: ...
def type_name(
typ: Optional[Type],
short: bool = ...,
resolved_type_params: Optional[Dict[Type, Type]] = ...,
is_type_origin: bool = ...,
none_type_as_none: bool = ...,
) -> str: ...
def is_special_typing_primitive(typ: Any) -> bool: ...
def is_generic(typ: Type) -> bool: ...
def is_typed_dict(typ: Type) -> bool: ...
def is_named_tuple(typ: Type) -> bool: ...
def is_new_type(typ: Type) -> bool: ...
def is_union(typ: Type) -> bool: ...
def is_optional(typ: Type, resolved_type_params: Optional[Dict[Type, Type]] = ...) -> bool: ...
def is_annotated(typ: Type) -> bool: ...
def get_type_annotations(typ: Type) -> Sequence[Any]: ...
def is_literal(typ: Type) -> bool: ...
def not_none_type_arg(
type_args: Tuple[Type, ...], resolved_type_params: Optional[Dict[Type, Type]] = ...
) -> Optional[Type]: ...
def is_type_var(typ: Type) -> bool: ...
def is_type_var_any(typ: Type) -> bool: ...
def is_class_var(typ: Type) -> bool: ...
def is_final(typ: Type) -> bool: ...
def is_init_var(typ: Type) -> bool: ...
def get_class_that_defines_method(method_name: str, cls: Type) -> Optional[Type]: ...
def get_class_that_defines_field(field_name: str, cls: Type) -> Optional[Type]: ...
def is_dataclass_dict_mixin(typ: Type) -> bool: ...
def is_dataclass_dict_mixin_subclass(typ: Type) -> bool: ...
def collect_type_params(typ: Type) -> Sequence[Type]: ...
def resolve_type_params(
typ: Type, type_args: Sequence[Type] = ..., include_bases: bool = ...
) -> Dict[Type, Dict[Type, Type]]: ...
def substitute_type_params(typ: Type, substitutions: Dict[Type, Type]) -> Type: ...
def get_name_error_name(e: NameError) -> str: ...
def is_dialect_subclass(typ: Type) -> bool: ...
def is_self(typ: Type) -> bool: ...
def is_required(typ: Type) -> bool: ...
def is_not_required(typ: Type) -> bool: ...
def get_function_arg_annotation(
function: typing.Callable[[Any], Any],
arg_name: typing.Optional[str] = ...,
arg_pos: typing.Optional[int] = ...,
) -> typing.Type: ...
def get_function_return_annotation(
function: typing.Callable[[typing.Any], typing.Any]
) -> typing.Type: ...
def is_unpack(typ: Type) -> bool: ...
def is_type_var_tuple(typ: Type) -> bool: ...
def hash_type_args(type_args: typing.Iterable[typing.Type]) -> str: ...
def iter_all_subclasses(cls) -> typing.Iterator[Type]: ...
13 changes: 13 additions & 0 deletions third-party-stubs/mashumaro/core/meta/mixin.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from mashumaro.dialect import Dialect
from typing import Any, Dict, Optional, Tuple, Type

def compile_mixin_packer(
cls,
format_name: str = ...,
dialect: Optional[Type[Dialect]] = ...,
encoder: Any = ...,
encoder_kwargs: Optional[Dict[str, Dict[str, Tuple[str, Any]]]] = ...,
) -> None: ...
def compile_mixin_unpacker(
cls, format_name: str = ..., dialect: Optional[Type[Dialect]] = ..., decoder: Any = ...
) -> None: ...
Empty file.
67 changes: 67 additions & 0 deletions third-party-stubs/mashumaro/core/meta/types/common.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from _typeshed import Incomplete
from functools import cached_property
from mashumaro.core.const import PEP_585_COMPATIBLE as PEP_585_COMPATIBLE
from mashumaro.core.meta.code.builder import CodeBuilder as CodeBuilder
from mashumaro.core.meta.helpers import (
get_type_origin as get_type_origin,
is_annotated as is_annotated,
is_generic as is_generic,
type_name as type_name,
)
from mashumaro.exceptions import (
UnserializableDataError as UnserializableDataError,
UnserializableField as UnserializableField,
)
from typing import Any, Dict, Mapping, Optional, Sequence, Type, TypeVar
from typing_extensions import TypeAlias

cached_property = property
NoneType: Incomplete
Expression: TypeAlias
P: Incomplete
T = TypeVar("T")

class ExpressionWrapper:
expression: Incomplete
def __init__(self, expression: str) -> None: ...

PROPER_COLLECTION_TYPES: Dict[Type, str]

class FieldContext:
name: str
metadata: Mapping
def copy(self, **changes: Any) -> FieldContext: ...
def __init__(self, name, metadata) -> None: ...

class ValueSpec:
type: Type
origin_type: Type
expression: Expression
builder: CodeBuilder
field_ctx: FieldContext
could_be_none: bool
annotated_type: Optional[Type]
def __setattr__(self, key: str, value: Any) -> None: ...
def copy(self, **changes: Any) -> ValueSpec: ...
@cached_property
def annotations(self) -> Sequence[str]: ...
def __init__(
self, type, expression, builder, field_ctx, could_be_none, annotated_type
) -> None: ...

ValueSpecExprCreator: TypeAlias

class Registry:
def register(self, function: ValueSpecExprCreator) -> ValueSpecExprCreator: ...
def get(self, spec: ValueSpec) -> Expression: ...
def __init__(self, _registry) -> None: ...

def ensure_generic_collection(spec: ValueSpec) -> bool: ...
def ensure_collection_type_args_supported(
collection_type: Type, type_args: Sequence[Type]
) -> bool: ...
def ensure_generic_collection_subclass(spec: ValueSpec, *checked_types: Type) -> bool: ...
def ensure_generic_mapping(spec: ValueSpec, args: Sequence[Type], checked_type: Type) -> bool: ...
def expr_or_maybe_none(spec: ValueSpec, new_expr: Expression) -> Expression: ...
def random_hex() -> str: ...
def clean_id(value: str) -> str: ...
Loading

0 comments on commit 4ddbdcd

Please sign in to comment.