Skip to content

Commit f5d7d17

Browse files
committed
Work around spurious mypy test errors
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.
1 parent 7595e7c commit f5d7d17

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

msgspec/structs.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from typing import Any, TypeVar, Union
22

33
from . import NODEFAULT, Struct
44

5-
S = TypeVar("S", bound=Struct, covariant=True)
5+
S = TypeVar("S", bound=Struct)
66

77
def replace(struct: S, /, **changes: Any) -> S: ...
88
def asdict(struct: Struct) -> dict[str, Any]: ...

msgspec/toml.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ def __dir__():
1616

1717
def _import_tomllib():
1818
try:
19-
import tomllib
19+
import tomllib # type: ignore
2020

2121
return tomllib
2222
except ImportError:
2323
pass
2424

2525
try:
26-
import tomli
26+
import tomli # type: ignore
2727

2828
return tomli
2929
except ImportError:
@@ -37,7 +37,7 @@ def _import_tomllib():
3737

3838
def _import_tomli_w():
3939
try:
40-
import tomli_w
40+
import tomli_w # type: ignore
4141

4242
return tomli_w
4343
except ImportError:
@@ -111,12 +111,7 @@ def decode(
111111
pass
112112

113113

114-
def decode(
115-
buf: Union[bytes, str],
116-
*,
117-
type: Type[T] = Any,
118-
dec_hook: Optional[Callable[[Type, Any], Any]] = None,
119-
) -> T:
114+
def decode(buf, *, type=Any, dec_hook=None):
120115
"""Deserialize an object from TOML.
121116
122117
Parameters

msgspec/yaml.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __dir__():
1616

1717
def _import_pyyaml(name):
1818
try:
19-
import yaml
19+
import yaml # type: ignore
2020
except ImportError:
2121
raise ImportError(
2222
f"`msgspec.yaml.{name}` requires PyYAML be installed.\n\n"
@@ -103,12 +103,7 @@ def decode(
103103
pass
104104

105105

106-
def decode(
107-
buf: Union[bytes, str],
108-
*,
109-
type: Type[T] = Any,
110-
dec_hook: Optional[Callable[[Type, Any], Any]] = None,
111-
) -> T:
106+
def decode(buf, *, type=Any, dec_hook=None):
112107
"""Deserialize an object from YAML.
113108
114109
Parameters

0 commit comments

Comments
 (0)