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

Add PEP 655 Required and NotRequired to typing_extensions #807

Closed
wants to merge 6 commits into from

Conversation

davidfstr
Copy link
Contributor

Related to python/mypy#10370

@JelleZijlstra
Copy link
Member

Thanks for submitting this! I'll make a new typing-extensions release for this once it's ready.

I don't have time for a full review right now, but two thoughts:

  • I feel like you should be able to get early 3.5 to work, since Required/NotRequired are conceptually similar at runtime to TypeGuard, which I got to work for early 3.5.
  • It would be nice if we could make it easy to figure out which keys are required or not required at runtime. I guess that would involve making the __required_keys__ attribute public; it currently seems undocumented.

@davidfstr
Copy link
Contributor Author

I feel like you should be able to get early 3.5 to work, since Required/NotRequired are conceptually similar at runtime to TypeGuard, which I got to work for early 3.5.

Definitely possible, but is it worth the effort? I see Python 3.5 isn't supported in general. But on the other hand I see typing_extensions attempts to provide support not just for 3.5 but also 3.4 and even 2.7. 🤔

It would be nice if we could make it easy to figure out which keys are required or not required at runtime. I guess that would involve making the required_keys attribute public; it currently seems undocumented.

The __required_keys__ and __optional_keys__ were recently documented in Python 3.10's typing module.

def __eq__(self, other):
if not isinstance(other, _Final):
return NotImplemented
if self.__type__ is not None:
Copy link
Member

Choose a reason for hiding this comment

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

This seems incorrect; it will make Required[str] == NotRequired[str] return True.

Also, could you add tests for __eq__?

@davidfstr
Copy link
Contributor Author

Thanks again for taking a first look @JelleZijlstra ! I'm prepping for PyCon this weekend, so am hoping next weekend (~5/15) to revise this PR based on feedback.

@davidfstr
Copy link
Contributor Author

Anyone have a tip on easily running the typing_extensions suite on very specific Python versions (especially 3.5.0-3.5.2) locally?

I tried to use Docker, via something like:

docker run -it -v `pwd`:/home -w /home python:3.5.2 bash

However it appears that this Docker image for Python lacks the Python's built-in semi-private test module which typing_extensions relies on.

Probably I'll try Docker again but with a specific Linux image like Ubuntu and try to install Python manually via package manager.

@JelleZijlstra
Copy link
Member

Anyone have a tip on easily running the typing_extensions suite on very specific Python versions (especially 3.5.0-3.5.2) locally?

Honestly I've just been abusing CI for that: push a change and see what happens in 3.5. I tried and failed to get 3.5 to compile locally.

@JelleZijlstra
Copy link
Member

@davidfstr Any updates?

@davidfstr
Copy link
Contributor Author

Sorry, going through rough patch in my life at the moment and my energy is nil. 😔

I'm projecting I could be out a month or two. Hopefully not, but I've got some rebuilding to do...

@JelleZijlstra
Copy link
Member

I'm sorry to hear that! No hurry, take your time.

@huyz
Copy link

huyz commented Jun 28, 2021

Hopefully not, but I've got some rebuilding to do...

@davidfstr Hey man, just wanted you to wish you the best on that. Life can be quite challenging.

@srittau
Copy link
Collaborator

srittau commented Aug 19, 2021

@JelleZijlstra If I understand correctly, this works for Python 3.6+, right? In that case, could we just use the current version and worry about Python 3.5 compatibility later (if ever)?

@JelleZijlstra
Copy link
Member

I'd have to look at the code again to make sure it's ready for 3.6+, but I'm on board in general with not worrying about 3.5.

@JelleZijlstra
Copy link
Member

Heads up that I'm hoping to get to this PR soon to get it across the finish line. It should be easier now because we dropped support for 3.5 since the PR was created.

@davidfstr
Copy link
Contributor Author

davidfstr commented Nov 10, 2021

I've regained most of my energy compared with earlier this year, so I am looking at reengaging again with PEP 655 in general starting within the next 1-2 weeks.

Heads up that I'm hoping to get to this PR soon to get it across the finish line. It should be easier now because we dropped support for 3.5 since the PR was created.

Aye. I'll coordinate with you before picking up this PR again.

@JelleZijlstra
Copy link
Member

Welcome back to the party!

@JelleZijlstra
Copy link
Member

New version in #937.

@srittau srittau closed this Nov 12, 2021
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.

None yet

6 participants