Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabling individual experimental features #13790

Merged
merged 7 commits into from
Oct 9, 2022

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Oct 2, 2022

Ref #13685

@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
Member Author

Hm it looks like this causes a crash, I will try to fix.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
Member Author

Hm, the second crash shows that we can't probably say Unpack support is complete yet. We should probably at least support *args: Unpack[tuple[int, str, int]] (supporting unions will be tricky, and we don't support unions of TypedDicts anyway, and unions are not specified by the PEP).

@ilevkivskyi
Copy link
Member Author

Btw a simple repro for the crash is

class E(Generic[T]):
    def __init__(self, *args: Unpack[tuple[int, str]]) -> None: ...
E()

Also while playing with this I have found two bugs in the **kwds support for Unpack. First, this crashes:

class C:
    def __init__(self, **kwds: Unpack) -> None: ...

Instead we should give an error about missing type arg. Second, this doesn't substitute implicit Any for a generic TypedDict, causing weird error:

T = TypeVar("T")
class TD(TypedDict, Generic[T]):
    x: T
    y: int

def foo(**kwds: Unpack[TD]) -> None: ...  # Should be same as `TD[Any]`
foo(x="yes", y=42)

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Looks cool!

Question: can we somehow bind feature ids to error codes?
So users won't have to memorize two separate things and their mappings?

mypy/options.py Outdated Show resolved Hide resolved
Co-authored-by: Nikita Sobolev <[email protected]>
@ilevkivskyi
Copy link
Member Author

can we somehow bind feature ids to error codes?

No, not really. Many features (in particular those that are relevant here like Unpack and TypeVarTuple) don't have any errors related to them. This PR is specifically for such cases.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2022

Diff from mypy_primer, showing the effect of this PR on open source code:

sublime_debugger (https://github.com/daveleroy/sublime_debugger)
- modules/core/event.py:5: error: "TypeVarTuple" is not supported by mypy yet  [misc]
+ modules/core/event.py:5: error: "TypeVarTuple" support is experimental, use --enable-incomplete-feature=TypeVarTuple to enable  [misc]
- modules/core/event.py:27: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/event.py:27: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/event.py:37: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/event.py:37: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/event.py:59: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/event.py:59: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/event.py:69: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/event.py:69: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/event.py:75: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/event.py:75: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/core.py:12: error: "TypeVarTuple" is not supported by mypy yet  [misc]
+ modules/core/core.py:12: error: "TypeVarTuple" support is experimental, use --enable-incomplete-feature=TypeVarTuple to enable  [misc]
- modules/core/core.py:30: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/core.py:30: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/core.py:33: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/core.py:33: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/core.py:36: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/core.py:36: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/core.py:42: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/core.py:42: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]
- modules/core/core.py:51: error: "Unpack" is not supported yet, use --enable-incomplete-features  [misc]
+ modules/core/core.py:51: error: "Unpack" support is experimental, use --enable-incomplete-feature=Unpack to enable  [misc]

@ilevkivskyi ilevkivskyi merged commit b79a20a into python:master Oct 9, 2022
@ilevkivskyi ilevkivskyi deleted the split-incomplete branch October 9, 2022 20:39
ilevkivskyi added a commit that referenced this pull request Oct 9, 2022
This fixes couple issues discovered in
#13790:
* A crash on empty `Unpack`
* Wrong behavior with implicit generic `Any`

The latter was actually caused by somewhat reckless handling of generic
`TypedDict`s, wrong argument count was handled inconsistently there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants