Skip to content

Commit

Permalink
Work around spurious mypy test errors
Browse files Browse the repository at this point in the history
Not sure why, but the mypy tests have suddenly started failing in CI
only. The failure is due to type stubs missing for an optional
dependency (the type stubs should only be needed for type checking the
internals of `msgspec`, not checking user usage of it). I cannot
reproduce these issues locally.

By checanging around our type annotations and adding a few `type:
ignore` comments, I believe this change should resolve the issues on CI.
  • Loading branch information
jcrist committed Apr 20, 2023
1 parent 7595e7c commit f5d7d17
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion msgspec/structs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from typing import Any, TypeVar, Union

from . import NODEFAULT, Struct

S = TypeVar("S", bound=Struct, covariant=True)
S = TypeVar("S", bound=Struct)

def replace(struct: S, /, **changes: Any) -> S: ...
def asdict(struct: Struct) -> dict[str, Any]: ...
Expand Down
13 changes: 4 additions & 9 deletions msgspec/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def __dir__():

def _import_tomllib():
try:
import tomllib
import tomllib # type: ignore

return tomllib
except ImportError:
pass

try:
import tomli
import tomli # type: ignore

return tomli
except ImportError:
Expand All @@ -37,7 +37,7 @@ def _import_tomllib():

def _import_tomli_w():
try:
import tomli_w
import tomli_w # type: ignore

return tomli_w
except ImportError:
Expand Down Expand Up @@ -111,12 +111,7 @@ def decode(
pass


def decode(
buf: Union[bytes, str],
*,
type: Type[T] = Any,
dec_hook: Optional[Callable[[Type, Any], Any]] = None,
) -> T:
def decode(buf, *, type=Any, dec_hook=None):
"""Deserialize an object from TOML.
Parameters
Expand Down
9 changes: 2 additions & 7 deletions msgspec/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __dir__():

def _import_pyyaml(name):
try:
import yaml
import yaml # type: ignore
except ImportError:
raise ImportError(
f"`msgspec.yaml.{name}` requires PyYAML be installed.\n\n"
Expand Down Expand Up @@ -103,12 +103,7 @@ def decode(
pass


def decode(
buf: Union[bytes, str],
*,
type: Type[T] = Any,
dec_hook: Optional[Callable[[Type, Any], Any]] = None,
) -> T:
def decode(buf, *, type=Any, dec_hook=None):
"""Deserialize an object from YAML.
Parameters
Expand Down

0 comments on commit f5d7d17

Please sign in to comment.