Removed the Requirement to Install Python and NodeJS (Now Bundled with Borealis)
This commit is contained in:
0
Dependencies/Python/Lib/test/typinganndata/__init__.py
vendored
Normal file
0
Dependencies/Python/Lib/test/typinganndata/__init__.py
vendored
Normal file
30
Dependencies/Python/Lib/test/typinganndata/_typed_dict_helper.py
vendored
Normal file
30
Dependencies/Python/Lib/test/typinganndata/_typed_dict_helper.py
vendored
Normal file
@ -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"]
|
62
Dependencies/Python/Lib/test/typinganndata/ann_module.py
vendored
Normal file
62
Dependencies/Python/Lib/test/typinganndata/ann_module.py
vendored
Normal file
@ -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
|
36
Dependencies/Python/Lib/test/typinganndata/ann_module2.py
vendored
Normal file
36
Dependencies/Python/Lib/test/typinganndata/ann_module2.py
vendored
Normal file
@ -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()
|
18
Dependencies/Python/Lib/test/typinganndata/ann_module3.py
vendored
Normal file
18
Dependencies/Python/Lib/test/typinganndata/ann_module3.py
vendored
Normal file
@ -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
|
5
Dependencies/Python/Lib/test/typinganndata/ann_module4.py
vendored
Normal file
5
Dependencies/Python/Lib/test/typinganndata/ann_module4.py
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# This ann_module isn't for test_typing,
|
||||
# it's for test_module
|
||||
|
||||
a:int=3
|
||||
b:str=4
|
10
Dependencies/Python/Lib/test/typinganndata/ann_module5.py
vendored
Normal file
10
Dependencies/Python/Lib/test/typinganndata/ann_module5.py
vendored
Normal file
@ -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
|
7
Dependencies/Python/Lib/test/typinganndata/ann_module6.py
vendored
Normal file
7
Dependencies/Python/Lib/test/typinganndata/ann_module6.py
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Tests that top-level ClassVar is not allowed
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import ClassVar
|
||||
|
||||
wrong: ClassVar[int] = 1
|
72
Dependencies/Python/Lib/test/typinganndata/ann_module695.py
vendored
Normal file
72
Dependencies/Python/Lib/test/typinganndata/ann_module695.py
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
from __future__ import annotations
|
||||
from typing import Callable
|
||||
|
||||
|
||||
class A[T, *Ts, **P]:
|
||||
x: T
|
||||
y: tuple[*Ts]
|
||||
z: Callable[P, str]
|
||||
|
||||
|
||||
class B[T, *Ts, **P]:
|
||||
T = int
|
||||
Ts = str
|
||||
P = bytes
|
||||
x: T
|
||||
y: Ts
|
||||
z: P
|
||||
|
||||
|
||||
Eggs = int
|
||||
Spam = str
|
||||
|
||||
|
||||
class C[Eggs, **Spam]:
|
||||
x: Eggs
|
||||
y: Spam
|
||||
|
||||
|
||||
def generic_function[T, *Ts, **P](
|
||||
x: T, *y: *Ts, z: P.args, zz: P.kwargs
|
||||
) -> None: ...
|
||||
|
||||
|
||||
def generic_function_2[Eggs, **Spam](x: Eggs, y: Spam): pass
|
||||
|
||||
|
||||
class D:
|
||||
Foo = int
|
||||
Bar = str
|
||||
|
||||
def generic_method[Foo, **Bar](
|
||||
self, x: Foo, y: Bar
|
||||
) -> None: ...
|
||||
|
||||
def generic_method_2[Eggs, **Spam](self, x: Eggs, y: Spam): pass
|
||||
|
||||
|
||||
def nested():
|
||||
from types import SimpleNamespace
|
||||
from typing import get_type_hints
|
||||
|
||||
Eggs = bytes
|
||||
Spam = memoryview
|
||||
|
||||
|
||||
class E[Eggs, **Spam]:
|
||||
x: Eggs
|
||||
y: Spam
|
||||
|
||||
def generic_method[Eggs, **Spam](self, x: Eggs, y: Spam): pass
|
||||
|
||||
|
||||
def generic_function[Eggs, **Spam](x: Eggs, y: Spam): pass
|
||||
|
||||
|
||||
return SimpleNamespace(
|
||||
E=E,
|
||||
hints_for_E=get_type_hints(E),
|
||||
hints_for_E_meth=get_type_hints(E.generic_method),
|
||||
generic_func=generic_function,
|
||||
hints_for_generic_func=get_type_hints(generic_function)
|
||||
)
|
11
Dependencies/Python/Lib/test/typinganndata/ann_module7.py
vendored
Normal file
11
Dependencies/Python/Lib/test/typinganndata/ann_module7.py
vendored
Normal file
@ -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
|
10
Dependencies/Python/Lib/test/typinganndata/ann_module8.py
vendored
Normal file
10
Dependencies/Python/Lib/test/typinganndata/ann_module8.py
vendored
Normal file
@ -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:
|
||||
...
|
14
Dependencies/Python/Lib/test/typinganndata/ann_module9.py
vendored
Normal file
14
Dependencies/Python/Lib/test/typinganndata/ann_module9.py
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# Test ``inspect.formatannotation``
|
||||
# https://github.com/python/cpython/issues/96073
|
||||
|
||||
from typing import Union, List
|
||||
|
||||
ann = Union[List[str], int]
|
||||
|
||||
# mock typing._type_repr behaviour
|
||||
class A: ...
|
||||
|
||||
A.__module__ = 'testModule.typing'
|
||||
A.__qualname__ = 'A'
|
||||
|
||||
ann1 = Union[List[A], int]
|
24
Dependencies/Python/Lib/test/typinganndata/mod_generics_cache.py
vendored
Normal file
24
Dependencies/Python/Lib/test/typinganndata/mod_generics_cache.py
vendored
Normal file
@ -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)
|
Reference in New Issue
Block a user