◐ Shell
reader mode source ↗
Skip to content

bpo-46644: No longer accept arbitrary callables as type arguments in generics#31159

Closed
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:typing-type-check-callable
Closed

bpo-46644: No longer accept arbitrary callables as type arguments in generics#31159
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:typing-type-check-callable

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Feb 6, 2022

Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

I am +1 on this version of this PR 👍

@JelleZijlstra

Copy link
Copy Markdown
Member

Please don't. This will break future innovation in the type system (e.g., making new typing primitives in typing-extensions). We don't need to be strict about allowed types in the typing.py runtime; that's what static type checkers are for.

@GBeauregard

Copy link
Copy Markdown
Contributor

Please don't. This will break future innovation in the type system (e.g., making new typing primitives in typing-extensions). We don't need to be strict about allowed types in the typing.py runtime; that's what static type checkers are for.

In addition, this breaks cpython internal typeforms that need to be able to pass through _type_check without importing typing: I need dataclasses.InitVar to do it in #30997.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Do typing primitives in typing-extensions subclass any typing class? If yes, it can be included in the list of allowed types. If no, we perhaps could use duck-typing: check for some attributes, like __parameters__.

Alternatively we can remove all checks.

@GBeauregard

GBeauregard commented Feb 6, 2022

Copy link
Copy Markdown
Contributor

dataclasses.InitVar doesn't subclass anything, and it's not acceptable to make dataclasses import typing. So this won't work.

Duck typing moves the reason __call__ is a bug magnet to another attribute that people won't notice until it's in the final code: an odd requirement not noticed because of the rarity of _type_check in actual type annotations. I support removing all the checks like I did in #31151. The only remaining check there is for tuple, but not for type reasons: it's because it's used to disallow multiple arguments by typeforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants