Commit Graph

22 Commits

Author SHA1 Message Date
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