Commit Graph

51 Commits

Author SHA1 Message Date
Michael Lee
efb67946f8 Use variable annotations everywhere (#2909) 2019-04-13 10:40:52 +02:00
Michael Brandt
1442cc02bf Add stubs for HTTP Handler classes in py2/urllib2 & py3/urllib.request (#2710)
* HTTP Handler class annotations for py2/urllib2 & py3/urllib.request

Add full annotations for the following classes:

* Python 2:

    * `urllib2.AbstractHTTPHandler`
    * `urllib2.HTTPHandler`
    * `urllib2.HTTPsHandler`

* Python 3:

    * `urllib.request.AbstractHTTPHandler`
    * `urllib.request.HTTPHandler`
    * `urllib.request.HTTPsHandler`

This information is largely undocumented, and was obtained by directly examining
the Python source code:

* Python 2 (v2.7.15) - https://github.com/python/cpython/blob/v2.7.15/Lib/urllib2.py#L1115-L1243
* Python 3 (v3.7.1) - https://github.com/python/cpython/blob/v3.7.1/Lib/urllib/request.py#L1224-L1364

`urllib2.AbstractHTTPHandler.do_open` takes as a parameter either
`HTTPConnection` or `HTTPSConnection`--one of the classes, not an instance of
either--and constructs an object using only a few of the parameters that either
constructor could use. `HTTPConnectionProtocol` in `stdlib/2/httplib.pyi`
follows a similar patten to `HTTPConnectionProtocol` added to
`stdlib/3/http/client.pyi` in pull request #2582 to describe the type of the
`http_class` that is passed to `do_open`.
2019-02-11 11:25:02 +01:00
Gregory P. Smith
cd4572e43c Annotate some missing http client and urllib APIs. (#2582) 2018-11-12 21:54:57 +01:00
Sebastian Rittau
006a79220f Flake8 fixes (#2549)
* Fix over-indented continuation lines

* Fix under-indented continuation lines

* Fix whitespace around default operator problems

* Limit line lengths

* Fix inconsistent files
2018-10-24 07:20:53 -07:00
Fionn Fitzmaurice
a6b4f687e0 Set urllib.parse.urljoin url argument to optional (#2513) 2018-10-11 19:50:52 +02:00
Wim L
fafed64213 Make _NetlocResultMixinBytes derive from _NetlocResultMixinBase[bytes], not [str] (#2503) 2018-10-03 19:26:12 -07:00
Sebastian Rittau
9827132d5b Fix return types in urllib.request (#2389)
* Tighten return types of URL handlers

* urlopen() etc. return a modified HTTPResponse

* Add missing methods to HTTPResponse
2018-09-18 16:45:09 -07:00
Michael Lee
bc8d68cd34 Add constructor for HTTPError in urllib2/urllib.error (#2373)
It seems that code using HTTPError previously worked by accident
because we used to accept arbitrary keyword arguments when
instantiating BaseException, or any subclass of BaseException
(see https://github.com/python/typeshed/pull/2348).

This commit adds in the correct constructor (which also lets the
user specify the arguments in keyword-argument form).

Note: I'm not very familiar with the urllib libraries, so I opted
to just add the signature and leave it up to somebody else to
fill in the types.
2018-08-08 17:05:35 -07:00
Yusuke Miyazaki
6192cce9d9 Avoid using string literals in type annotations (#2294) 2018-07-02 20:23:29 -07:00
Yusuke Miyazaki
86883d3df9 Remove unused import statements (#2282) 2018-06-27 20:14:57 -07:00
Sebastian Rittau
b05e99297c Drop Python 3.3 support from several stubs (#2266)
* Drop Python 3.3 support from importlib stubs

* Drop Python 3.3 support from html and symbol stubs
2018-06-20 16:46:11 -07:00
Jelle Zijlstra
ced5d61bb6 make urllib.response.addinfourl instantiable (#2134)
Fixes #1377 (because HTTPError is a subclass of addinfourl). Also part of #1476.
2018-06-11 15:43:53 -07:00
Michael Hirsch, Ph.D
48904699ec urlretrieve can accept filename: pathlib.Path for Python>=3.6 (#2194) 2018-06-05 07:58:39 -07:00
Sushain Cherivirala
0193ee87a8 Add OpenDirector.addheaders and PEP 526 refactoring (fixes #2163) (#2164)
* Add OpenDirector.addheaders and replace type comments with annotations

* Use ClassVar/eliminate `= ...` and add BaseHandler.handler_order (exists in Py2 versions)
2018-05-28 08:09:35 -07:00
Michael J. Sullivan
2ba90a65c0 Remove __all__ = ... from stubs (#2161)
The presence of a __all__ causes everything to not get picked up by
import *, which among other things breaks the new six.moves stubs.
2018-05-24 19:00:07 -07:00
Michael Lee
97d9f2eb2c Ensures overloads are ordered from narrow to broad (#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.
2018-05-17 09:45:33 -04:00
Salvo 'LtWorf' Tomaselli
89e5d9607c Add missing headers field (#1946) 2018-03-06 21:36:33 -08:00
Jelle Zijlstra
54dd6ba27c Change numerous default values to ... (#1722)
This is the convention, and some default values (e.g. strings) apparently
break pytype.
2017-11-09 06:28:40 -08:00
Martin DeMello
d389ef3d85 Remove a few files from the pytype blacklist. (#1628)
Fixes the following issues:

* Literals rather than ... for default values
* None rather than ... for default value of typed variable
* Literals rather than ... # type for top level constants
* # Foo rather than # type: Foo
* return value of init not set to None
2017-09-27 07:57:13 -07:00
Matthias Kramm
ac0b809bf5 tweak files to fix pytype parsing errors (#1325)
* Don't use "\" to join lines
2017-05-26 08:45:52 -07:00
Jelle Zijlstra
1d6e3f492e Fix incorrect usage of AnyStr (#1215)
* Fix incorrect usage of AnyStr

- sqlite3 was using Union[bytes, AnyStr], which doesn't make sense
- The urllib functions I changed accept either bytes or str for their "safe"
  argument
- Also added supports for PathLike to pstats
- Remove some unused imports of AnyStr

* pstats: python 2 accepts unicode
2017-04-27 08:47:59 -07:00
Nathan Henrie
abb7e49089 HTTPPasswordMgrWithDefaultRealm inherits from HTTPPasswordMgr (#1082)
ee51327a23/Lib/urllib/request.py (L900)
2017-03-23 10:48:22 -07:00
David Wetterau
50327f00ee Add types for parse_qs and parse_qsl when taking bytes as input (#1020) 2017-03-18 14:52:30 -07:00
Hong Minhee
aa54fc1958 Add missing attribs to urllib.response.addinfourl (#968) 2017-03-07 16:38:52 -08:00
David Euresti
91ff50ad7a Fix AbstractDigestAuthHandler to have correct types. 2017-02-22 20:29:17 -08:00
David Euresti
6eca1a04da Some ssl fixes (#919)
Fix return of wrap_socket.
Add read, write, pending to SSLSocket
Fix argument to socket.setdefaulttimeout
2017-02-06 17:23:22 -08:00
Mike Patek
1a49669711 Add quote_via argument to urlencode (#897)
Fixes #873
2017-01-30 12:03:52 -08:00
Mohab Usama
534c7c1103 Fix SplitResult and ParseResult stubs (#816) 2017-01-09 08:33:14 -08:00
Madeleine Thompson
4b5e766193 allow_fragments, not allow_framgents (#812) 2017-01-05 14:59:04 -08:00
Lukasz Langa
c0c982ada5 Add missing Dict imports. 2016-12-21 01:15:26 -08:00
Lukasz Langa
68a49c2c2e Fixing flake8 E111, E114, E116, E203, E225, E262 errors 2016-12-20 01:39:18 -08:00
Lukasz Langa
6b5c6626d6 Fixing flake8 E121, E122, E123, E124, E125, E126 errors 2016-12-19 23:53:19 -08:00
Lukasz Langa
67e38b6806 Fixing flake8 E231 errors 2016-12-19 23:53:19 -08:00
Lukasz Langa
fe0e3744cc Fixing flake8 E261 errors 2016-12-19 22:09:35 -08:00
Jelle Zijlstra
ed4f9e9b0b urlencode: change parameters to Any instead of AnyStr (#715)
The implementation of this function calls str() on all arguments, so it accepts
any object (https://hg.python.org/cpython/file/3.5/Lib/urllib/parse.py#l801).

This was discussed on the mypy gitter chat.
2016-12-01 11:38:23 +00:00
rymdhund
eb90eddd8f Fix urllib.parse.urlencode signature (#702)
Fixes #700
2016-11-24 11:45:20 +00:00
Richard Eames
4f567d993b Add missing self parameters (#695)
A few methods are missing the `self` parameter in  `urllib.RobotFileParser`
2016-11-23 11:37:39 +00:00
Roy Williams
1b30761802 Small changes by @rowilla to collections.pyi and urllib/requests.pyi.
(Extracted from PR #530.)
2016-11-08 19:40:10 -08:00
Elazar Gershuni
090667c7b2 fix self in urllib (#643) 2016-10-30 15:01:46 -07:00
peterdotran
aef68f323f Added attributes for URLError and HTTPError (#494) 2016-08-23 17:55:51 -07:00
Guido van Rossum
39325bf159 Mypy now supports sys.platform and sys.version_info checks (#410) 2016-07-27 13:25:29 -07:00
Eklavya Sharma
a424eeb1f8 Fix some stubs in urllib.parse (#334)
* urllib.parse: Make return type of unquote_from_bytes str.

* urllib.parse: Reject encoding when quote is passed bytes.

encoding and errors must not be supplied to quote_plus and
quote if the first parameter is a bytes, or a TypeError is raised.
So overload quote and do not put encoding and errors in the
version where bytes is the first parameter.

quote and quote_plus also allow string and safe to be of different
types.  Also allow that in the stubs.
2016-07-04 13:53:46 -07:00
Alvaro Caceres
d0ac66f5f8 Use "..." for attribute values, instead of None, [], {} 2016-06-15 14:10:04 -05:00
Valérian Rousset
2b776cfb4e complete urllib (#241) 2016-06-02 09:22:29 -07:00
Tim Abbott
9ad37b5701 Add urllib.request.proxy_bypass stubs. 2016-01-27 22:12:16 -08:00
Tim Abbott
8f3f56d07f Add some missing python 3 urllib.parse stubs. 2016-01-26 20:25:30 -08:00
Tim Abbott
9e62b7df06 Add urllib.response stub for Python 3. 2016-01-26 20:25:30 -08:00
Tim Abbott
70eb00d3f2 Fix missing urllib.error ContentTooShortError stub. 2016-01-26 20:25:30 -08:00
Tim Abbott
f036fd05f3 Add stubs for urllib.robotparser. 2016-01-26 20:25:30 -08:00
Matthias Kramm
94c9ce8fd0 Consistently use '= ...' for optional parameters. 2015-11-09 13:55:02 -08:00