File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1078,7 +1078,8 @@ def get_lineno(self):
1078
1078
1079
1079
# First, let's see if there are any method definitions
1080
1080
for member in self .cls .__dict__ .values ():
1081
- if isinstance (member , types .FunctionType ):
1081
+ if (isinstance (member , types .FunctionType ) and
1082
+ member .__module__ == self .cls .__module__ ):
1082
1083
for lineno , end_lineno in self .lineno_found :
1083
1084
if lineno <= member .__code__ .co_firstlineno <= end_lineno :
1084
1085
return lineno
Original file line number Diff line number Diff line change 15
15
import shutil
16
16
import sys
17
17
import types
18
+ import tempfile
18
19
import textwrap
19
20
import unicodedata
20
21
import unittest
@@ -963,6 +964,33 @@ def test_nested_class_definition_inside_function(self):
963
964
self .assertSourceEqual (mod2 .cls213 , 218 , 222 )
964
965
self .assertSourceEqual (mod2 .cls213 ().func219 (), 220 , 221 )
965
966
967
+ def test_class_with_method_from_other_module (self ):
968
+ with tempfile .TemporaryDirectory () as tempdir :
969
+ with open (os .path .join (tempdir , 'inspect_actual%spy' % os .extsep ),
970
+ 'w' , encoding = 'utf-8' ) as f :
971
+ f .write (textwrap .dedent ("""
972
+ import inspect_other
973
+ class A:
974
+ def f(self):
975
+ pass
976
+ class A:
977
+ def f(self):
978
+ pass # correct one
979
+ A.f = inspect_other.A.f
980
+ """ ))
981
+
982
+ with open (os .path .join (tempdir , 'inspect_other%spy' % os .extsep ),
983
+ 'w' , encoding = 'utf-8' ) as f :
984
+ f .write (textwrap .dedent ("""
985
+ class A:
986
+ def f(self):
987
+ pass
988
+ """ ))
989
+
990
+ with DirsOnSysPath (tempdir ):
991
+ import inspect_actual
992
+ self .assertIn ("correct" , inspect .getsource (inspect_actual .A ))
993
+
966
994
@unittest .skipIf (
967
995
support .is_emscripten or support .is_wasi ,
968
996
"socket.accept is broken"
You can’t perform that action at this time.
0 commit comments