-
Notifications
You must be signed in to change notification settings - Fork 250
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 typing_extensions module for new / optional typing features to PyPI #435
Comments
Agreed. I do think there should be a requirement for things to appear in a PEP (either 484 or a new one) before they go into typing_extensions. This means we should probably write up TypedDict and maybe wait for argspecs (for those there's still a lot of possible variation in the eventual design). |
Type and maybe NewType would be other good candidates. They're present in the later versions of Python 3.5, but not the earlier ones, iirc. |
Oooh, might as well! |
Other ones perhaps worth adding in:
(I got this list by looking for the "New in" phrase in the typing docs, though it might not be comprehensive. For example, neither And for the sake of completeness, we could also add in the |
Sounds like it might be worthwhile to just shadow/duplicate all of regular I've been thinking of a related idea to create a library of commonly useful type aliases. Some things that could be included are:
|
I was curious and decided to just install Python 3.5.0 and 3.6.1 and do a diff, and found a few more (non-private) names that I missed: (Though, I'm not sure how many of these are meant to be publicly used or not? The last four items on the list certainly don't appear to be documented anywhere.) In any case, I agree with @JelleZijlstra that just shadowing |
I'm not sure if I like shadowing everything, as it would potentially lead into a subset of users just importing everything from # Just to make sure everything works in 3.5.0
from typing_extensions import Optional, Tuple Also, if implementations of things like # a.py
from typing_extensions import List
A = List # b.py
from a import A
from typing import List
List[A[int]] # might fail The memory usage and startup time cost of If we'd just import the basic primitives like My preference would be just to include new things added to the public API of |
I would say it will most certainly fail. I remember having big troubles because of accidentally having two copies of
I agree we should not shadow everything. Also I could propose adding stuff from |
Is anybody working on this at the moment? If not, I'd be happy to volunteer :) I don't think I should be the one to publish the package on pypi or anything, but I could definitely do the preliminary work of pulling together the module for somebody to review, and work on making whatever changes are necessary to mypy itself. |
@Michael0x2a
|
I think that we should focus on things in Similarly, maybe |
This is a reasonable approach. Then my list above would be even simpler: |
I've started work on this, and ran into some complications I'd like to get some feedback on. First, I know we discussed up above that we wanted to minimize duplication, but I think it makes sense here to include the modified version of Second, the typing module seems to have been refactored between Python 3.5.2 and 3.5.3. In the older variant, you create new types by doing something like this: class UnionMeta(TypingMeta):
# Complicated code here
class Union(Final, metaclass=UnionMeta, _root=True):
# Simple code here In the newer variant, you instead do this: class _Union(_FinalTypingBase, _root=True):
# Complex code here
Union = _Union(_root=True) This causes some complications with the One solution is to copy over The other solution would be to re-implement I'm tentatively leaning towards the second solution -- thoughts? I don't think this last thing is that big of a deal, but the exact definition of some of the collections types were changed over time. For example, The question is whether we should include these modified types in However, I don't think this is a feature many people rely on (maybe except for people writing runtime type checkers?), so I'm planning on not including these modified types to minimize duplication. Does that sound correct, or should we backport the modified collection types anyways for the sake of consistency? A third option might be to rename any modified types in typing_extensions (e.g. provide a |
I hope Ivan can provide more guidance here, but I also hope that
typing_extensions.py doesn't end up containing a whole bunch of
reimplementations of stuff that's also in typing.py. I do accept that in
order to support the full range of released versions of typing.py, you may
need to implement some things in different ways -- hopefully checking
sys.version_info should suffice there (since typing.py release Python
versions anyway; I don't really want to support configurations where
someone installed e.g. typing.py 3.5.3 on Python 3.5.1).
|
I agree -- I'm also hoping to keep things as simple as possible. So far, it looks like NoReturn and ClassVar are the only two things that's going to require re-implementation in some way. Relatedly, maybe there's a third alternative to the NoReturn and ClassVar thing -- just eliminate as much of the runtime checks as possible and keep typing_extensions.py super minimal, just like mypy_extensions.py. We'd still have to re-implement NoReturn, ClassVar, and any future types we add, but would be free to keep that re-implementation really simple instead of trying to build it on top of older versions of typing.py. After all, I don't think anybody who's aware of typing_extensions to begin with is actually going to start abusing types... |
Oh, of course. If a dummy works for mypy_extensions.py it should work for
typing_extensions.py. It means they won't have great runtime introspection
but that's probably okay. So this should work at least for older typing.py
versions.
|
@Michael0x2a
If you have specific questions about the internal API, I will be glad to help. |
I have a first draft for this project here, if anybody is interested in reviewing it: https://github.com/michael0x2a/typing_extensions. (If I should make a pull request somewhere instead, let me know). While implementing this, I also made the following decisions:
Basically, I chose to favor emulating typing as closely as possible and backporting as much as possible possibly at the cost of simplicity. That may have been the wrong tradeoff to make -- in that case, I'm happy to go back and simply and remove some of the hacks I added in. Running tests: Because installing seven different versions of the Python interpreter just to test this module seemed a bit extreme, I wrote a test runner that only depends on the existence of Python 2.7.x and Python 3.6.1, and modifies PYTHONPATH that points to snapshots of relevant modules from standard library for each Python release. This should emulate running the tests against different versions of the Python standard library.
More specifically, the tests assume that |
I wonder if this could be done as a subdirectory of the existing typing repo? That way the link between the two is more obvious, and we may be more likely to update them in sync. (I think the idea is that stuff gets added to both, but typing_extensions gets released frequently, while typing.py only gets released in sync with CPython bugfix releases. |
This pull request adds a 'typing_exensions' subproject to 'typing'. The 'typing_extensions' module backports any new additions to 'typing' for Python 3.5+ users who are using older versions of 'typing' that were bundled with their standard library (and so can't update to the latest versions). See python#435 for motivation and additional context.
I think we should do it this way. |
This pull request adds a 'typing_exensions' subproject to 'typing'. The 'typing_extensions' module backports any new additions to 'typing' for Python 3.5+ users who are using older versions of 'typing' that were bundled with their standard library (and so can't update to the latest versions). See python#435 for motivation and additional context.
This pull request adds a 'typing_exensions' subproject to 'typing'. The 'typing_extensions' module backports any new additions to 'typing' for Python 3.5+ users who are using older versions of 'typing' that were bundled with their standard library (and so can't update to the latest versions). See python#435 for motivation and additional context.
This pull request adds a 'typing_exensions' subproject to 'typing'. The 'typing_extensions' module backports any new additions to 'typing' for Python 3.5+ users who are using older versions of 'typing' that were bundled with their standard library (and so can't update to the latest versions). As well, it will contain new experimental features than could eventually end up in 'typing'. See #435 for motivation and additional context.
|
I think that we should wait some more to see if these features will be actively used by users. Looking at Dropbox internal repos, extended |
One of the best features of TypeScript is interfaces (mostly for me because of REST APIs), and Jetbrains (aka @vlasovskikh) has said, that they will support typing_extensions but not mypy_extensions, so, @ilevkivskyi , this is my vote for getting Of course, I don't know how "in-flux" |
We are planning to add Since we now have |
This pull request adds a 'typing_exensions' subproject to 'typing'. The 'typing_extensions' module backports any new additions to 'typing' for Python 3.5+ users who are using older versions of 'typing' that were bundled with their standard library (and so can't update to the latest versions). As well, it will contain new experimental features than could eventually end up in 'typing'. See python/typing#435 for motivation and additional context.
This pull request adds a 'typing_exensions' subproject to 'typing'. The 'typing_extensions' module backports any new additions to 'typing' for Python 3.5+ users who are using older versions of 'typing' that were bundled with their standard library (and so can't update to the latest versions). As well, it will contain new experimental features than could eventually end up in 'typing'. See python/typing#435 for motivation and additional context.
Let's add
typing_extensions
module to PyPI in addition to Mypy-specificmypy_extensions
.Currently new stuff in typing appears in
mypy_extensions
even though most of the new typing features are not Mypy-specific.In order to make new typing features available to 1) previous Python versions, 2) all type checkers I would suggest to move these features to
typing_extensions
.The good candidates for including in
typing_extensions
could be:NoReturn
(apparently already in PEP 484)Protocol
(draft PEP 544)TypedDict
?The text was updated successfully, but these errors were encountered: