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

PEP 747: Require TypeExpr(X | Y) syntax to spell value of type TypeExpr[X | Y] #3893

Merged

Conversation

davidfstr
Copy link
Contributor

@davidfstr davidfstr commented Aug 4, 2024

  • Change is either:
    • To a Draft PEP
    • To an Accepted or Final PEP, with Steering Council approval
    • To fix an editorial issue (markup, typo, link, header, etc)
  • PR title prefixed with PEP number (e.g. PEP 123: Summary of changes)

📚 Documentation preview 📚: https://pep-previews--3893.org.readthedocs.build/

@davidfstr
Copy link
Contributor Author

This PR has been posted for 1 week without comments. Silence is golden?

@JelleZijlstra do you have any comments in advance of merge?

@JelleZijlstra
Copy link
Member

I haven't had the time to look in detail at the discussion in the other PR. I would be OK with a less precise specification here, essentially saying that int | str should be assignable to TypeExpr as well as to UnionType and leaving the exact way that happens up to type checkers. For example, type checkers could use a form of type context to achieve this, just like [] right now can be evaluated as either list[int] or list[str] depending on context.

@davidfstr
Copy link
Contributor Author

I would be OK with a less precise specification here, essentially saying that int | str should be assignable to TypeExpr as well as to UnionType and leaving the exact way that happens up to type checkers.

It sounded like Eric really wanted a precise specification, based on his comment on the previous PR, rather than a less precise one.

To resolve the question of how to recognize T1 | T2, I see 3 general approaches:

  1. Define formal rules for the | operator.
    • This is high effort and not something I'm motivated enough to do myself at this time.
  2. Use a less precise specification that still allows T1 | T2 to be assignable to TypeExpr.
  3. Don't attempt to make T1 | T2 assignable to TypeExpr.
    • That's the approach of this PR.

Right now I'm leaning on approach 3 (i.e. this PR), just to quickly unblock this final question and allow implementation of the PEP in type checkers to proceed. In particular I really want to start implementing the PEP in mypy while I still have time to.

@JelleZijlstra JelleZijlstra merged commit a6fb1e8 into python:main Aug 13, 2024
7 checks passed
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.

3 participants