@@ -123,10 +123,12 @@ def test_basic_ref(self):
123123    def  test_ref_repr (self ):
124124        obj  =  C ()
125125        ref  =  weakref .ref (obj )
126-         self .assertRegex (repr (ref ),
127-                          rf"<weakref at 0x[0-9a-fA-F]+; " 
128-                          rf"to '{ C .__module__ } { C .__qualname__ }  
129-                          rf"at 0x[0-9a-fA-F]+>" )
126+         regex  =  (
127+             rf"<weakref at 0x[0-9a-fA-F]+; " 
128+             rf"to '{ ''  if  __name__  ==  '__main__'  else  C .__module__  +  '.' } { C .__qualname__ }  
129+             rf"at 0x[0-9a-fA-F]+>" 
130+         )
131+         self .assertRegex (repr (ref ), regex )
130132
131133        obj  =  None 
132134        gc_collect ()
@@ -141,10 +143,13 @@ def __name__(self):
141143
142144        obj2  =  WithName ()
143145        ref2  =  weakref .ref (obj2 )
144-         self .assertRegex (repr (ref2 ),
145-                          rf"<weakref at 0x[0-9a-fA-F]+; " 
146-                          rf"to '{ WithName .__module__ } { WithName .__qualname__ }  
147-                          rf"at 0x[0-9a-fA-F]+ \(custom_name\)>" )
146+         regex  =  (
147+             rf"<weakref at 0x[0-9a-fA-F]+; " 
148+             rf"to '{ ''  if  __name__  ==  '__main__'  else  WithName .__module__  +  '.' }  
149+             rf"{ WithName .__qualname__ }  
150+             rf"at 0x[0-9a-fA-F]+ +\(custom_name\)>" 
151+         )
152+         self .assertRegex (repr (ref2 ), regex )
148153
149154    def  test_repr_failure_gh99184 (self ):
150155        class  MyConfig (dict ):
@@ -229,10 +234,12 @@ def check(proxy):
229234    def  test_proxy_repr (self ):
230235        obj  =  C ()
231236        ref  =  weakref .proxy (obj , self .callback )
232-         self .assertRegex (repr (ref ),
233-                          rf"<weakproxy at 0x[0-9a-fA-F]+; " 
234-                          rf"to '{ C .__module__ } { C .__qualname__ }  
235-                          rf"at 0x[0-9a-fA-F]+>" )
237+         regex  =  (
238+             rf"<weakproxy at 0x[0-9a-fA-F]+; " 
239+             rf"to '{ ''  if  __name__  ==  '__main__'  else  C .__module__  +  '.' } { C .__qualname__ }  
240+             rf"at 0x[0-9a-fA-F]+>" 
241+         )
242+         self .assertRegex (repr (ref ), regex )
236243
237244        obj  =  None 
238245        gc_collect ()
0 commit comments