Skip to content

Commit 3031d5b

Browse files
authored
more typing (#5840)
* rename typing * No test code modification rules * remove orphan TODOs * mro_entires * typing module name * typing_subst * typing.override * Comparable for typing * remove to_owned() from typing
1 parent 6905d43 commit 3031d5b

File tree

4 files changed

+170
-75
lines changed

4 files changed

+170
-75
lines changed

.github/copilot-instructions.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,27 @@ cargo run --features jit
183183
cargo run --features ssl
184184
```
185185

186+
## Test Code Modification Rules
187+
188+
**CRITICAL: Test code modification restrictions**
189+
- NEVER comment out or delete any test code lines except for removing `@unittest.expectedFailure` decorators and upper TODO comments
190+
- NEVER modify test assertions, test logic, or test data
191+
- When a test cannot pass due to missing language features, keep it as expectedFailure and document the reason
192+
- The only acceptable modifications to test files are:
193+
1. Removing `@unittest.expectedFailure` decorators and the upper TODO comments when tests actually pass
194+
2. Adding `@unittest.expectedFailure` decorators when tests cannot be fixed
195+
196+
**Examples of FORBIDDEN modifications:**
197+
- Commenting out test lines
198+
- Changing test assertions
199+
- Modifying test data or expected results
200+
- Removing test logic
201+
202+
**Correct approach when tests fail due to unsupported syntax:**
203+
- Keep the test as `@unittest.expectedFailure`
204+
- Document that it requires PEP 695 support
205+
- Focus on tests that can be fixed through Rust code changes only
206+
186207
## Documentation
187208

188209
- Check the [architecture document](architecture/architecture.md) for a high-level overview

Lib/test/test_typing.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ def test_alias(self):
373373
self.assertEqual(get_args(alias_3), (LiteralString,))
374374

375375
class TypeVarTests(BaseTestCase):
376-
# TODO: RUSTPYTHON
377376
def test_basic_plain(self):
378377
T = TypeVar('T')
379378
# T equals itself.
@@ -388,8 +387,6 @@ def test_basic_plain(self):
388387
self.assertIs(T.__infer_variance__, False)
389388
self.assertEqual(T.__module__, __name__)
390389

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

406-
# TODO: RUSTPYTHON
407403
def test_attributes(self):
408404
T_bound = TypeVar('T_bound', bound=int)
409405
self.assertEqual(T_bound.__name__, 'T_bound')
@@ -445,7 +441,6 @@ def test_typevar_subclass_type_error(self):
445441
with self.assertRaises(TypeError):
446442
issubclass(T, int)
447443

448-
# TODO: RUSTPYTHON
449444
def test_constrained_error(self):
450445
with self.assertRaises(TypeError):
451446
X = TypeVar('X', int)
@@ -478,7 +473,6 @@ def test_union_constrained(self):
478473
A = TypeVar('A', str, bytes)
479474
self.assertNotEqual(Union[A, str], Union[A])
480475

481-
# TODO: RUSTPYTHON
482476
def test_repr(self):
483477
self.assertEqual(repr(T), '~T')
484478
self.assertEqual(repr(KT), '~KT')
@@ -493,7 +487,6 @@ def test_no_redefinition(self):
493487
self.assertNotEqual(TypeVar('T'), TypeVar('T'))
494488
self.assertNotEqual(TypeVar('T', int, str), TypeVar('T', int, str))
495489

496-
# TODO: RUSTPYTHON
497490
def test_cannot_subclass(self):
498491
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'TypeVar'):
499492
class V(TypeVar): pass
@@ -573,7 +566,6 @@ def test_many_weakrefs(self):
573566
vals[x] = cls(str(x))
574567
del vals
575568

576-
# TODO: RUSTPYTHON
577569
def test_constructor(self):
578570
T = TypeVar(name="T")
579571
self.assertEqual(T.__name__, "T")
@@ -654,7 +646,6 @@ class X[T]: ...
654646
self.assertIs(T.__default__, NoDefault)
655647
self.assertFalse(T.has_default())
656648

657-
# TODO: RUSTPYTHON
658649
def test_paramspec(self):
659650
P = ParamSpec('P', default=(str, int))
660651
self.assertEqual(P.__default__, (str, int))
@@ -682,7 +673,6 @@ class X[**P]: ...
682673
self.assertIs(P.__default__, NoDefault)
683674
self.assertFalse(P.has_default())
684675

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

12851275
class TypeVarTupleTests(BaseTestCase):
12861276

1287-
# TODO: RUSTPYTHON
12881277
def test_name(self):
12891278
Ts = TypeVarTuple('Ts')
12901279
self.assertEqual(Ts.__name__, 'Ts')
12911280
Ts2 = TypeVarTuple('Ts2')
12921281
self.assertEqual(Ts2.__name__, 'Ts2')
12931282

1294-
# TODO: RUSTPYTHON
12951283
def test_module(self):
12961284
Ts = TypeVarTuple('Ts')
12971285
self.assertEqual(Ts.__module__, __name__)
12981286

1299-
# TODO: RUSTPYTHON
1300-
@unittest.expectedFailure
13011287
def test_exec(self):
13021288
ns = {}
13031289
exec('from typing import TypeVarTuple; Ts = TypeVarTuple("Ts")', ns)
@@ -4270,7 +4256,6 @@ class Node(Generic[T]): ...
42704256
self.assertEqual(t, copy(t))
42714257
self.assertEqual(t, deepcopy(t))
42724258

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

87938778
class ParamSpecTests(BaseTestCase):
87948779

8795-
# TODO: RUSTPYTHON
87968780
def test_basic_plain(self):
87978781
P = ParamSpec('P')
87988782
self.assertEqual(P, P)
87998783
self.assertIsInstance(P, ParamSpec)
88008784
self.assertEqual(P.__name__, 'P')
88018785
self.assertEqual(P.__module__, __name__)
88028786

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

9003-
# TODO: RUSTPYTHON
90048985
def test_var_substitution(self):
90058986
P = ParamSpec("P")
90068987
subst = P.__typing_subst__
@@ -9011,7 +8992,6 @@ def test_var_substitution(self):
90118992
self.assertIs(subst(P), P)
90128993
self.assertEqual(subst(Concatenate[int, P]), Concatenate[int, P])
90138994

9014-
# TODO: RUSTPYTHON
90158995
def test_bad_var_substitution(self):
90168996
T = TypeVar('T')
90178997
P = ParamSpec('P')
@@ -9191,8 +9171,6 @@ def test_paramspec_gets_copied(self):
91919171
self.assertEqual(C2[Concatenate[str, P2]].__parameters__, (P2,))
91929172
self.assertEqual(C2[Concatenate[T, P2]].__parameters__, (T, P2))
91939173

9194-
# TODO: RUSTPYTHON
9195-
@unittest.expectedFailure
91969174
def test_cannot_subclass(self):
91979175
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'ParamSpec'):
91989176
class C(ParamSpec): pass
@@ -9229,7 +9207,6 @@ def test_dir(self):
92299207
with self.subTest(required_item=required_item):
92309208
self.assertIn(required_item, dir_items)
92319209

9232-
# TODO: RUSTPYTHON
92339210
def test_valid_uses(self):
92349211
P = ParamSpec('P')
92359212
T = TypeVar('T')

vm/src/frame.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
protocol::{PyIter, PyIterReturn},
1818
scope::Scope,
1919
source::SourceLocation,
20-
stdlib::{builtins, typing::_typing},
20+
stdlib::{builtins, typing},
2121
vm::{Context, PyMethod},
2222
};
2323
use indexmap::IndexMap;
@@ -1234,7 +1234,7 @@ impl ExecutingFrame<'_> {
12341234
bytecode::Instruction::TypeVar => {
12351235
let type_name = self.pop_value();
12361236
let type_var: PyObjectRef =
1237-
_typing::make_typevar(vm, type_name.clone(), vm.ctx.none(), vm.ctx.none())
1237+
typing::make_typevar(vm, type_name.clone(), vm.ctx.none(), vm.ctx.none())
12381238
.into_ref(&vm.ctx)
12391239
.into();
12401240
self.push_value(type_var);
@@ -1244,7 +1244,7 @@ impl ExecutingFrame<'_> {
12441244
let type_name = self.pop_value();
12451245
let bound = self.pop_value();
12461246
let type_var: PyObjectRef =
1247-
_typing::make_typevar(vm, type_name.clone(), bound, vm.ctx.none())
1247+
typing::make_typevar(vm, type_name.clone(), bound, vm.ctx.none())
12481248
.into_ref(&vm.ctx)
12491249
.into();
12501250
self.push_value(type_var);
@@ -1254,7 +1254,7 @@ impl ExecutingFrame<'_> {
12541254
let type_name = self.pop_value();
12551255
let constraint = self.pop_value();
12561256
let type_var: PyObjectRef =
1257-
_typing::make_typevar(vm, type_name.clone(), vm.ctx.none(), constraint)
1257+
typing::make_typevar(vm, type_name.clone(), vm.ctx.none(), constraint)
12581258
.into_ref(&vm.ctx)
12591259
.into();
12601260
self.push_value(type_var);
@@ -1267,13 +1267,13 @@ impl ExecutingFrame<'_> {
12671267
.downcast()
12681268
.map_err(|_| vm.new_type_error("Type params must be a tuple."))?;
12691269
let value = self.pop_value();
1270-
let type_alias = _typing::TypeAliasType::new(name, type_params, value);
1270+
let type_alias = typing::TypeAliasType::new(name, type_params, value);
12711271
self.push_value(type_alias.into_ref(&vm.ctx).into());
12721272
Ok(None)
12731273
}
12741274
bytecode::Instruction::ParamSpec => {
12751275
let param_spec_name = self.pop_value();
1276-
let param_spec: PyObjectRef = _typing::make_paramspec(param_spec_name.clone())
1276+
let param_spec: PyObjectRef = typing::make_paramspec(param_spec_name.clone())
12771277
.into_ref(&vm.ctx)
12781278
.into();
12791279
self.push_value(param_spec);
@@ -1282,7 +1282,7 @@ impl ExecutingFrame<'_> {
12821282
bytecode::Instruction::TypeVarTuple => {
12831283
let type_var_tuple_name = self.pop_value();
12841284
let type_var_tuple: PyObjectRef =
1285-
_typing::make_typevartuple(type_var_tuple_name.clone(), vm)
1285+
typing::make_typevartuple(type_var_tuple_name.clone(), vm)
12861286
.into_ref(&vm.ctx)
12871287
.into();
12881288
self.push_value(type_var_tuple);

0 commit comments

Comments
 (0)