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

bpo-44490: Add __parameters__ and __getitem__ to types.Union #26980

Merged
merged 14 commits into from
Jul 6, 2021

Conversation

uriyyo
Copy link
Member

@uriyyo uriyyo commented Jul 1, 2021

@uriyyo
Copy link
Member Author

uriyyo commented Jul 1, 2021

@Fidget-Spinner Could you please review this PR?

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

@uriyyo thank you for sending this PR so quickly! Excellent work. I only have a few minor readability nits below.

Lib/test/test_types.py Outdated Show resolved Hide resolved
Objects/unionobject.c Outdated Show resolved Hide resolved
Include/genericaliasobject.h Outdated Show resolved Hide resolved
@uriyyo
Copy link
Member Author

uriyyo commented Jul 2, 2021

@Fidget-Spinner Thanks for review, I have added tests that you suggested.

@Fidget-Spinner
Copy link
Member

@Fidget-Spinner Thanks for review, I have added tests that you suggested.

Thanks for applying the suggestions. This LGTM. I've requested a review from Guido and I'm waiting for him to take a look when he has the time. I can't merge PRs, sorry.

@Fidget-Spinner
Copy link
Member

@uriyyo can you please rebase this against main branch? I fixed a GC bug in Union in 1097384, and I think you may have to add Py_VISIT(alias->parameters) in union_traverse Thanks.

uriyyo and others added 11 commits July 3, 2021 17:26
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
…90.xY80VR.rst

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
@uriyyo uriyyo force-pushed the fix-issue-44490 branch from cddb7e0 to 8cfa980 Compare July 3, 2021 14:29
@uriyyo
Copy link
Member Author

uriyyo commented Jul 3, 2021

@Fidget-Spinner Thanks, fixed

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

LG, I would just update two comments slightly.

Lib/test/test_types.py Show resolved Hide resolved
Objects/genericaliasobject.c Outdated Show resolved Hide resolved
Objects/unionobject.c Outdated Show resolved Hide resolved
uriyyo and others added 2 commits July 5, 2021 20:00
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
@uriyyo uriyyo requested a review from gvanrossum July 5, 2021 17:12
@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Jul 5, 2021

Eventually if this PR is merged, we may have to consider backporting this to 3.10. Since it's a somewhat big change, I'm pinging @pablogsal as the 3.10 RM for his awareness.

TLDR: Some uncommon but valid use cases not covered by PEP 604 were discovered in bpo. This PR adds support for them. Can it land in 3.10 beta 4 too?

@pablogsal
Copy link
Member

Eventually if this PR is merged, we may have to consider backporting this to 3.10. Since it's a somewhat big change, I'm pinging @pablogsal as the 3.10 RM for his awareness.

TLDR: Some uncommon but valid use cases not covered by PEP 604 were discovered in bpo. This PR adds support for them. Can it land in 3.10 beta 4 too?

We are too far in the development cycle to add new features, specially stuff that is touching c code. I do understand that this is something new in 3.10 so we do not have possibility of regressions and I see that this is an important point. I think we are fine to get this in with the following requirements:

  • Is merged before the last beta (beta4)
  • At least 2 core Devs review and approve the PR

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Thanks!

@gvanrossum
Copy link
Member

@Fidget-Spinner Can you think of another core dev to review this (not Pablo)?

@pablogsal
Copy link
Member

@Fidget-Spinner Can you think of another core dev to review this (not Pablo)?

I can do a review if you don't find anyone else, but currently, I am flooded with PEP 657 stuff so it will probably be in a couple of days

@pablogsal pablogsal added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 5, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 7799a15 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 5, 2021
@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Jul 5, 2021

@Fidget-Spinner Can you think of another core dev to review this (not Pablo)?

@serhiy-storchaka , are you alright with reviewing this?

In the meantime, the Windows 10 buildbot failures seem potentially related so @uriyyo please look into them. I'll take a look too in a day or two.

@pablogsal
Copy link
Member

In the meantime, the Windows 10 buildbot failures seem potentially related so @uriyyo please look into them. I'll take a look too in a day or two.

I am restarting them as I am quite sure this is due to corrupted pyc files from a previous run. New builds here:

https://buildbot.python.org/all/#/builders/577/builds/86
https://buildbot.python.org/all/#/builders/593/builds/89

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Jul 6, 2021

In the meantime, the Windows 10 buildbot failures seem potentially related so @uriyyo please look into them. I'll take a look too in a day or two.

I am restarting them as I am quite sure this is due to corrupted pyc files from a previous run. New builds here:

https://buildbot.python.org/all/#/builders/577/builds/86
https://buildbot.python.org/all/#/builders/593/builds/89

Oh you're right. Sorry @uriyyo if I led you on a wild goose chase. I suspect one of two things

  • maybe someone forgot to bump the magic number for a Windows-related change.
  • the worker maybe didn't clean up old files properly -- I suspect it's this one because I cannot reproduce this locally on Windows machine.

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Jul 6, 2021

After spending a few hours investigating this. I think our best bet is to merge latest main into this PR and try running the buildbots again. I have no clue why those 2 buildbots fail and any help would be much appreciated. Some findings:

  • They are 2 different workers. I find it unlikely that 2 machines could both have corrupted/out of date pyc files coincidentally.
  • I've tried building this locally with same build flags as the buildbots, but I can't reproduce it.
  • I noticed the buildbot/clean.bat script fails on both. But they've been like this for at least a month and I suspect it's because there are no leftover pyc files to clean. Maybe the buildbots already clean it up themselves?

@gvanrossum
Copy link
Member

Yeah, merge latest main is definitely a good first step.

@uriyyo
Copy link
Member Author

uriyyo commented Jul 6, 2021

@gvanrossum @Fidget-Spinner I have merged latest main into PR branch.

And I have a question should we fix more cases in the scope of this PR?

  1. types.Union is not serializable and can not be used with pickle.
  2. types.Union can not be used with typing.Annotated.
  3. typing._collect_type_vars currently do not collect params from the types.Union.
>>> typing.List[list[T] | float].__parameters__
()

UPD. Actually, there is a lot of case at typing module where types.Union is not supported but I believe it should be.

@gvanrossum
Copy link
Member

Tests pass now, I propose to merge now and do another PR for the other issues.

We still need another core dev approval, but I'm merging now. ("Merged before b4" was one of the requirements, "two core devs" is the other.)

@gvanrossum gvanrossum merged commit c45fa1a into python:main Jul 6, 2021
@uriyyo
Copy link
Member Author

uriyyo commented Jul 6, 2021

Great, I will open another PR to cover cases that I mentioned.

Fidget-Spinner added a commit to Fidget-Spinner/cpython that referenced this pull request Jul 17, 2021
…ugfix backports

Co-Authored-By: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-Authored-By: Guido van Rossum <gvanrossum@gmail.com>
Co-Authored-By: Yurii Karabas <1998uriyyo@gmail.com>
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Jul 17, 2021
…ythonGH-26980)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>.
(cherry picked from commit c45fa1a)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jul 17, 2021

There are several bugs (bpo-44633, bpo-44653), but I am going to fix them soon.

I am +1 for backporting this feature to 3.10.

@uriyyo
Copy link
Member Author

uriyyo commented Jul 17, 2021

@serhiy-storchaka Do you need help with it? There is also issue with types.Union serialisation that I am going to fix.

@pablogsal
Copy link
Member

There are several bugs (bpo-44633, bpo-44653), but I am going to fix them soon.

I am +1 for backporting this feature to 3.10.

Please, see my other comment: #27207 (comment)

serhiy-storchaka added a commit that referenced this pull request Jul 17, 2021
…H-26980) (GH-27207)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>.
(cherry picked from commit c45fa1a)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
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.

7 participants