8000 more typing by youknowone · Pull Request #5840 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

more typing #5840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/copilot-instructions.md
10000
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,27 @@ cargo run --features jit
cargo run --features ssl
```

## Test Code Modification Rules

**CRITICAL: Test code modification restrictions**
- NEVER comment out or delete any test code lines except for removing `@unittest.expectedFailure` decorators and upper TODO comments
- NEVER modify test assertions, test logic, or test data
- When a test cannot pass due to missing language features, keep it as expectedFailure and document the reason
- The only acceptable modifications to test files are:
1. Removing `@unittest.expectedFailure` decorators and the upper TODO comments when tests actually pass
2. Adding `@unittest.expectedFailure` decorators when tests cannot be fixed

**Examples of FORBIDDEN modifications:**
- Commenting out test lines
- Changing test assertions
- Modifying test data or expected results
- Removing test logic

**Correct approach when tests fail due to unsupported syntax:**
- Keep the test as `@unittest.expectedFailure`
- Document that it requires PEP 695 support
- Focus on tests that can be fixed through Rust code changes only

## Documentation

- Check the [architecture document](architecture/architecture.md) for a high-level overview
Expand Down
23 changes: 0 additions & 23 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ def test_alias(self):
self.assertEqual(get_args(alias_3), (LiteralString,))

class TypeVarTests(BaseTestCase):
# TODO: RUSTPYTHON
def test_basic_plain(self):
T = TypeVar('T')
# T equals itself.
Expand All @@ -388,8 +387,6 @@ def test_basic_plain(self):
self.assertIs(T.__infer_variance__, False)
self.assertEqual(T.__module__, __name__)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_basic_with_exec(self):
ns = {}
exec('from typing import TypeVar; T = TypeVar("T", bound=float)', ns, ns)
Expand All @@ -403,7 +400,6 @@ def test_basic_with_exec(self):
self.assertIs(T.__infer_variance__, False)
self.assertIs(T.__module__, None)

# TODO: RUSTPYTHON
def test_attributes(self):
T_bound = TypeVar('T_bound', bound=int)
self.assertEqual(T_bound.__name__, 'T_bound')
Expand Down Expand Up @@ -445,7 +441,6 @@ def test_typevar_subclass_type_error(self):
with self.assertRaises(TypeError):
issubclass(T, int)

# TODO: RUSTPYTHON
def test_constrained_error(self):
with self.assertRaises(TypeError):
X = TypeVar('X', int)
Expand Down Expand Up @@ -478,7 +473,6 @@ def test_union_constrained(self):
A = TypeVar('A', str, bytes)
self.assertNotEqual(Union[A, str], Union[A])

# TODO: RUSTPYTHON
def test_repr(self):
self.assertEqual(repr(T), '~T')
self.assertEqual(repr(KT), '~KT')
Expand All @@ -493,7 +487,6 @@ def test_no_redefinition(self):
self.assertNotEqual(TypeVar('T'), TypeVar('T'))
self.assertNotEqual(TypeVar('T', int, str), TypeVar('T', int, str))

# TODO: RUSTPYTHON
def test_cannot_subclass(self):
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'TypeVar'):
class V(TypeVar): pass
Expand Down Expand Up @@ -573,7 +566,6 @@ def test_many_weakrefs(self):
vals[x] = cls(str(x))
del vals

# TODO: RUSTPYTHON
def test_constructor(self):
T = TypeVar(name="T")
self.assertEqual(T.__name__, "T")
Expand Down Expand Up @@ -654,7 +646,6 @@ class X[T]: ...
self.assertIs(T.__default__, NoDefault)
self.assertFalse(T.has_default())

# TODO: RUSTPYTHON
def test_paramspec(self):
P = ParamSpec('P', default=(str, int))
self.assertEqual(P.__default__, (str, int))
Expand Down Expand Up @@ -682,7 +673,6 @@ class X[**P]: ...
self.assertIs(P.__default__, NoDefault)
self.assertFalse(P.has_default())

# TODO: RUSTPYTHON
def test_typevartuple(self):
Ts = TypeVarTuple('Ts', default=Unpack[Tuple[str, int]])
self.assertEqual(Ts.__default__, Unpack[Tuple[str, int]])
Expand Down Expand Up @@ -1284,20 +1274,16 @@ class Gen[*Ts]: ...

class TypeVarTupleTests(BaseTestCase):

# TODO: RUSTPYTHON
def test_name(self):
Ts = TypeVarTuple('Ts')
self.assertEqual(Ts.__name__, 'Ts')
Ts2 = TypeVarTuple('Ts2')
self.assertEqual(Ts2.__name__, 'Ts2')

# TODO: RUSTPYTHON
def test_module(self):
Ts = TypeVarTuple('Ts')
self.assertEqual(Ts.__module__, __name__)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_exec(self):
ns = {}
exec('from typing import TypeVarTuple; Ts = TypeVarTuple("Ts")', ns)
Expand Down Expand Up @@ -4270,7 +4256,6 @@ class Node(Generic[T]): ...
self.assertEqual(t, copy(t))
self.assertEqual(t, deepcopy(t))

# TODO: RUSTPYTHON
def test_immutability_by_copy_and_pickle(self):
# Special forms like Union, Any, etc., generic aliases to containers like List,
# Mapping, etc., and type variabcles are considered immutable by copy and pickle.
Expand Down Expand Up @@ -8792,16 +8777,13 @@ def test_cannot_subscript(self):

class ParamSpecTests(BaseTestCase):

# TODO: RUSTPYTHON
def test_basic_plain(self):
P = ParamSpec('P')
self.assertEqual(P, P)
self.assertIsInstance(P, ParamSpec)
self.assertEqual(P.__name__, 'P')
self.assertEqual(P.__module__, __name__)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_basic_with_exec(self):
ns = {}
exec('from typing import ParamSpec; P = ParamSpec("P")', ns, ns)
Expand Down Expand Up @@ -9000,7 +8982,6 @@ class Y(Generic[P, T]):
B = A[[int, str], bytes, float]
self.assertEqual(B.__args__, ((int, str,), Tuple[bytes, float]))

# TODO: RUSTPYTHON
def test_var_substitution(self):
P = ParamSpec("P")
subst = P.__typing_subst__
Expand All @@ -9011,7 +8992,6 @@ def test_var_substitution(self):
self.assertIs(subst(P), P)
self.assertEqual(subst(Concatenate[int, P]), Concatenate[int, P])

# TODO: RUSTPYTHON
def test_bad_var_substitution(self):
T = TypeVar('T')
P = ParamSpec('P')
Expand Down Expand Up @@ -9191,8 +9171,6 @@ def test_paramspec_gets_copied(self):
self.assertEqual(C2[Concatenate[str, P2]].__parameters__, (P2,))
self.assertEqual(C2[Concatenate[T, P2]].__parameters__, (T, P2))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_cannot_subclass(self):
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'ParamSpec'):
class C(ParamSpec): pass
Expand Down Expand Up @@ -9229,7 +9207,6 @@ def test_dir(self):
with self.subTest(required_item=required_item):
self.assertIn(required_item, dir_items)

# TODO: RUSTPYTHON
def test_valid_uses(self):
P = ParamSpec('P')
T = TypeVar('T')
Expand Down
14 changes: 7 additions & 7 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
protocol::{PyIter, PyIterReturn},
scope::Scope,
source::SourceLocation,
stdlib::{builtins, typing::_typing},
stdlib::{builtins, typing},
vm::{Context, PyMethod},
};
use indexmap::IndexMap;
Expand Down Expand Up @@ -1234,7 +1234,7 @@ impl ExecutingFrame<'_> {
bytecode::Instruction::TypeVar => {
let type_name = self.pop_value();
let type_var: PyObjectRef =
_typing::make_typevar(vm, type_name.clone(), vm.ctx.none(), vm.ctx.none())
typing::make_typevar(vm, type_name.clone(), vm.ctx.none(), vm.ctx.none())
.into_ref(&vm.ctx)
.into();
self.push_value(type_var);
Expand All @@ -1244,7 +1244,7 @@ impl ExecutingFrame<'_> {
let type_name = self.pop_value();
let bound = self.pop_value();
let type_var: PyObjectRef =
_typing::make_typevar(vm, type_name.clone(), bound, vm.ctx.none())
typing::make_typevar(vm, type_name.clone(), bound, vm.ctx.none())
.into_ref(&vm.ctx)
.into();
self.push_value(type_var);
Expand All @@ -1254,7 +1254,7 @@ impl ExecutingFrame<'_> {
let type_name = self.pop_value();
let constraint = self.pop_value();
let type_var: PyObjectRef =
_typing::make_typevar(vm, type_name.clone(), vm.ctx.none(), constraint)
typing::make_typevar(vm, type_name.clone(), vm.ctx.none(), constraint)
.into_ref(&vm.ctx)
.into();
self.push_value(type_var);
Expand All @@ -1267,13 +1267,13 @@ impl ExecutingFrame<'_> {
.downcast()
.map_err(|_| vm.new_type_error("Type params must be a tuple."))?;
let value = self.pop_value();
let type_alias = _typing::TypeAliasType::new(name, type_params, value);
let type_alias = typing::TypeAliasType::new(name, type_params, value);
self.push_value(type_alias.into_ref(&vm.ctx).into());
Ok(None)
}
bytecode::Instruction::ParamSpec => {
let param_spec_name = self.pop_value();
let param_spec: PyObjectRef = _typing::make_paramspec(param_spec_name.clone())
let param_spec: PyObjectRef = typing::make_paramspec(param_spec_name.clone())
.into_ref(&vm.ctx)
.into();
self.push_value(param_spec);
Expand All @@ -1282,7 +1282,7 @@ impl ExecutingFrame<'_> {
bytecode::Instruction::TypeVarTuple => {
let type_var_tuple_name = self.pop_value();
let type_var_tuple: PyObjectRef =
_typing::make_typevartuple(type_var_tuple_name.clone(), vm)
typing::make_typevartuple(type_var_tuple_name.clone(), vm)
.into_ref(&vm.ctx)
.into();
self.push_value(type_var_tuple);
Expand Down
Loading
Loading
0