To implement a full version of PEP604
<https://www.python.org/dev/peps/pep-0604/>, I analyze the typing module,
started with _GenericAlias.
1) I must rewrite :

   - def _type_check(arg, msg, is_argument=True)
   - def _type_repr(obj)
   - def _collect_type_vars(types)
   - def _subs_tvars(tp, tvars, subs)
   - def _check_generic(cls, parameters)
   - def _remove_dups_flatten(parameters)
   - def _tp_cache(func)
   - class _Final
   - class _Immutable
   - class _SpecialForm(_Final, _Immutable, _root=True)
   - class ForwardRef(_Final, _root=True)
   - class TypeVar(_Final, _Immutable, _root=True)
   - def _is_dunder(attr)
   - class _GenericAlias(_Final, _root=True)
   - class Generic
   - class _TypingEmpty
   - class _TypingEllipsis
   - def _get_protocol_attrs(cls)
   - def _is_callable_members_only(cls)
   - def _allow_reckless_class_cheks()
   - class _ProtocolMeta(ABCMeta)
   - class Protocol(Generic, metaclass=_ProtocolMeta)

2) The function _tp_cache use functools.lru_cache()
def _tp_cache(func):
    cached = functools.lru_cache()(func)
it's not reasonable to move the lru_cache() in the core

3) The method TypeVar.__init__() use:
def_mod = sys._getframe(1).f_globals['__name__']  # for pickling

4) The method def _allow_reckless_class_cheks() use:
return sys._getframe(3).f_globals['__name__'] in ['abc', 'functools']

5) The method Protocol.__init_subclass___proto_hook() use:
if (isinstance(annotations, collections.abc.Mapping)
it's not reasonable to move the Mapping type in the core

It's not enough to move the typing classes, I must move
functools.lru_cache() and dependencies, collections.abs.Mapping and
dependencies, and track the frame level.

*It's too big for me.*

May be, the approach with only PEP 563 is enough.
from __future__ import annotations
a:int|str=3

This new syntax is only usable in annotations. Without runtime evaluation
and without modifying issubclass() and isinstance() may be acceptable. Only
the mypy (and others tools like this) must be updated.


Philippe
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NX6IIO4XZ56XNBWDEQBDF4PZ23NW32HZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to