Commit Graph

909 Commits

Author SHA1 Message Date
Tom Christie
dbbcf438cd
Version 0.16 (#1347) 2020-10-06 15:29:40 +01:00
Michael K
160e3088cd
Run tests against Python 3.9 stable (#1348)
Co-authored-by: Tom Christie <tom@tomchristie.com>
2020-10-06 14:57:30 +01:00
Tom Christie
c725387b2d
Preserve header casing (#1338) 2020-10-06 14:57:10 +01:00
Tom Christie
0eed6a3734
Drop .next()/.anext() in favour of response.next_request (#1339)
* Drop response.next()/response.anext() in favour of response.next_request

* Drop NotRedirectResponse
2020-10-06 14:53:07 +01:00
Tom Christie
2a2bbe58a6
Tighten client closed-state behaviour (#1346)
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-10-06 13:38:05 +01:00
Michael K
a3eb0f99dc
Run tests against Python 3.9 and add trove classifier (#1342)
Co-authored-by: Tom Christie <tom@tomchristie.com>
2020-10-06 13:12:52 +01:00
Jair Henrique
4487ac067c
Add VCR.py to third party packages doc. (#1345) 2020-10-05 22:11:52 +02:00
Changsheng
4b8774041d
Allow covariants of __enter__, __aenter__, and @classmethod (#1336)
* Allow covariants of __enter__, __aenter__, and @classmethod

The problem we currently have is the return type of classes such as
Client does not allow covariants when subclassing or context manager.
In other words:

```python
class Base:
    def __enter__(self) -> Base:  # XXX
        return self

class Derived(Base):
    ...

with Derived() as derived:
   # The type of derived is Base but not Derived. It is WRONG
    ...
```

There are three approaches to improve type annotations.
1. Just do not type-annotate and let the type checker infer
   `return self`.
2. Use a generic type with a covariant bound
   `_AsyncClient = TypeVar('_AsyncClient', bound=AsyncClient)`
3. Use a generic type `T = TypeVar('T')` or `Self = TypeVar('Self')`

They have pros and cons.
1. It just works and is not friendly to developers as there is no type
   annotation at the first sight. A developer has to reveal its type via
   a type checker. Aslo, documentation tools that rely on type
   annotations lack the type. I haven't found any python docuementation
   tools that rely on type inference to infer `return self`. There are
   some tools simply check annotations.

2. This approach is correct and has a nice covariant bound that adds
   type safety. It is also nice to documentation tools and _somewhat_
   friendly to developers. Type checkers, pyright that I use, always
   shows the the bounded type '_AsyncClient' rather than the subtype.
   Aslo, it requires more key strokes. Not good, not good.

   It is used by `BaseException.with_traceback`
   See https://github.com/python/typeshed/pull/4298/files

3. This approach always type checks, and I believe it _will_ be the
   official solution in the future. Fun fact, Rust has a Self type
   keyword. It is slightly unfriendly to documentation, but is simple to
   implement and easy to understand for developers. Most importantly,
   type checkers love it.

   See https://github.com/python/mypy/issues/1212

But, we can have 2 and 3 combined:

```python
_Base = typing.TypeVar('_Base', bound=Base)

class Base:
   def __enter__(self: _Base) -> _Base:
      return self

class Derive(Base): ...

with Derived() as derived:
   ...  # type of derived is Derived and it's a subtype of Base
```

* revert back type of of SteamContextManager to Response

* Remove unused type definitions

* Add comment and link to PEP484 for clarification

* Switch to `T = TypeVar("T", covariant=True)`

* fixup! Switch to `T = TypeVar("T", covariant=True)`

* Add back bound=xxx in TypeVar

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-10-02 16:34:57 +01:00
Tom Christie
65b69fabdb
Fix typo in CHANGELOG (#1337) 2020-10-02 13:15:23 +01:00
Tom Christie
c9354282ba
Version 0.15.5 (#1335)
* Version 0.15.5

* Tweak ChangeLog
2020-10-01 13:57:08 +01:00
Tom Christie
3f51392bea
Add response.next_request (#1334)
* Add response.next_request

* Add response.next_request

* Add response.next_request to the docs
2020-10-01 13:52:03 +01:00
Johannes
32d37cfdf1
Small namedtuple refactor (#1329)
Plus order consistency because why not..
2020-09-27 22:15:04 +02:00
Tom Christie
a7a76fbb12
Version 0.15.4 (#1327)
* Version 0.15.4

* Update CHANGELOG

* Update CHANGELOG

* Update CHANGELOG
2020-09-25 12:34:52 +01:00
Musale Martin
815ef94ed9
Support header comparisons with dict or list. (#1326)
* Support header comparisons with dict or list.

* Add check for no headers item

* Fixup testcases affected by headers comparison using dict or list

* Update test_responses.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
2020-09-25 12:28:34 +01:00
Tom Christie
666cbbdfe8
Fix automatic .read() when Response instances are created with content=<str> (#1324) 2020-09-25 11:29:17 +01:00
Tom Christie
320bfe1d0e
Fix warning test case (#1322) 2020-09-24 18:50:30 +02:00
Johannes
ac7704e78c
Remove seed-isort-config (#1321)
As of isort 5 seed-isort-config is no longer needed.

We can get rid of some explicit config too as it's now more clever.
2020-09-24 11:08:07 +01:00
Florimond Manca
24da8d40ff
Release 0.15.3 (#1318) 2020-09-24 11:39:02 +02:00
daa
78afd08e0f
Properly close stream on async response close (#1316) 2020-09-24 09:42:26 +02:00
Tom Christie
8ceb34f486
Version 0.15.2 (#1314)
* Fix response.elapsed

* Version 0.15.2
2020-09-23 11:28:22 +01:00
Tom Christie
befa57c6f9
Fix response.elapsed (#1313) 2020-09-23 11:26:12 +01:00
Tom Christie
d25f2bfeff
Fix stream unsetting auth (#1312)
* Fix ASGITransport path escaping

* Add failing test case for auth with streaming

* Fix .stream setting auth=None
2020-09-23 11:25:54 +01:00
emlazzarin
257b8fab6a
update arg name to max_keepalive_connections (#1309)
The old name `max_keepalive` was removed recently, so this updates the docs.
2020-09-23 10:42:21 +01:00
Tom Christie
27e67b32e9
Version 0.15.1 (#1308)
* Update CHANGELOG.md

* Update __version__.py
2020-09-23 11:12:50 +02:00
Tom Christie
e53f995994
Fix ASGITransport path escaping (#1307) 2020-09-23 09:37:19 +01:00
Tom Christie
c923f1af91
Update docs for 0.15 (#1306) 2020-09-22 11:57:14 +01:00
Tom Christie
a63b038267
Include 0.15.0 release date. (#1305) 2020-09-22 11:51:52 +01:00
Tom Christie
5d11756585
Include curio support in CHANGELOG (#1304) 2020-09-22 11:49:33 +01:00
Tom Christie
f932af9172
Version 0.15.0 (#1301)
* Version 0.15.0

* Update CHANGELOG.md

Co-authored-by: Jamie Hewland <jamie.hewland@hpe.com>

* Escalate deprecations into removals.

* Deprecate overly verbose timeout parameter names

* Fully deprecate max_keepalive in favour of explicit max_keepalive_connections

* Fully deprecate PoolLimits in favour of Limits

* Deprecate instantiating 'Timeout' without fully explicit values

* Include deprecation notes in changelog

* Use httpcore 0.11.x

Co-authored-by: Jamie Hewland <jamie.hewland@hpe.com>
2020-09-22 11:44:28 +01:00
Tom Christie
8e4a8a1c73
Finesse URL properties (#1285)
* url.userinfo should be URL encoded bytes

* Neater copy_with implementation

* Finesse API around URL properties and copy_with

* Docstring for URL, and drop url.authority

* Support url.copy_with(raw_path=...)

* Docstrings on URL methods

* Tweak docstring
2020-09-21 11:35:25 +01:00
Tom Christie
f3c29416f1
Support Response(text=...), Response(html=...), Response(json=...) (#1297)
* Refactor content_streams internally

* Tidy up multipart

* Use ByteStream annotation internally

* Support Response(text=...), Response(html=...), Response(json=...)

* Add tests for Response(text=..., html=..., json=...)
2020-09-21 11:19:19 +01:00
Tom Christie
8ee08afe96
Update _client.py (#1300) 2020-09-18 14:17:03 +01:00
Tom Christie
d8050ed753
Neater Host header logic on redirects (#1299) 2020-09-18 12:00:43 +01:00
Tom Christie
ed27682686
NetRC lookups should use host, not host+port (#1298) 2020-09-18 11:50:13 +01:00
Tom Christie
354c4cac1f
Refactor content streams (#1296)
* Refactor content_streams internally

* Tidy up multipart

* Use ByteStream annotation internally
2020-09-18 10:50:15 +01:00
Tom Christie
fbb21fb1ae
Drop ContentStream (#1295)
* Drop ContentStream
2020-09-18 08:41:09 +01:00
Tom Christie
e1f7791e97
Requests from transport API (#1293)
* Refactoring to support instantiating requests from transport API

* Minor refactoring
2020-09-17 11:59:42 +01:00
Tom Christie
09f94edd93
encode -> encode_request (#1292) 2020-09-17 09:33:36 +01:00
Tom Christie
ff0febbaa9
Update README.md (#1291)
* Update README.md

* Update index.md
2020-09-17 09:11:41 +01:00
Stephen Brown II
a394df59da
Fix function name in event hooks docs (#1290) 2020-09-16 09:45:20 +08:00
Tom Christie
feb404f86b
Seperate content=... and data=... parameters (#1266)
* Seperate content=... and data=... parameters

* Update compatibility.md
2020-09-15 13:36:10 +01:00
Tom Christie
54f7708e2b
Event hooks (#1246)
* Add EventHooks internal datastructure

* Add support for 'request' and 'response' event hooks

* Support Client.event_hooks property

* Handle exceptions raised by response event hooks

* Docs for event hooks

* Only support 'request' and 'response' event hooks

* Add event_hooks to top-level API

* Event hooks

* Formatting

* Formatting

* Fix up event hooks test

* Add test case to confirm that redirects/event hooks don't currently play together correctly

* Refactor test cases

* Make response.request clear in response event hooks docs

* Drop merge marker

* Request event hook runs as soon as we have an auth-constructed request
2020-09-15 12:05:39 +01:00
Tom Christie
d0fe113945
Drop chardet (#1269)
* Internal refactoring to swap auth/redirects ordering

* Drop chardet for charset detection

* Drop chardet in favour of simpler charset autodetection

* Revert unintentionally included changes

* Update test case

* Refactor to prefer different decoding style

* Update text decoding docs/docstrings

* Resolve typo

* Update docs/quickstart.md

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-09-15 11:20:19 +01:00
Tom Christie
2d6c30d061
Refactor test_auth.py to use MockTransport class. (#1288)
* Use tests.utils.MockTransport

* Use tests.utils.MockTransport
2020-09-14 17:44:05 +01:00
cdeler
62c6c1c8ad
Refactoring of models api (#1284)
* Made Request.prepare private (i.e. renamed it to _prepare)

* Added bytes as a new possible QueryParamTypes
2020-09-14 12:16:45 +01:00
Tom Christie
b58bd8e8e5
Pin flake8-pie (#1286)
* Pin `flake8-pie`

* Update requirements.txt

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-09-12 19:41:47 +01:00
Tom Christie
c2afd2d9bf
Refactor tests to use MockTransport(<handler_function>) (#1281)
* Support Response(content=<bytes iterator>)

* Update test for merged master

* Add MockTransport for test cases

* Use MockTransport for redirect tests

* Reduce change footprint

* Reduce change footprint

* Clean up headers slightly

* Update requirements.txt

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-09-12 11:16:10 +01:00
Tom Christie
8a5050ea41
Refactor to use isinstance(..., typing.Iterator) (#1282) 2020-09-11 14:37:51 +01:00
Tom Christie
5ee6135256
Support Response(content=<bytes iterator>) (#1265)
* Support Response(content=<bytes iterator>)

* Update test for merged master
2020-09-11 10:28:18 +01:00
Bart
4bd08bed22
Update compatibility.md: mention differing query parameter handling (#1262)
* Update compatibility.md

* Update docs/compatibility.md

* Update docs/compatibility.md

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Co-authored-by: Tom Christie <tom@tomchristie.com>
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-09-10 21:22:14 +02:00