Skip to content

Missing issues with CPython tests #1

@JanEricNitschke

Description

@JanEricNitschke
  • Pickling of typing_extensions.AsyncContextManager[Any] and typing_extensions.ContextManager[Any] goes through _GenericAlias whose __reduce__ is
    def __reduce__(self):
        if self._name:
            origin = globals()[self._name]
        else:
            origin = self.__origin__
        args = tuple(self.__args__)
        if len(args) == 1 and not isinstance(args[0], tuple):
            args, = args
        return operator.getitem, (origin, args)

and grabs typing.AsyncContextManager instead of typing_extensions.AsyncContextManager. Not sure how to solve

  • There are explicit checks AGAINST what we are backporting in 3.12 for AsyncContextManager:
    • Added a sed to fix it
        self.assertEqual(typing.AsyncContextManager[int].__args__, (int,))
        with self.assertRaises(TypeError):
            isinstance(42, typing.AsyncContextManager[int])
        with self.assertRaises(TypeError):
            typing.AsyncContextManager[int, str]

  • ParamSpec (and others) __module__ gets set to __main__ instead of None on exec:
    def test_basic_with_exec(self):
        ns = {}
        exec('from typing_extensions import ParamSpec; P = ParamSpec("P")', ns, ns)
        P = ns['P']
        self.assertIsInstance(P, ParamSpec)
        self.assertEqual(P.__name__, 'P')
        self.assertIs(P.__module__, None)

And in typing extensions we have:

    class ParamSpec(metaclass=_TypeVarLikeMeta):
        def __new__(cls, name, *, bound=None,
                    covariant=False, contravariant=False,
                    infer_variance=False, default=NoDefault):
            ...
            _set_module(paramspec)


def _set_module(typevarlike):
    # for pickling:
    def_mod = _caller(depth=2)
    if def_mod != 'typing_extensions':
        typevarlike.__module__ = def_mod


def _caller(depth=1, default='__main__'):
    try:
        return sys._getframemodulename(depth + 1) or default
    except AttributeError:  # For platforms without _getframemodulename()
        pass
    try:
        return sys._getframe(depth + 1).f_globals.get('__name__', default)
    except (AttributeError, ValueError):  # For platforms without _getframe()
        pass
    return None
FAIL: test_base_class (__main__.DataclassTransformTests.test_base_class)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<stdin>", line 8583, in test_base_class
AssertionError: {'eq_[62 chars]e, 'frozen_default': False, 'field_specifiers'[45 chars]rue}} != {'eq_[62 chars]e, 'field_specifiers': (), 'kwargs': {'make_ev[20 chars]rue}}
  {'eq_default': True,
   'field_specifiers': (),
-  'frozen_default': False,
   'kw_only_default': False,
   'kwargs': {'make_everything_awesome': True},
   'order_default': True}

  • Overload registry:
    • Testing typing internals, dont think its worth to debug. Can be skipped with a sed.
======================================================================
FAIL: test_overload_registry (__main__.OverloadTests.test_overload_registry)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/unittest/mock.py", line 1378, in patched
    return func(*newargs, **newkeywargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<stdin>", line 5256, in test_overload_registry
AssertionError: defaultdict(<function OverloadTests.<lambda> at 0x7f6150560860>, {}) == {}

  • TypeVarTupleTests.test_bad_var_substitution: no error raised

    • The issue is that TypeVar __typing_subst__ has this check if ((isinstance(arg, typing._GenericAlias) and arg.__origin__ is typing.Unpack)
    • Can be fixed with a monkey patch
  • Unpack repr syntax

    • Changed because of using in hinting kwargs.
  • 3.10/3.9 Any tests

    • Any used to not be subclassable or useable in issubclass.
    • This has changed and we are backporting this ability.
    • Tests can be skipped with sed
  • ConcatenateTests

    • Change in CPython from 3.10 -> 3.11 to allow "C = Concatenate[T, P]; C[int, ...]"
    • Change to allow ellipsis in second position, we are backporting that. So test needs to be fixed
  • 3.10/3.9 Implicit Option right: 'Node[T]' = None,

  • Pickling and printing errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions