classification
Title: ContextManager and AsyncContextManager protocols can't be subclassed
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: divijrajkumar, levkivskyi, miss-islington
Priority: normal Keywords: patch

Created on 2019-09-02 11:44 by divijrajkumar, last changed 2019-09-12 11:59 by levkivskyi. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 15647 merged divijrajkumar, 2019-09-02 14:57
PR 16021 merged miss-islington, 2019-09-12 10:14
Messages (5)
msg350988 - (view) Author: Divij Rajkumar (divijrajkumar) * Date: 2019-09-02 11:47
Reported this initially on github - https://github.com/python/typing/pull/650

The problem is in the typing code that checks if any of the parent classes for a Protocol are builtin protocols. The code today maintains a whitelist of builtin protocols that are okay to be subclassed, but expects them all to live within the 'collections.abc' module. This means 'typing.ContextManager' and 'typing.AsyncContextManager' cannot be subclassed, even though those protocols are listing in the whitelist.
msg350989 - (view) Author: Divij Rajkumar (divijrajkumar) * Date: 2019-09-02 11:57
I'd like to take a stab at putting up a patch for this but I've never contributed anything to Python before, so I'll have a read through the contribution docs and put up a PR.
msg351000 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-09-02 13:39
> I'd like to take a stab at putting up a patch for this

Great, thanks! Go ahead and try it.
msg352088 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-09-12 10:13
New changeset 692a0dc91597b7fb350383b633dc4d044cbd360e by Ivan Levkivskyi (Divij Rajkumar) in branch 'master':
bpo-38008: Move builtin protocol whitelist to mapping instead of list (GH-15647)
https://github.com/python/cpython/commit/692a0dc91597b7fb350383b633dc4d044cbd360e
msg352096 - (view) Author: miss-islington (miss-islington) Date: 2019-09-12 10:32
New changeset 52baf90a74f3a4573f4266bb4ca8569534db42a9 by Miss Islington (bot) in branch '3.8':
bpo-38008: Move builtin protocol whitelist to mapping instead of list (GH-15647)
https://github.com/python/cpython/commit/52baf90a74f3a4573f4266bb4ca8569534db42a9
History
Date User Action Args
2019-09-12 11:59:49levkivskyisetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
components: + Library (Lib)
versions: - Python 2.7, Python 3.5, Python 3.6, Python 3.7
2019-09-12 10:32:40miss-islingtonsetnosy: + miss-islington
messages: + msg352096
2019-09-12 10:14:03miss-islingtonsetpull_requests: + pull_request15644
2019-09-12 10:13:54levkivskyisetmessages: + msg352088
2019-09-02 14:57:45divijrajkumarsetkeywords: + patch
stage: patch review
pull_requests: + pull_request15313
2019-09-02 13:39:28levkivskyisetnosy: + levkivskyi
messages: + msg351000
2019-09-02 11:57:37divijrajkumarsetmessages: + msg350989
2019-09-02 11:47:29divijrajkumarsetmessages: + msg350988
2019-09-02 11:44:10divijrajkumarcreate