From 82e36dba45b750ad4ed68735eb05bb939968a1fa Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Wed, 8 Nov 2023 17:19:34 +0300 Subject: gh-108303: Move more `typing` related files to `Lib/test/typinganndata` (#111825) Co-authored-by: Alex Waygood --- Lib/test/_typed_dict_helper.py | 30 ---------------------------- Lib/test/mod_generics_cache.py | 24 ---------------------- Lib/test/test_type_aliases.py | 2 +- Lib/test/test_typing.py | 3 +-- Lib/test/typinganndata/_typed_dict_helper.py | 30 ++++++++++++++++++++++++++++ Lib/test/typinganndata/mod_generics_cache.py | 24 ++++++++++++++++++++++ 6 files changed, 56 insertions(+), 57 deletions(-) delete mode 100644 Lib/test/_typed_dict_helper.py delete mode 100644 Lib/test/mod_generics_cache.py create mode 100644 Lib/test/typinganndata/_typed_dict_helper.py create mode 100644 Lib/test/typinganndata/mod_generics_cache.py diff --git a/Lib/test/_typed_dict_helper.py b/Lib/test/_typed_dict_helper.py deleted file mode 100644 index 9df0ede..0000000 --- a/Lib/test/_typed_dict_helper.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Used to test `get_type_hints()` on a cross-module inherited `TypedDict` class - -This script uses future annotations to postpone a type that won't be available -on the module inheriting from to `Foo`. The subclass in the other module should -look something like this: - - class Bar(_typed_dict_helper.Foo, total=False): - b: int - -In addition, it uses multiple levels of Annotated to test the interaction -between the __future__ import, Annotated, and Required. -""" - -from __future__ import annotations - -from typing import Annotated, Generic, Optional, Required, TypedDict, TypeVar - - -OptionalIntType = Optional[int] - -class Foo(TypedDict): - a: OptionalIntType - -T = TypeVar("T") - -class FooGeneric(TypedDict, Generic[T]): - a: Optional[T] - -class VeryAnnotated(TypedDict, total=False): - a: Annotated[Annotated[Annotated[Required[int], "a"], "b"], "c"] diff --git a/Lib/test/mod_generics_cache.py b/Lib/test/mod_generics_cache.py deleted file mode 100644 index 6c1ee2f..0000000 --- a/Lib/test/mod_generics_cache.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Module for testing the behavior of generics across different modules.""" - -from typing import TypeVar, Generic, Optional, TypeAliasType - -default_a: Optional['A'] = None -default_b: Optional['B'] = None - -T = TypeVar('T') - - -class A(Generic[T]): - some_b: 'B' - - -class B(Generic[T]): - class A(Generic[T]): - pass - - my_inner_a1: 'B.A' - my_inner_a2: A - my_outer_a: 'A' # unless somebody calls get_type_hints with localns=B.__dict__ - -type Alias = int -OldStyle = TypeAliasType("OldStyle", int) diff --git a/Lib/test/test_type_aliases.py b/Lib/test/test_type_aliases.py index 8f0a998..9c325bc 100644 --- a/Lib/test/test_type_aliases.py +++ b/Lib/test/test_type_aliases.py @@ -2,7 +2,7 @@ import pickle import types import unittest from test.support import check_syntax_error, run_code -from test import mod_generics_cache +from test.typinganndata import mod_generics_cache from typing import Callable, TypeAliasType, TypeVar, get_args diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 6ff79e8..1e812e1 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -45,8 +45,7 @@ import weakref import types from test.support import captured_stderr, cpython_only, infinite_recursion -from test import mod_generics_cache -from test import _typed_dict_helper +from test.typinganndata import mod_generics_cache, _typed_dict_helper CANNOT_SUBCLASS_TYPE = 'Cannot subclass special typing classes' diff --git a/Lib/test/typinganndata/_typed_dict_helper.py b/Lib/test/typinganndata/_typed_dict_helper.py new file mode 100644 index 0000000..9df0ede --- /dev/null +++ b/Lib/test/typinganndata/_typed_dict_helper.py @@ -0,0 +1,30 @@ +"""Used to test `get_type_hints()` on a cross-module inherited `TypedDict` class + +This script uses future annotations to postpone a type that won't be available +on the module inheriting from to `Foo`. The subclass in the other module should +look something like this: + + class Bar(_typed_dict_helper.Foo, total=False): + b: int + +In addition, it uses multiple levels of Annotated to test the interaction +between the __future__ import, Annotated, and Required. +""" + +from __future__ import annotations + +from typing import Annotated, Generic, Optional, Required, TypedDict, TypeVar + + +OptionalIntType = Optional[int] + +class Foo(TypedDict): + a: OptionalIntType + +T = TypeVar("T") + +class FooGeneric(TypedDict, Generic[T]): + a: Optional[T] + +class VeryAnnotated(TypedDict, total=False): + a: Annotated[Annotated[Annotated[Required[int], "a"], "b"], "c"] diff --git a/Lib/test/typinganndata/mod_generics_cache.py b/Lib/test/typinganndata/mod_generics_cache.py new file mode 100644 index 0000000..6c1ee2f --- /dev/null +++ b/Lib/test/typinganndata/mod_generics_cache.py @@ -0,0 +1,24 @@ +"""Module for testing the behavior of generics across different modules.""" + +from typing import TypeVar, Generic, Optional, TypeAliasType + +default_a: Optional['A'] = None +default_b: Optional['B'] = None + +T = TypeVar('T') + + +class A(Generic[T]): + some_b: 'B' + + +class B(Generic[T]): + class A(Generic[T]): + pass + + my_inner_a1: 'B.A' + my_inner_a2: A + my_outer_a: 'A' # unless somebody calls get_type_hints with localns=B.__dict__ + +type Alias = int +OldStyle = TypeAliasType("OldStyle", int) -- cgit v0.12