Commit Graph

64 Commits

Author SHA1 Message Date
Sebastian Rittau
87d7dd3d95 Fix annotations with literal values (#3411) 2019-10-28 06:59:28 -07:00
Sebastian Rittau
ec7960a8cb Convert namedtuples to class syntax (#3321) 2019-10-20 10:37:33 +02:00
Maarten ter Huurne
6a92ae6295 Change type for urllib headers from Mapping to email.message.Message (#3345)
Also remove override of 'headers' in HTTPError

Closes #3344
2019-10-11 14:56:19 +02:00
Russ Allbery
f0ccb325aa Mark some urllib.parse return fields optional (#3332)
Per the urllib.parse documentation, username, password, hostname,
and port will be set to None if not set in the parsed URL.  The
same is true for urlparse in Python 2 according to its documentation.
2019-10-09 19:38:59 +02:00
robertschweizer
3ee8fc2242 Add missing Optional types in urllib.parse (#3263)
None values are accepted, and interpreted as empty (byte) strings by
some urllib.parse functions.
2019-10-09 08:38:46 +02:00
Sebastian Rittau
256b3ce8ab Remove a bunch of unused imports (#3323) 2019-10-08 07:59:32 -07:00
Sebastian Rittau
c32e1e2280 Enable --disallow-any-generics for stubs (#3288) 2019-10-01 05:31:34 -07:00
Vasily Zakharov
aaff561ef6 Added stub for urllib.request.proxy_bypass() (#3283) 2019-09-30 18:57:14 +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
Sebastian Rittau
9ccf9356bf Remove Python 3.4 support (#3147)
Closes #3123
2019-07-27 10:58:21 +02:00
Sebastian Rittau
0177dedc42 Add werkzeug.middleware (#3103)
HTTPConnection.timeout can be a float
2019-07-24 08:51:55 -07:00
Utkarsh Gupta
8e7c32846f request.pyi: Change Union[] -> Any for attributing status. (#3045)
Fixes #3026
2019-06-13 12:01:13 +02:00
Jelle Zijlstra
8bd744a38f fix type of msg argument to HTTPRedirectHandler.redirect_request (#2949)
It's not really documented (https://docs.python.org/3/library/urllib.request.html#urllib.request.HTTPRedirectHandler.redirect_request), but logically a message is a str, and reading the code for the stdlib confirms that it's intended to be a str.
2019-05-03 20:44:56 +02:00
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