From 3f61cf646d0506baa0c0c2118f05110446519c62 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Wed, 23 Aug 2023 18:42:08 +0300 Subject: gh-108303: Move `ann_module*.py` files to `typinganndata/` folder (#108354) --- Lib/test/ann_module.py | 62 ----------------------------------- Lib/test/ann_module2.py | 36 -------------------- Lib/test/ann_module3.py | 18 ---------- Lib/test/ann_module4.py | 5 --- Lib/test/ann_module5.py | 10 ------ Lib/test/ann_module6.py | 7 ---- Lib/test/ann_module7.py | 11 ------- Lib/test/ann_module8.py | 10 ------ Lib/test/test_grammar.py | 6 ++-- Lib/test/test_inspect.py | 2 +- Lib/test/test_module/__init__.py | 4 ++- Lib/test/test_opcodes.py | 3 +- Lib/test/test_typing.py | 6 ++-- Lib/test/typinganndata/ann_module.py | 62 +++++++++++++++++++++++++++++++++++ Lib/test/typinganndata/ann_module2.py | 36 ++++++++++++++++++++ Lib/test/typinganndata/ann_module3.py | 18 ++++++++++ Lib/test/typinganndata/ann_module4.py | 5 +++ Lib/test/typinganndata/ann_module5.py | 10 ++++++ Lib/test/typinganndata/ann_module6.py | 7 ++++ Lib/test/typinganndata/ann_module7.py | 11 +++++++ Lib/test/typinganndata/ann_module8.py | 10 ++++++ 21 files changed, 172 insertions(+), 167 deletions(-) delete mode 100644 Lib/test/ann_module.py delete mode 100644 Lib/test/ann_module2.py delete mode 100644 Lib/test/ann_module3.py delete mode 100644 Lib/test/ann_module4.py delete mode 100644 Lib/test/ann_module5.py delete mode 100644 Lib/test/ann_module6.py delete mode 100644 Lib/test/ann_module7.py delete mode 100644 Lib/test/ann_module8.py create mode 100644 Lib/test/typinganndata/ann_module.py create mode 100644 Lib/test/typinganndata/ann_module2.py create mode 100644 Lib/test/typinganndata/ann_module3.py create mode 100644 Lib/test/typinganndata/ann_module4.py create mode 100644 Lib/test/typinganndata/ann_module5.py create mode 100644 Lib/test/typinganndata/ann_module6.py create mode 100644 Lib/test/typinganndata/ann_module7.py create mode 100644 Lib/test/typinganndata/ann_module8.py diff --git a/Lib/test/ann_module.py b/Lib/test/ann_module.py deleted file mode 100644 index 5081e6b..0000000 --- a/Lib/test/ann_module.py +++ /dev/null @@ -1,62 +0,0 @@ - - -""" -The module for testing variable annotations. -Empty lines above are for good reason (testing for correct line numbers) -""" - -from typing import Optional -from functools import wraps - -__annotations__[1] = 2 - -class C: - - x = 5; y: Optional['C'] = None - -from typing import Tuple -x: int = 5; y: str = x; f: Tuple[int, int] - -class M(type): - - __annotations__['123'] = 123 - o: type = object - -(pars): bool = True - -class D(C): - j: str = 'hi'; k: str= 'bye' - -from types import new_class -h_class = new_class('H', (C,)) -j_class = new_class('J') - -class F(): - z: int = 5 - def __init__(self, x): - pass - -class Y(F): - def __init__(self): - super(F, self).__init__(123) - -class Meta(type): - def __new__(meta, name, bases, namespace): - return super().__new__(meta, name, bases, namespace) - -class S(metaclass = Meta): - x: str = 'something' - y: str = 'something else' - -def foo(x: int = 10): - def bar(y: List[str]): - x: str = 'yes' - bar() - -def dec(func): - @wraps(func) - def wrapper(*args, **kwargs): - return func(*args, **kwargs) - return wrapper - -u: int | float diff --git a/Lib/test/ann_module2.py b/Lib/test/ann_module2.py deleted file mode 100644 index 76cf5b3..0000000 --- a/Lib/test/ann_module2.py +++ /dev/null @@ -1,36 +0,0 @@ -""" -Some correct syntax for variable annotation here. -More examples are in test_grammar and test_parser. -""" - -from typing import no_type_check, ClassVar - -i: int = 1 -j: int -x: float = i/10 - -def f(): - class C: ... - return C() - -f().new_attr: object = object() - -class C: - def __init__(self, x: int) -> None: - self.x = x - -c = C(5) -c.new_attr: int = 10 - -__annotations__ = {} - - -@no_type_check -class NTC: - def meth(self, param: complex) -> None: - ... - -class CV: - var: ClassVar['CV'] - -CV.var = CV() diff --git a/Lib/test/ann_module3.py b/Lib/test/ann_module3.py deleted file mode 100644 index eccd7be..0000000 --- a/Lib/test/ann_module3.py +++ /dev/null @@ -1,18 +0,0 @@ -""" -Correct syntax for variable annotation that should fail at runtime -in a certain manner. More examples are in test_grammar and test_parser. -""" - -def f_bad_ann(): - __annotations__[1] = 2 - -class C_OK: - def __init__(self, x: int) -> None: - self.x: no_such_name = x # This one is OK as proposed by Guido - -class D_bad_ann: - def __init__(self, x: int) -> None: - sfel.y: int = 0 - -def g_bad_ann(): - no_such_name.attr: int = 0 diff --git a/Lib/test/ann_module4.py b/Lib/test/ann_module4.py deleted file mode 100644 index 13e9aee..0000000 --- a/Lib/test/ann_module4.py +++ /dev/null @@ -1,5 +0,0 @@ -# This ann_module isn't for test_typing, -# it's for test_module - -a:int=3 -b:str=4 diff --git a/Lib/test/ann_module5.py b/Lib/test/ann_module5.py deleted file mode 100644 index 837041e..0000000 --- a/Lib/test/ann_module5.py +++ /dev/null @@ -1,10 +0,0 @@ -# Used by test_typing to verify that Final wrapped in ForwardRef works. - -from __future__ import annotations - -from typing import Final - -name: Final[str] = "final" - -class MyClass: - value: Final = 3000 diff --git a/Lib/test/ann_module6.py b/Lib/test/ann_module6.py deleted file mode 100644 index 6791756..0000000 --- a/Lib/test/ann_module6.py +++ /dev/null @@ -1,7 +0,0 @@ -# Tests that top-level ClassVar is not allowed - -from __future__ import annotations - -from typing import ClassVar - -wrong: ClassVar[int] = 1 diff --git a/Lib/test/ann_module7.py b/Lib/test/ann_module7.py deleted file mode 100644 index 8f890cd..0000000 --- a/Lib/test/ann_module7.py +++ /dev/null @@ -1,11 +0,0 @@ -# Tests class have ``__text_signature__`` - -from __future__ import annotations - -DEFAULT_BUFFER_SIZE = 8192 - -class BufferedReader(object): - """BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n--\n\n - Create a new buffered reader using the given readable raw IO object. - """ - pass diff --git a/Lib/test/ann_module8.py b/Lib/test/ann_module8.py deleted file mode 100644 index bd03148..0000000 --- a/Lib/test/ann_module8.py +++ /dev/null @@ -1,10 +0,0 @@ -# Test `@no_type_check`, -# see https://bugs.python.org/issue46571 - -class NoTypeCheck_Outer: - class Inner: - x: int - - -def NoTypeCheck_function(arg: int) -> int: - ... diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index ee105a3..8507a07 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -12,9 +12,9 @@ from sys import * # different import patterns to check that __annotations__ does not interfere # with import machinery -import test.ann_module as ann_module +import test.typinganndata.ann_module as ann_module import typing -from test import ann_module2 +from test.typinganndata import ann_module2 import test # These are shared with test_tokenize and other test modules. @@ -452,7 +452,7 @@ class GrammarTests(unittest.TestCase): def test_var_annot_in_module(self): # check that functions fail the same way when executed # outside of module where they were defined - ann_module3 = import_helper.import_fresh_module("test.ann_module3") + ann_module3 = import_helper.import_fresh_module("test.typinganndata.ann_module3") with self.assertRaises(NameError): ann_module3.f_bad_ann() with self.assertRaises(NameError): diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 07c48ea..9cb92c0 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -4726,7 +4726,7 @@ class TestSignatureDefinitions(unittest.TestCase): def test_base_class_have_text_signature(self): # see issue 43118 - from test.ann_module7 import BufferedReader + from test.typinganndata.ann_module7 import BufferedReader class MyBufferedReader(BufferedReader): """buffer reader class.""" diff --git a/Lib/test/test_module/__init__.py b/Lib/test/test_module/__init__.py index cfc4d9c..2524e6c 100644 --- a/Lib/test/test_module/__init__.py +++ b/Lib/test/test_module/__init__.py @@ -324,7 +324,9 @@ a = A(destroyed)""" del foo.__annotations__ def test_annotations_are_created_correctly(self): - ann_module4 = import_helper.import_fresh_module('test.ann_module4') + ann_module4 = import_helper.import_fresh_module( + 'test.typinganndata.ann_module4', + ) self.assertTrue("__annotations__" in ann_module4.__dict__) del ann_module4.__annotations__ self.assertFalse("__annotations__" in ann_module4.__dict__) diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py index e880c3f..72488b2 100644 --- a/Lib/test/test_opcodes.py +++ b/Lib/test/test_opcodes.py @@ -1,7 +1,8 @@ # Python test set -- part 2, opcodes import unittest -from test import ann_module, support +from test import support +from test.typinganndata import ann_module class OpcodeTest(unittest.TestCase): diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index fa39c79..38baf95 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -5377,7 +5377,7 @@ class AssertTypeTests(BaseTestCase): # We need this to make sure that `@no_type_check` respects `__module__` attr: -from test import ann_module8 +from test.typinganndata import ann_module8 @no_type_check class NoTypeCheck_Outer: @@ -5968,7 +5968,9 @@ class OverloadTests(BaseTestCase): # Definitions needed for features introduced in Python 3.6 -from test import ann_module, ann_module2, ann_module3, ann_module5, ann_module6 +from test.typinganndata import ( + ann_module, ann_module2, ann_module3, ann_module5, ann_module6, +) T_a = TypeVar('T_a') diff --git a/Lib/test/typinganndata/ann_module.py b/Lib/test/typinganndata/ann_module.py new file mode 100644 index 0000000..5081e6b --- /dev/null +++ b/Lib/test/typinganndata/ann_module.py @@ -0,0 +1,62 @@ + + +""" +The module for testing variable annotations. +Empty lines above are for good reason (testing for correct line numbers) +""" + +from typing import Optional +from functools import wraps + +__annotations__[1] = 2 + +class C: + + x = 5; y: Optional['C'] = None + +from typing import Tuple +x: int = 5; y: str = x; f: Tuple[int, int] + +class M(type): + + __annotations__['123'] = 123 + o: type = object + +(pars): bool = True + +class D(C): + j: str = 'hi'; k: str= 'bye' + +from types import new_class +h_class = new_class('H', (C,)) +j_class = new_class('J') + +class F(): + z: int = 5 + def __init__(self, x): + pass + +class Y(F): + def __init__(self): + super(F, self).__init__(123) + +class Meta(type): + def __new__(meta, name, bases, namespace): + return super().__new__(meta, name, bases, namespace) + +class S(metaclass = Meta): + x: str = 'something' + y: str = 'something else' + +def foo(x: int = 10): + def bar(y: List[str]): + x: str = 'yes' + bar() + +def dec(func): + @wraps(func) + def wrapper(*args, **kwargs): + return func(*args, **kwargs) + return wrapper + +u: int | float diff --git a/Lib/test/typinganndata/ann_module2.py b/Lib/test/typinganndata/ann_module2.py new file mode 100644 index 0000000..76cf5b3 --- /dev/null +++ b/Lib/test/typinganndata/ann_module2.py @@ -0,0 +1,36 @@ +""" +Some correct syntax for variable annotation here. +More examples are in test_grammar and test_parser. +""" + +from typing import no_type_check, ClassVar + +i: int = 1 +j: int +x: float = i/10 + +def f(): + class C: ... + return C() + +f().new_attr: object = object() + +class C: + def __init__(self, x: int) -> None: + self.x = x + +c = C(5) +c.new_attr: int = 10 + +__annotations__ = {} + + +@no_type_check +class NTC: + def meth(self, param: complex) -> None: + ... + +class CV: + var: ClassVar['CV'] + +CV.var = CV() diff --git a/Lib/test/typinganndata/ann_module3.py b/Lib/test/typinganndata/ann_module3.py new file mode 100644 index 0000000..eccd7be --- /dev/null +++ b/Lib/test/typinganndata/ann_module3.py @@ -0,0 +1,18 @@ +""" +Correct syntax for variable annotation that should fail at runtime +in a certain manner. More examples are in test_grammar and test_parser. +""" + +def f_bad_ann(): + __annotations__[1] = 2 + +class C_OK: + def __init__(self, x: int) -> None: + self.x: no_such_name = x # This one is OK as proposed by Guido + +class D_bad_ann: + def __init__(self, x: int) -> None: + sfel.y: int = 0 + +def g_bad_ann(): + no_such_name.attr: int = 0 diff --git a/Lib/test/typinganndata/ann_module4.py b/Lib/test/typinganndata/ann_module4.py new file mode 100644 index 0000000..13e9aee --- /dev/null +++ b/Lib/test/typinganndata/ann_module4.py @@ -0,0 +1,5 @@ +# This ann_module isn't for test_typing, +# it's for test_module + +a:int=3 +b:str=4 diff --git a/Lib/test/typinganndata/ann_module5.py b/Lib/test/typinganndata/ann_module5.py new file mode 100644 index 0000000..837041e --- /dev/null +++ b/Lib/test/typinganndata/ann_module5.py @@ -0,0 +1,10 @@ +# Used by test_typing to verify that Final wrapped in ForwardRef works. + +from __future__ import annotations + +from typing import Final + +name: Final[str] = "final" + +class MyClass: + value: Final = 3000 diff --git a/Lib/test/typinganndata/ann_module6.py b/Lib/test/typinganndata/ann_module6.py new file mode 100644 index 0000000..6791756 --- /dev/null +++ b/Lib/test/typinganndata/ann_module6.py @@ -0,0 +1,7 @@ +# Tests that top-level ClassVar is not allowed + +from __future__ import annotations + +from typing import ClassVar + +wrong: ClassVar[int] = 1 diff --git a/Lib/test/typinganndata/ann_module7.py b/Lib/test/typinganndata/ann_module7.py new file mode 100644 index 0000000..8f890cd --- /dev/null +++ b/Lib/test/typinganndata/ann_module7.py @@ -0,0 +1,11 @@ +# Tests class have ``__text_signature__`` + +from __future__ import annotations + +DEFAULT_BUFFER_SIZE = 8192 + +class BufferedReader(object): + """BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n--\n\n + Create a new buffered reader using the given readable raw IO object. + """ + pass diff --git a/Lib/test/typinganndata/ann_module8.py b/Lib/test/typinganndata/ann_module8.py new file mode 100644 index 0000000..bd03148 --- /dev/null +++ b/Lib/test/typinganndata/ann_module8.py @@ -0,0 +1,10 @@ +# Test `@no_type_check`, +# see https://bugs.python.org/issue46571 + +class NoTypeCheck_Outer: + class Inner: + x: int + + +def NoTypeCheck_function(arg: int) -> int: + ... -- cgit v0.12