Commit Graph

15 Commits

Author SHA1 Message Date
Jelle Zijlstra
5d553c9584 apply black and isort (#4287)
* apply black and isort

* move some type ignores
2020-06-28 13:31:00 -07:00
Jelle Zijlstra
44a852dff5 Literal: always import from typing_extensions for simplicity (#4219) 2020-06-10 21:23:58 -07:00
Shantanu
4c6ae26a0e codecs: add literal overloads for bytes to bytes, str to str codecs (#3599)
Closes: #300
2020-01-10 16:38:23 +01:00
Parth Sharma
4e1a45a0bb update codecs.register type definition (#3271)
Closes #3262
2019-09-27 19:06:08 +02:00
Michael Lee
b294782183 Make most contextmanager __exit__ signatures return Optional[bool] (#3179)
This pull request is a follow-up to https://github.com/python/mypy/issues/7214.

In short, within that mypy issue, we found it would be helpful to
determine between contextmanagers that can "swallow" exceptions vs ones
that can't. This helps prevent some false positive when using flags that
analyze control flow such as `--warn-unreachable`. To do this,
Jelle proposed assuming that only contextmanagers where the `__exit__`
returns `bool` are assumed to swallow exceptions.

This unfortunately required the following typeshed changes:

1. The typing.IO, threading.Lock, and concurrent.futures.Executor
   were all modified so `__exit__` returns `Optional[None]` instead
   of None -- along with all of their subclasses.

   I believe these three types are meant to be subclassed, so I felt
   picking the more general type was correct.

2. There were also a few concrete types (e.g. see socketserver,
   subprocess, ftplib...) that I modified to return `None` -- I checked
   the source code, and these all seem to return None (and don't appear
   to be meant to be subclassable).

3. contextlib.suppress was changed to return bool. I also double-checked
   the unittest modules and modified a subset of those contextmanagers,
   leaving ones like `_AssertRaisesContext` alone.
2019-08-16 16:13:33 -07:00
Rebecca Chen
5dc89fe8cf Add undocumented methods codecs.utf_16_be_{decode,encode}. (#3091)
I found the signatures here:
6a16b18224/Modules/_codecsmodule.c (L729)

https://github.com/google/pytype/issues/348 was opened against
pytype about utf_16_be_encode being missing.
2019-06-26 20:29:16 -07:00
Aymeric Augustin
0b6d134795 Support the errors arg in codecs factory functions. (#2752) 2019-02-09 15:06:46 +01:00
Rebecca Chen
7dbc8748dc Add __iter__ method to codecs.StreamReader. (#2463) 2018-09-18 13:46:16 +02:00
Martin DeMello
19708fac61 add __enter__, __exit__ and __getattr__ to streamreader/writer (#2411) 2018-09-04 13:38:18 -07:00
Siva Chandra
01abd34327 Use class with __call__ method instead of callable. (#2418)
This will enable checking positional and keyword parameters.
2018-09-03 09:50:01 -07:00
Jelle Zijlstra
6bbf3d89eb Further improve codecs stubs (#2217)
- remove header comments
- uppercase type aliases
- remove old-style type annotations
- unquote forward refs
- reformat the file
- remove values for globals
- don't use private names from codecs stub in io.pyi
2018-06-11 22:24:34 -07:00
Jelle Zijlstra
bdb06b5b81 improve codecs stubs (#2114)
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)
```
2018-06-11 15:53:15 -07:00
Daniel Bowtell
bb8b9bdaec codecs.iter(en|de)code fix return type (#1807)
codecs.iterencode and codecs.iterdecode should both return Generators rather than Iterators
2018-01-02 12:49:34 -08:00
Jelle Zijlstra
7c2d82fcb5 Add to codecs.StreamReaderWriter stub (#1032)
* Add to codecs.StreamReaderWriter stub

Closes #732

* BinaryIO -> IO[_encoded]
2017-03-21 08:15:46 -07:00
Jelle Zijlstra
cf6c563ce1 codecs: merge 2 and 3 stubs (#960) 2017-03-10 15:50:14 -08:00