* Use Tuple field in DecimalTuple
* Remove unnecessary base classes from Decimal
* Decimal.__init__ -> __new__
* Decimal.__ne__ is not defined in Python 3
* Add Decimal.as_integer_ratio()
* Annotate DecimalException.handle()
* Correct types of Decimal method arguments
* Add missing arguments and optional markers to Decimal
* Add missing arguments to Context
* Remove spurious int from Unions with float
* Remove Context.__setattr__()
* Fix return types of Context methods
These type annotations are unnecessary and seem to confuse the type system.
* Remove annotation from PlistFormat enum members
Same rationale as python/typeshed#2314; same adverse effects observed.
To backport `os.path.commonpath` in mypy I needed to use genericpath. It seems unchanged since 3.4, and the `same*` functions were added in 3.4. (checked via comparing the `__all__`s of the source in 2.7, 3.4, and 3.7.)
* Drop support for Python 3.3
* Merge Python 2 and 3 shutil
* Marked some arguments optional
* Changed callback return type from None to Any for more flexibility
`zipfile.ZipFile` is typed to accept `Text` for local and archive file
paths. In Python 3.6, several `ZipFile` methods accept `pathlib.Path`
objects, not just `str` objects. Generalize `ZipFile`'s methods so code
using `pathlib.Path` with `ZipFile` type-checks.
I verified (using my own project) that the following methods work with
os.PurePath at runtime on CPython 3.6:
* zipfile.ZipInfo.__init__
* zipfile.ZipInfo.extractall
* zipfile.ZipInfo.write
optparse.Values is like argparse.Namespace and also has a __getattr__() method to return the parsed options.
Apply commits 54b4983 and 9ae0c0b from python/typeshed#25
```python
import fileinput
with fileinput.input(files=('foo.txt',), inplace=True, backup='') as f:
for line in f:
print(f'prefix{line}', end='')
```
```
$ mypy test2.py
test2.py:3: error: "Iterable[str]" has no attribute "__enter__"; maybe "__iter__"?
test2.py:3: error: "Iterable[str]" has no attribute "__exit__"
```
```
$ mypy test2.py --custom-typeshed typeshed
$
```
Started out as progress towards #1476, but I ended up fixing a few more things:
- fixed the signature of _encode_type, which actually returns a pair, not a string
- made some attributes into properties in order to prevent the descriptor protocol from turning them into methods
- found a bug in CPython in the process (python/cpython#6779)
I used the following test file to make sure these classes are now instantiable:
```python
import codecs
import io
from typing import IO
bio = io.BytesIO()
cod = codecs.lookup('utf-8')
codecs.StreamReaderWriter(bio, codecs.StreamReader, codecs.StreamWriter)
codecs.StreamRecoder(bio, cod.encode, cod.decode, codecs.StreamReader, codecs.StreamWriter)
```
The type signature of get_grouped_opcodes() was incorrect. Resulting in type errors when checking return values.
The usage of this function is like this:
groups = sm.get_grouped_opcodes() # groups is Iterable[List[Tuple[str, int, int, int, int]]]
for group in groups: # group is List[Tuple[str, int, int, int, int]]
for opcode in group: # opcode is Tuple[str, int, int, int, int]
* Use typing.Text
* Add InputStream and ErrorStream WSGI protocols
* Fix return type of WSGIApplication
* Add type hints to wsgiref.validate
* Replace _Bytes by plain bytes
* Add wsgiref.util
* Add wsgiref.headers
* ErrorWrapper.writelines() takes an Iterable
* Fix start_response return type
* Make Python 2 and 3 branches resemble each other more closely
* Use typing.NoReturn
* Fix WriteWrapper.writer type
* Change return type of WriteWrapper.writer to Any
Standard implementation is:
```
def process(self, msg, kwargs):
kwargs["extra"] = self.extra
return msg, kwargs
```
so the signature is clearly `(Text, ...) -> (Text, ...)` (or `(str, ...) -> (str, ...)`, but following the other stubs here, I gather it's `Text`).
Basically, the same thing as [my previous pull request][0], except the
fixes are now focusing on functions with overlapping argument counts.
[0]: https://github.com/python/typeshed/pull/2138
This commit reorders any overloads where the first overload was
"shadowing" the second, preventing it from ever being matched by type
checkers that work by selecting the first matching overload alternative.
For example, the first overload alternative below is strictly broader
then the second, preventing it from ever being selected:
class Parent: pass
class Child(Parent): pass
@overload
def foo(x: *int) -> Parent: ...
@overload
def foo(x: int, y: int) -> Child: ...
The correct thing to do is to either delete the second overload or
rearrange them to look like this:
@overload
def foo(x: int, y: int) -> Child: ...
@overload
def foo(x: *int) -> Parent: ...
Rationale: I'm currently [working on a proposal][0] that would amend
PEP 484 to (a) mandate type checkers check overloads in order and
(b) prohibit overloads where an earlier alternative completely shadows
a later one.
[0]: https://github.com/python/typing/issues/253#issuecomment-389262904
This would prohibit overloads that look like the example below, where
the first alternative completely shadows the second.
I figured it would be a good idea to make these changes ahead of time:
if my proposal is accepted, it'd make the transition smoother. If not,
this is hopefully a relatively harmless change.
Note: I think some of these overloads could be simplified (e.g.
`reversed(...)`), but I mostly stuck with rearranging them in case I was
wrong. The only overload I actually changed was `hmac.compare_digest` --
I believe the Python 2 version actually accepts unicode.
Fixes#1961.
I mostly just replaced all str annotations with Text, including in return types. This is
only broadly correct; diffing a str and a unicode sequence actually results in a mixed
output of str and unicode. We could also keep the return types as str if using Text
causes errors in real code. For callbacks that take str, I introduced a Union alias
because a callable taking a str would not be a compatible with a parameter of type
Callable[[Text], bool].
I also fixed the return type of difflib.restore.