File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ assert type .__module__ == 'builtins'
2+ assert type .__qualname__ == 'type'
3+ assert type .__name__ == 'type'
4+ assert isinstance (type .__doc__ , str )
5+ assert object .__qualname__ == 'object'
6+ assert int .__qualname__ == 'int'
7+
8+
9+ class A (type ):
10+ pass
11+
12+
13+ class B (type ):
14+ __module__ = 'b'
15+ __qualname__ = 'BB'
16+
17+
18+ class C :
19+ pass
20+
21+
22+ class D :
23+ __module__ = 'd'
24+ __qualname__ = 'DD'
25+
26+
27+ assert A .__module__ == '__main__'
28+ assert A .__qualname__ == 'A'
29+ assert B .__module__ == 'b'
30+ assert B .__qualname__ == 'BB'
31+ assert C .__module__ == '__main__'
32+ assert C .__qualname__ == 'C'
33+ assert D .__module__ == 'd'
34+ assert D .__qualname__ == 'DD'
35+
36+
37+ # Regression to
38+ # https://github.com/RustPython/RustPython/issues/2310
39+ import builtins
40+ assert builtins .iter .__class__ .__module__ == 'builtins'
41+ assert builtins .iter .__class__ .__qualname__ == 'builtin_function_or_method'
42+
43+ assert iter .__class__ .__module__ == 'builtins'
44+ assert iter .__class__ .__qualname__ == 'builtin_function_or_method'
45+ assert type (iter ).__module__ == 'builtins'
46+ assert type (iter ).__qualname__ == 'builtin_function_or_method'
Original file line number Diff line number Diff line change @@ -306,6 +306,14 @@ impl PyType {
306306 . read ( )
307307 . get ( "__qualname__" )
308308 . cloned ( )
309+ // We need to exclude this method from going into recursion:
310+ . and_then ( |found| {
311+ if found. isinstance ( & vm. ctx . types . getset_type ) {
312+ None
313+ } else {
314+ Some ( found)
315+ }
316+ } )
309317 . unwrap_or_else ( || vm. ctx . new_str ( self . name . clone ( ) ) )
310318 }
311319
@@ -316,6 +324,14 @@ impl PyType {
316324 . read ( )
317325 . get ( "__module__" )
318326 . cloned ( )
327+ // We need to exclude this method from going into recursion:
328+ . and_then ( |found| {
329+ if found. isinstance ( & vm. ctx . types . getset_type ) {
330+ None
331+ } else {
332+ Some ( found)
333+ }
334+ } )
319335 . unwrap_or_else ( || vm. ctx . new_str ( "builtins" ) )
320336 }
321337
You can’t perform that action at this time.
0 commit comments