You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying mypy==0.650 on my codebase (using --strict) and I'm hitting some new positives associated with --disallow-any-generics. Some of these are legit warnings that I should fix, but a couple have me flummoxed.
For example, the following is an attempt to describe the type that you can pass to requests as the json= argument (it'll take a file-like object, anything that you can shove into json.dumps a string or bytes object):
fromtypingimportUnion, Sequence, Any, IO, AnyStr, Mapping# This is a pretty lousy approximate way to say "an object that can be made into JSON"_JSON_TYPE_ISH=Union[
Mapping[str, Any],
Sequence[Any],
str, int, None]
_REQUEST_BYTES=Union[
IO[AnyStr],
AnyStr, None]
_REQUEST_TYPE=Union[
_JSON_TYPE_ISH,
_REQUEST_BYTES,
None
]
Running this gets me:
$ mypy --strict sandbox/foo.py
sandbox/foo.py:13: error: Missing type parameters for generic type
However, if I inline the _REQUEST_BYTES type alias, it seems to work OK:
fromtypingimportUnion, Sequence, Any, IO, AnyStr, Mapping# This is a pretty lousy approximate way to say "an object that can be made into JSON"_JSON_TYPE_ISH=Union[
Mapping[str, Any],
Sequence[Any],
str, int, None]
# _REQUEST_BYTES = Union[# IO[AnyStr],# AnyStr, None]_REQUEST_TYPE=Union[
_JSON_TYPE_ISH,
# _REQUEST_BYTES,Union[IO[AnyStr], AnyStr, None],
None
]
It's possible that this issue is related to #6112 -- though I tried to read though that issue and I'm not entirely sure if it's just another symptom of the same problem or not.
The text was updated successfully, but these errors were encountered:
If I read ilevkivskyi comment on issue #6112 correctly, you should be able to get rid of the error by changing line 13 to read: _REQUEST_BYTES[AnyStr]. I am not sure if that is the correct solution, but
# This is a pretty lousy approximate way to say "an object that can be made into JSON"
_JSON_TYPE_ISH = Union[
Mapping[str, Any],
Sequence[Any],
str, int, None]
_REQUEST_BYTES = Union[
IO[AnyStr],
AnyStr, None]
_REQUEST_TYPE = Union[
_JSON_TYPE_ISH,
_REQUEST_BYTES[AnyStr],
None
]
I'm trying mypy==0.650 on my codebase (using
--strict
) and I'm hitting some new positives associated with--disallow-any-generics
. Some of these are legit warnings that I should fix, but a couple have me flummoxed.For example, the following is an attempt to describe the type that you can pass to
requests
as thejson=
argument (it'll take a file-like object, anything that you can shove intojson.dumps
a string or bytes object):Running this gets me:
However, if I inline the
_REQUEST_BYTES
type alias, it seems to work OK:It's possible that this issue is related to #6112 -- though I tried to read though that issue and I'm not entirely sure if it's just another symptom of the same problem or not.
The text was updated successfully, but these errors were encountered: