Jukka Lehtosalo
b08a2e6dea
Fix Python 2 genericpath.commonprefix ( #5500 )
...
The more specific overload item should come first. Also
fix the return type.
2021-05-19 12:56:18 +02:00
Jukka Lehtosalo
17bc1d83ea
Don't import enum in Python 2 stubs ( #5445 )
...
Python 2.7 doesn't have enum in the stdlib, in particular, so we
shouldn't import it.
2021-05-14 15:29:54 +02:00
Jukka Lehtosalo
a5e243fbcd
Change some str types to Text in google.protobuf.text_format ( #5343 )
...
Python 2 `unicode` values are supported. For example:
https://github.com/protocolbuffers/protobuf/blob/master/python/google/protobuf/text_format.py#L843
2021-05-05 09:33:59 +01:00
Jukka Lehtosalo
fe4acabdd7
Allow bytes in addition to str in google.protobuf.text_format ( #5267 )
2021-04-30 15:46:29 +02:00
Jukka Lehtosalo
aff821c538
Improve requests.adapters.HttpAdapter.__init__ ( #5266 )
...
The `max_retries` argument can be `None`. It's handled here as `retries`:
https://github.com/urllib3/urllib3/blob/main/src/urllib3/util/retry.py#L235
2021-04-30 14:15:13 +01:00
Jukka Lehtosalo
8bd3e16eef
Add back module-level __getattr__ to encodings ( #5261 )
...
This is needed for submodules, such as `encodings.cp437`.
2021-04-28 07:45:15 -07:00
Jukka Lehtosalo
9134f7bc3c
Fix type of typed_ast.ast27.Str.s ( #4703 )
...
The original type was too narrow.
2020-10-25 01:39:51 +02:00
Jukka Lehtosalo
5be9c91518
freezegun: Fix __exit__ and remove union return types ( #4491 )
...
These caused false positives, for example in code like this:
```
with freeze_time(None) as ft: # False positive here
ft.tick(3) # False positive here
```
2020-08-28 16:50:05 +01:00
Jukka Lehtosalo
3e966524b7
Add back six.moves.cStringIO (Python 3) ( #4490 )
...
This was accidentally removed in #4287 .
2020-08-28 16:49:56 +01:00
Jukka Lehtosalo
ab0f5519a9
Add back six.moves.range (Python 3) ( #4481 )
...
This was accidentally removed in #4287 .
2020-08-25 16:42:15 +01:00
Jukka Lehtosalo
276d0428b9
Avoid false positivies from urlparse (Python 2) ( #4437 )
...
PR #3887 changed some `str` types to `Union[str, unicode]`. The `str`
types were too narrow, but the new types are too general, resulting in
around 80 false positives in a Dropbox internal repository.
I think that it's better to narrow down the types back some to avoid
the false positives, as these are commonly used functions.
Test cases:
```
from urlparse import urlunparse, urlunsplit, urljoin, urlparse, urlsplit
reveal_type(urlunparse(('1', '2', '3', '4', '5', '6'))) # str
reveal_type(urlunparse(['1', '2', '3', '4', '5', '6'])) # str
reveal_type(urlunparse((u'1', '2', '3', '4', '5', '6'))) # unicode
reveal_type(urlunparse([u'1', '2', '3', '4', '5', '6'])) # unicode
reveal_type(urlunsplit(('1', '2', '3', '4', '5'))) # str
reveal_type(urlunsplit(['1', '2', '3', '4', '5'])) # str
reveal_type(urlunsplit((u'1', '2', '3', '4', '5'))) # unicode
reveal_type(urlunsplit([u'1', '2', '3', '4', '5'])) # unicode
reveal_type(urljoin('x', 'y')) # str
reveal_type(urljoin(u'x', 'y')) # unicode
reveal_type(urljoin('x', u'y')) # unicode
reveal_type(urlparse('x').path) # str
reveal_type(urlparse(u'x').path) # str
reveal_type(urlparse(u'x').username) # Optional[str]
reveal_type(urlsplit('x').path) # str
reveal_type(urlsplit(u'x').path) # str
```
2020-08-11 13:03:06 +01:00
Jukka Lehtosalo
866b0c3bf0
ConfigParser: accept readline() that takes no arguments ( #4433 )
...
At runtime readline() is called without arguments, so requiring
an optional argument may result in false positives.
2020-08-10 15:55:32 +01:00
Jukka Lehtosalo
0cd2350595
Add back md5.md5 ( #4432 )
...
This was accidentally removed in #4287 .
2020-08-10 12:52:13 +01:00
Jukka Lehtosalo
199b262f63
Add back six.moves.urllib.parse.unquote (Python 2) ( #4414 )
...
This was accidentally removed in #4287 .
2020-08-07 17:56:54 +01:00
Jukka Lehtosalo
57a1a3937a
Add back six.StringIO (Python 2) ( #4413 )
...
This was accidentally removed in #4287 .
2020-08-07 17:41:48 +01:00
Jukka Lehtosalo and Jelle Zijlstra
7c444365f2
Add back six.moves.range (Python 2) ( #4411 )
...
This was accidentally removed in #4287 .
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com >
2020-08-07 17:20:34 +01:00
Jukka Lehtosalo
29c71ff52a
Add back tornado stubs for Python 2 only ( #4412 )
...
Tornado ships with inline annotations, but it no longer is Python 2
compatible. I think that it makes sense to keep the legacy stubs for
Python 2 compatibility, at least for a while longer.
This restores stubs removed in #4321 , but moves them to
`third_party/2`.
2020-08-07 08:54:57 -07:00
Jukka Lehtosalo
5162c536c8
Make attributes of inspect.ArgSpec optional in Python 3 ( #3838 )
...
This makes them consistent with Python 2 stubs.
The attributes are documented here:
https://docs.python.org/3/library/inspect.html#inspect.getargspec
2020-03-10 13:15:20 +01:00
Jukka Lehtosalo
1c08bf7fa2
Improve an annotation in tornado stubs ( #3809 )
2020-03-05 14:34:14 +00:00
Jukka Lehtosalo
86135edb6d
Fix signature of assertRaisesRegexp in unittest ( #3434 )
...
Fixes mypy false positive `"None" has noattribute "__enter__"` here:
```
class Foo(unittest.TestCase):
def test_foo(self) -> None:
with self.assertRaisesRegexp(Exception, "foo"):
1 / 0
```
Fixes regression introduced in e6c467af82 .
2019-11-01 15:48:35 +00:00
Jukka Lehtosalo
eca93753ee
Update the signature of decorator.decorator ( #3336 )
...
Nothing prevents a decorator defined using `@decorator` from
changing the signature of the decorated function. For example,
this example changes the return type to `str`:
```
from decorator import decorator
@decorator
def stringify(f, *args, **kwargs) -> str:
return str(f(*args, **kwargs))
```
The old signature caused false positives in internal Dropbox code.
I couldn't come up with a signature that would produce better types
with mypy while not generating false positives.
2019-10-10 16:45:06 +01:00
Jukka Lehtosalo
3a2fdfd45d
Make it explicit that the cryptography stubs are incomplete ( #3331 )
2019-10-09 16:20:36 +01:00
Jukka Lehtosalo
0914d50b49
Fix the signature of decorator.contextmanager ( #3330 )
2019-10-09 16:58:37 +02:00
Jukka Lehtosalo
e3773ad691
Fix typos in yaml stubs (save_* -> safe_*) ( #2985 )
2019-05-13 11:57:34 -04:00
Jukka Lehtosalo
306b4694ae
Remove redundant definition of ast.PyCF_ONLY_AST ( #2803 )
...
This gets imported from `_ast`, so the definition was
redundant. This causes problems with the new mypy semantic
analyzer, as it will flag the redefinition as an error.
2019-02-20 17:12:11 +00:00
Jukka Lehtosalo
184148611a
Fix signature of TypedDict has_key() ( #2672 )
2018-12-05 18:17:37 +01:00
Jukka Lehtosalo
c8890b0f93
Add mypy fallback class for TypedDict methods to mypy_extensions ( #2670 )
...
This class is not defined at runtime but it's used by
mypy internally to support TypedDict methods.
Use NoReturn in argument types for better type safety
when the related mypy plugin hook is not active.
2018-12-04 18:21:58 +00:00
Jukka Lehtosalo
eaeb5fcf13
Revert "Move Sized earlier in the bases of Sequence ( #2602 )" ( #2657 )
...
This reverts commit 4dc21f04dd .
Fixes #2655 .
2018-11-30 14:48:55 +00:00
Jukka Lehtosalo
84548f5bba
Revert "fix list concatenation ( #2404 )" ( #2653 )
...
The fix caused regressions for mypy that are difficult to
fix. See https://github.com/python/mypy/issues/5492 for
context.
This reverts commit 1a42a2c3ea .
2018-11-29 12:20:29 -08:00
Jukka Lehtosalo
07374a8251
Fix requests.post signature ( #2256 )
...
The change introduced in 395ab5abd1
broke the signature of `requests.post`, among others, since
`MutableSequence` is invariant, and plain `Dict[str, str]` values
were no longer valid for the `data` argument.
This changes the signature to have `Any` components as a
compromise. Adding more items to the union seems a bit too much, since
the error messages for invalid argument types are already pretty hard to
read.
Another option might be to use `Mapping` instead of `MutableMapping`
due to covariance, but I assume there's a reason why `MutableMapping`
is used here.
2018-06-19 17:08:55 +01:00
Jukka Lehtosalo
feeb4e71ef
Change mock classes to Any values to avoid false positives ( #2255 )
...
The previous definitions in `mock` caused many false positives in
internal Dropbox repositories.
One source of problems was `List[Mock]` not being compatible with
`List[SomeClass]`, since `list` is invariant.
2018-06-19 16:28:19 +01:00
Jukka Lehtosalo
a88d942f91
Add missing protobuf container methods ( #2254 )
...
Implementation of the methods is here:
https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/containers.py
2018-06-19 15:52:54 +01:00
Jukka Lehtosalo
9b612c9218
Add TypedDict total argument ( #1443 )
...
See https://github.com/python/mypy/pull/3558 for context.
2017-06-29 08:38:13 -07:00
Jukka Lehtosalo
f296b37e80
Fixes to unittest stubs ( #1024 )
...
* Fixes to unittest stubs
* Make types more precise
2017-03-18 14:35:33 -07:00
Jukka Lehtosalo
f2579e532f
Update signature of dict.get ( #852 )
...
Without this change, mypy can't infer proper types for cases like
`d.get(k, [])` where it needs type context to infer the type of
`[]`. We add the value type to the second argument to `get` using
union types, and this provides the context. This doesn't affect
the effective signature of `get`, other than providing the type
context for mypy.
Also removed some related redundant method definitions where we can
just inherit the base class definition. This makes it easier to
keep the method signatures consistent.
Note that this requires a few mypy PRs before mypy will be able to
use this effectively:
* https://github.com/python/mypy/pull/2718
* https://github.com/python/mypy/pull/2715
2017-01-20 07:41:54 -08:00
Jukka Lehtosalo
c577c84a17
Add stub for cryptography.hazmat.primitives.serialization ( #851 )
...
This makes the stubs for cryptoraphy less incompelete. Created using
stubgen. I don't know what the types are.
2017-01-20 07:40:30 -08:00
Jukka Lehtosalo
35978a7ca5
Make signature of DictMixin.get consistent with Mapping.get ( #838 )
2017-01-17 14:08:49 +00:00
Jukka Lehtosalo
734ad44a11
Make MRO of UserDict.DictMixin consistent with Mapping ( #837 )
...
This fixes MRO conflicts produced by mypy when using multiple
inheritance.
2017-01-17 13:55:31 +00:00
Jukka Lehtosalo
f39f9bf694
Make object_hook of json.load and json.loads optional (Python 2) ( #757 )
2016-12-07 13:32:56 -08:00
Jukka Lehtosalo
e05edb60f1
Mypy stub fixes for strict optional mode ( #366 )
2016-07-13 09:38:40 -07:00
Jukka Lehtosalo
b98580d299
Don't use basestring in tempfile stub ( #205 )
...
Fixes #202 .
2016-05-24 16:45:48 -07:00
Jukka Lehtosalo
d3d6a47302
Accept more unicode in 2.7 tempfile stubs ( #201 )
2016-05-16 13:37:15 +01:00
Jukka Lehtosalo
292447bd62
Misc stub fixes ( #181 )
2016-05-04 16:54:57 -07:00
Jukka Lehtosalo
a5d5dcc4f4
Fixes to os.environ ( #172 )
...
Add os.environ.copy() to Python 2 stubs. Fix return
type of os.environ.copy().
2016-04-28 11:53:51 +01:00
Jukka Lehtosalo
8df19841bb
Make Queue generic in Python 2, similar to Python 3 ( #155 )
2016-04-22 15:49:02 +01:00
Jukka Lehtosalo
5eaf522cde
Fixes to urllib2 stubs ( #154 )
2016-04-22 13:19:37 +01:00
Jukka Lehtosalo
fcef262a9b
Support keyword arguments for dict() (Python 2) ( #148 )
2016-04-17 13:07:54 +01:00
Jukka Lehtosalo
70c2274e94
Update dict(...) to accept keyword arguments ( #147 )
...
We can't describe the fact that a keyword argument results in a 'str'
dictionary key in a stub. This needs to be handled elsewhere.
2016-04-16 16:30:15 +01:00
Jukka Lehtosalo
bd36a37481
Add __setattr__ to object
2015-12-05 15:44:28 -08:00
Jukka Lehtosalo
4c547fc4f6
Add object.__new__
...
Not entirely sure about the right signature, though.
2015-11-29 12:18:42 -08:00
Jukka Lehtosalo
d3efa5d6bc
Add missing definitions to Python 3 'traceback'
2015-11-23 21:49:51 -08:00
Jukka Lehtosalo
9640fe569d
Add directories for Python 2 and Python 3 stubs
2015-03-04 20:57:49 -08:00
Jukka Lehtosalo
893f49bd80
Initial commit
2015-03-04 20:51:28 -08:00