Commit Graph

33 Commits

Author SHA1 Message Date
Shantanu
e3889c776e pep 484: explicit reexport as intended (#4586)
See discussion on typing-sig.
This doesn't take care of some third_party libraries, will follow up on
those.

Co-authored-by: hauntsaninja <>
2020-09-30 10:04:23 -07:00
Eric Traut
04c74640f0 Removed imported symbols that are not accessed or re-exported (#4387)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-05 22:49:17 -07:00
Sebastian Rittau
5e76f51930 Upgrade to isort 5 (#4323)
This now also reformats imports not at the top of files.
2020-07-16 07:01:57 -07:00
Jelle Zijlstra
5d553c9584 apply black and isort (#4287)
* apply black and isort

* move some type ignores
2020-06-28 13:31:00 -07:00
Brad Solomon
ddb47deb27 Allow Union[unicode, str] rather than just str in several places (#3887)
* Allow unicode objects throughout urlparse.py

Functions such as `urlparse()`, if given a unicode object,
will happily return a ParseResult of unicode components.

Relatedly, functions like `unquote()` will accept any of
bytes/str/unicode and return an object of the same type
or a composite containing that type.

* Allow unicode in several places in Thread

`name` and `kwargs` to Thread.__init__ function perfectly
well with unicode, not just str.

Note: the .name attribute will always be str even
if the constructor is passed something else, since
__init__ calls:

    self.__name = str(name or _newname())

* Use typing.AnyStr properly

...rather than defining a new TypeVar unncessarily.

* Use typing.Text properly

Text is behaviorally equivalent to Union[str, unicode]
for Python 2 argument types.

* Remove outdated import & definition

* [check file consistent] copy changes to _dummy_threading.pyi
2020-05-27 19:52:14 -07:00
Shantanu
d313e170b7 threading: update for py39 (#4087) 2020-05-26 17:37:07 -07:00
Shantanu
00a27634b1 threading: fix inheritance (#4072) 2020-05-24 18:51:30 -07:00
PGijsbers
16ba411434 Change annotation of 'function' in Timer.__init__ from Callable[..., None] to Callable[..., Any] (#3788)
The return value is ignored, but calling a function with a return value should still be valid.

Closes: #3782
2020-02-29 14:05:23 +01:00
Rune Tynan
85afac3bd5 Add (_)dummy_threading module, identical to threading (#3554)
* Add (_)dummy_threading module, identical to threading

* Remove unnecessary comment, add consistency check
2020-01-18 07:42:32 -08:00
Sebastian Rittau
0501e2b329 Annotations for remaining Python 3.8 additions (#3358)
* Add os.add_dll_directory()
* Add memfd_create() and flags
* Add type annotation to flags
* Add stat_result.st_reparse_tag and flags
* Add ncurses_version
* Add Path.link_to()
* Add Picker.reducer_override()
* Add plistlib.UID
* Add has_dualstack_ipv6() and create_server()
* Add shlex.join()
* Add SSL methods and fields
* Add Python 3.8 statistics functions and classes
* Remove obsolete sys.subversion
* Add sys.unraisablehook
* Add threading.excepthook
* Add get_native_id() and Thread.native_id
* Add Python 3.8 tkinter methods
* Add CLOCK_UPTIME_RAW
* Add SupportsIndex
* Add typing.get_origin() and get_args()
* Add unicodedata.is_normalized
* Add unittest.mock.AsyncMock

Currently this is just an alias for Any like Mock and MagicMock. All of
these classes should probably be sub-classing Any and add their own
methods. See also #3224.

* Add unittest cleanup methods
* Add IsolatedAsyncioTestCase
* Add ElementTree.canonicalize() and C14NWriterTarget
* cProfile.Profile can be used as a context manager
* Add asyncio task name handling
* mmap.flush() now always returns None
* Add posonlyargcount to CodeType
2019-10-14 09:53:48 +02:00
Guido van Rossum
b336182b69 Fix some errors with --disallow-any-generics (#3276)
See #3267. Covers all of stdlib/2and3.
2019-09-29 09:15:27 -07:00
Augusto Hack
4c63939585 setprofile accepts None (#3239)
The function `threading.setprofile` can be called with a `None` value to
clear the profile function. This does unset the function from the
existing threads, it only clears the callback function so that new
threads are created without the profiling hook installed.
2019-09-17 13:15:27 +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
Brian Brunner
53500c8750 Make Timer args less restrictive (#3007)
Closes #3004
2019-05-23 15:08:48 +02:00
Michael Lee
efb67946f8 Use variable annotations everywhere (#2909) 2019-04-13 10:40:52 +02:00
Sergey Machulskis
bec2fef7fa threading.Lock issue when using it with ExitStack (#2908)
* Make threading primitives ContextManagers
* Make catch_warnings ContextManager
* Make SMTP ContextManager
* Fix type of exc_type for SMTP
2019-04-11 21:39:17 +02:00
Utkarsh Gupta
388de0876b threading.pyi: Add currentThread for all versions (#2647)
Fixes https://github.com/python/typeshed/issues/2625
2018-11-28 18:52:27 -08:00
PRAJWAL M
9ee458226c Remove version guard (#2565)
isAlive() is still present in threading.py in python 2.7, 3.4, 3.5, 3.6, 3.7.

Closes #2552
2018-10-28 00:21:47 +02:00
Yusuke Miyazaki
581705d9ee Prefer to use ellipsis over pass (#2292) 2018-06-28 10:29:45 -07:00
Anthony Sottile
be3c43cf63 A Thread(target=...) function can return anything (#2224) 2018-06-13 11:50:17 -07:00
Emil Hessman
4d8010a988 Define threading.local as a proper class (#2086)
Fixes #1591
2018-04-30 08:48:12 -07:00
Josh Staiger
fd25e534ad Add default timeout for Condition.wait_for (#1726)
Fixes:

- Too few arguments for "wait_for" of "Condition"

when timeout is not specified.
2017-11-09 10:12:33 -08:00
rchen152
85e75c9a6a Fix a parameter type in threading.Thread.__init__ (#1706) 2017-11-01 15:41:10 -07:00
hashstat
fc74f53c5a Corrects timeout type annotations. (#1639)
Timeouts should be floats, but were ints for some reason.
2017-10-04 08:40:40 -07:00
Jelle Zijlstra
6f6fa428ce fix some issues found by stubcheck (#1303)
- ThreadError exists (undocumented) on Python 3. It's an alias for _thread.error,
  but making it a separate exception seems fine.
- zipfile.error is an alias for BadZipFile on both Python versions.
- zlib.Compress and Decompress are not actually accessible at runtime.
2017-05-23 12:44:35 -07:00
Gerhard Hagerer
96123f8474 Added Lock.locked() method stub (#633)
https://docs.python.org/3/library/asyncio-sync.html#asyncio.Lock.locked
2016-10-26 07:17:59 -07:00
Matthias Kramm
b0eae4bf46 allow to use RLock in type annotations (#595) 2016-10-10 16:52:47 -07:00
Alvaro Caceres
92b600540e Add private members to stdlib threading (#590)
* Add threading._DummyThread

* Make threading.RLock a factory function, not a class

Will break code that currently uses a threading.RLock type annotation
2016-10-07 13:11:47 -07:00
Alvaro Caceres
674fe2b59f Add threading.Condition.notifyAll (#587)
Documented in py2, undocumented in py3
2016-10-06 14:14:08 -07:00
Guido van Rossum
1e1694276c Oops, should use ... not None. 2016-08-02 11:06:52 -07:00
Guido van Rossum
2bb6856456 Change local to type Any and add link to mypy bug. 2016-08-02 10:59:11 -07:00
Guido van Rossum
9debde04e9 Make type of threading.locals more lenient. 2016-08-02 09:39:00 -07:00
Valérian Rousset
ee02a8a968 Improve threading (#403)
* initial stubgen

* comment everything

* 17.1.0 done

* 17.1.1 done

* 17.1.2 done

* 17.1.3 done

* 17.1.4 done

* 17.1.5 done

* reorder __enter__, __exit__

* 17.1.6 done

* 17.1.7 done

* 17.1.8 done

* 17.1.9 done

* cleanup, py3 done

* py2 begin, comment everything

* 16.2.0 done

* 16.2.1 done

* 16.2.2 done

* 16.2.3 done

* 16.2.4 done

* 16.2.5 done

* 16.2.6 done

* 16.2.7 done

* cleanup, py2 done

* remove old threading stubs

* use --strict-optional

* improve Condition.wait_for

* remove type ignore
2016-08-01 14:31:57 -07:00