diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-08-23 15:42:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-23 15:42:08 (GMT) |
commit | 3f61cf646d0506baa0c0c2118f05110446519c62 (patch) | |
tree | 0422bf72d76cdcdbb8387f761a429f2402b05baf /Lib/test/typinganndata | |
parent | f5559f38d9831e7e55a518e516bcd620ec13af14 (diff) | |
download | cpython-3f61cf646d0506baa0c0c2118f05110446519c62.zip cpython-3f61cf646d0506baa0c0c2118f05110446519c62.tar.gz cpython-3f61cf646d0506baa0c0c2118f05110446519c62.tar.bz2 |
gh-108303: Move `ann_module*.py` files to `typinganndata/` folder (#108354)
Diffstat (limited to 'Lib/test/typinganndata')
-rw-r--r-- | Lib/test/typinganndata/ann_module.py | 62 | ||||
-rw-r--r-- | Lib/test/typinganndata/ann_module2.py | 36 | ||||
-rw-r--r-- | Lib/test/typinganndata/ann_module3.py | 18 | ||||
-rw-r--r-- | Lib/test/typinganndata/ann_module4.py | 5 | ||||
-rw-r--r-- | Lib/test/typinganndata/ann_module5.py | 10 | ||||
-rw-r--r-- | Lib/test/typinganndata/ann_module6.py | 7 | ||||
-rw-r--r-- | Lib/test/typinganndata/ann_module7.py | 11 | ||||
-rw-r--r-- | Lib/test/typinganndata/ann_module8.py | 10 |
8 files changed, 159 insertions, 0 deletions
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: + ... |