In this diff:
* Loosen `set.__[i]sub__()` to allow typical use cases (that work at runtime). Namely, allow removing `unicode` from a set of `str`, and allow removing optional values from non-optional sets.
* Avoid using union return types in `cryptography` deserialization functions.
* Tune `SupportsItems` so that `dict` implements it on Python 2.
Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
Added empty stubs for xml.dom.minidom.parse and xml.dom.minidom.parseString, and other modules under xml.dom
Co-authored-by: Stephanie Ding <sym@fb.com>
Co-authored-by: Shantanu <hauntsaninja@users.noreply.github.com>
The previous typing meant `threading.ExceptHookArgs` could not be used
to type a value.
The new typing follows what cpython does in the happy path (`_thread`
exists rather than the pure-python fallback being used).
Fixes#4767.
And use it everywhere. Note there seemed to be a discrepancy between
heapq in Python 2 and 3, so I changed that. It should probably be more
widely used within heapq, but leaving that out of scope for this PR.
Co-authored-by: hauntsaninja <>
https://github.com/python/mypy/pull/9626 will make stubtest a little bit
stricter about positional-only arguments for dunders like __init__
Co-authored-by: hauntsaninja <>
Returning a union from tcgetattr forces the caller to use isinstance or
a type: ignore comment if they modify the returned list. Return
List[Any] instead.
The cc field has ints at cc[termios.VTIME] and cc[termios.VMIN] if
lflag & termios.ICANON is zero. Change _Attr to allow this.
Fixes#4661
* Add a version guard for importing enum.
I'm trying to pull the latest version of typeshed into Google, and
pytype chokes on pstats in Python 2 because the enum module was
introduced in 3.4.
* Move the enum import into the branch that defines SortKey.
I made PathLike a protocol in #4447, but it should also be
runtime_checkable.
Caught by mypy_primer:
src/werkzeug/utils.py:646: error: Only @runtime_checkable protocols can be used with instance and class checks
Having an obscure type variable name is causing some pretty inscrutable
errors. For instance:
```
xarray/core/utils.py:466: error: Value of type variable "_LT" of "sorted" cannot be "K"
tornado/simple_httpclient.py:324: error: Value of type variable "_LT" of "min" cannot be "Optional[float]"
```
I think having a more descriptive type variable name here is better for
user experience and helps address the "why" of an error.
The target argument can be an arbitrary object.
If it has certain methods, they are used by XMLParser,
missing methods are ignored.
Ideally, we'd be able to type the potentially missing
methods correctly, but currently the type system is
unable to do so.
Fixes#4537