[Python-ideas] Moving typing out of the stdlib in Python 3.7?
desmoulinmichel at gmail.com
Sat Nov 4 13:09:57 EDT 2017
I could see the typing module staying but:
- typing_extension (or the new official external module) append types in
the typing module;
- if typing_extension is not installed or too old and missing some
types, any missing type being accessed returns some kind of mock object
that avoid crashing;
- any running type checker encountering mocked types has to show a warning
- you can pip install typing (and it's mocking abilities) in python 2.
This way somebody without the 3rd party module can still use the code
without crashing it. Having types out of date or missing a brand new one
won't crash the code, only have a warning in mypy or pycharm.
This solves the compatibility problem, but also another major problem
currently: several projects I worked on had a fake typing module I could
use it in python 2 and 3 without having to manually install typing.
Sometime I also create scripts and leave type annotations, and my users
really don't want to install the exact typing extension to make it work.
And I don't want to remove the annotations manually after ward.
Le 03/11/2017 à 15:51, Chris Angelico a écrit :
> On Sat, Nov 4, 2017 at 1:49 AM, Guido van Rossum <guido at python.org> wrote:
>> On Fri, Nov 3, 2017 at 7:45 AM, Chris Angelico <rosuav at gmail.com> wrote:
>>> On Sat, Nov 4, 2017 at 1:35 AM, Guido van Rossum <guido at python.org> wrote:
>>>> [A copy from https://github.com/python/typing/issues/495 to get more
>>>> people's attention to this issue.]
>>>> I'm wondering if we should remove typing from the stdlib. Now's the time
>>>> think about this, as the feature freeze for 3.7 is about 12 weeks away.
>>>> People have to depend on a PyPI package to use typing (but they do
>>>> for typing_extensions)
>>> If the lazy evaluation of annotations (PEP 563) also lands in 3.7,
>>> then this would be a very minor downside. You'd need to pip-install
>>> typing as well as mypy *for the actual type checking*, but at run
>>> time, you could ignore both (all those List[...] annotations would be
>>> stored unevaluated). Otherwise, it'd mean that any project that makes
>>> use of type hints would require typing as a run-time dependency.
>> This would not work if you use TypeVar, NewType, or any kind of type alias
>> involving things imported from typing (e.g. Union or TypedDict). Also
> Ah, I forgot about those - they're not just used in the annotations.
> Oh well, was a nice idea.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas