mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Replace old anndata to new from CPython 3.13.5
This commit is contained in:
18
Lib/test/_typed_dict_helper.py
vendored
18
Lib/test/_typed_dict_helper.py
vendored
@@ -1,18 +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
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, TypedDict
|
||||
|
||||
OptionalIntType = Optional[int]
|
||||
|
||||
class Foo(TypedDict):
|
||||
a: OptionalIntType
|
||||
62
Lib/test/ann_module.py
vendored
62
Lib/test/ann_module.py
vendored
@@ -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
|
||||
36
Lib/test/ann_module2.py
vendored
36
Lib/test/ann_module2.py
vendored
@@ -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()
|
||||
18
Lib/test/ann_module3.py
vendored
18
Lib/test/ann_module3.py
vendored
@@ -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
|
||||
5
Lib/test/ann_module4.py
vendored
5
Lib/test/ann_module4.py
vendored
@@ -1,5 +0,0 @@
|
||||
# This ann_module isn't for test_typing,
|
||||
# it's for test_module
|
||||
|
||||
a:int=3
|
||||
b:str=4
|
||||
10
Lib/test/ann_module5.py
vendored
10
Lib/test/ann_module5.py
vendored
@@ -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
|
||||
7
Lib/test/ann_module6.py
vendored
7
Lib/test/ann_module6.py
vendored
@@ -1,7 +0,0 @@
|
||||
# Tests that top-level ClassVar is not allowed
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import ClassVar
|
||||
|
||||
wrong: ClassVar[int] = 1
|
||||
11
Lib/test/ann_module7.py
vendored
11
Lib/test/ann_module7.py
vendored
@@ -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
|
||||
53
Lib/test/mod_generics_cache.py
vendored
53
Lib/test/mod_generics_cache.py
vendored
@@ -1,53 +0,0 @@
|
||||
"""Module for testing the behavior of generics across different modules."""
|
||||
|
||||
import sys
|
||||
from textwrap import dedent
|
||||
from typing import TypeVar, Generic, Optional
|
||||
|
||||
|
||||
if sys.version_info[:2] >= (3, 6):
|
||||
exec(dedent("""
|
||||
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__
|
||||
"""))
|
||||
else: # This should stay in sync with the syntax above.
|
||||
__annotations__ = dict(
|
||||
default_a=Optional['A'],
|
||||
default_b=Optional['B'],
|
||||
)
|
||||
default_a = None
|
||||
default_b = None
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
class A(Generic[T]):
|
||||
__annotations__ = dict(
|
||||
some_b='B'
|
||||
)
|
||||
|
||||
|
||||
class B(Generic[T]):
|
||||
class A(Generic[T]):
|
||||
pass
|
||||
|
||||
__annotations__ = dict(
|
||||
my_inner_a1='B.A',
|
||||
my_inner_a2=A,
|
||||
my_outer_a='A' # unless somebody calls get_type_hints with localns=B.__dict__
|
||||
)
|
||||
2
Lib/test/test_grammar.py
vendored
2
Lib/test/test_grammar.py
vendored
@@ -400,7 +400,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
|
||||
from test.ann_module3 import f_bad_ann, g_bad_ann, D_bad_ann
|
||||
from test.typinganndata.ann_module3 import f_bad_ann, g_bad_ann, D_bad_ann
|
||||
with self.assertRaises(NameError):
|
||||
f_bad_ann()
|
||||
with self.assertRaises(NameError):
|
||||
|
||||
28
Lib/test/typinganndata/mod_generics_cache.py
vendored
28
Lib/test/typinganndata/mod_generics_cache.py
vendored
@@ -2,25 +2,23 @@
|
||||
|
||||
from typing import TypeVar, Generic, Optional, TypeAliasType
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
default_a: Optional['A'] = None
|
||||
default_b: Optional['B'] = None
|
||||
|
||||
# default_a: Optional['A'] = None
|
||||
# default_b: Optional['B'] = None
|
||||
|
||||
# T = TypeVar('T')
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
# class A(Generic[T]):
|
||||
# some_b: 'B'
|
||||
class A(Generic[T]):
|
||||
some_b: 'B'
|
||||
|
||||
|
||||
# class B(Generic[T]):
|
||||
# class A(Generic[T]):
|
||||
# pass
|
||||
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__
|
||||
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)
|
||||
type Alias = int
|
||||
OldStyle = TypeAliasType("OldStyle", int)
|
||||
|
||||
Reference in New Issue
Block a user