mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-34144 Suppress warnings while resolving variables
This commit is contained in:
@@ -3,6 +3,8 @@ try:
|
||||
except:
|
||||
import io as StringIO
|
||||
import traceback
|
||||
import warnings
|
||||
from contextlib import contextmanager
|
||||
from os.path import basename
|
||||
|
||||
from _pydevd_bundle import pydevd_constants
|
||||
@@ -55,6 +57,13 @@ except:
|
||||
MethodWrapperType = None
|
||||
|
||||
|
||||
@contextmanager
|
||||
def suppress_warnings():
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
yield
|
||||
|
||||
|
||||
#=======================================================================================================================
|
||||
# See: pydevd_extension_api module for resolver interface
|
||||
#=======================================================================================================================
|
||||
@@ -69,7 +78,8 @@ class DefaultResolver:
|
||||
'''
|
||||
|
||||
def resolve(self, var, attribute):
|
||||
return getattr(var, attribute)
|
||||
with suppress_warnings():
|
||||
return getattr(var, attribute)
|
||||
|
||||
def get_dictionary(self, var, names=None):
|
||||
if MethodWrapperType:
|
||||
@@ -164,7 +174,8 @@ class DefaultResolver:
|
||||
continue
|
||||
|
||||
try:
|
||||
attr = getattr(var, n)
|
||||
with suppress_warnings():
|
||||
attr = getattr(var, n)
|
||||
|
||||
#filter builtins?
|
||||
if filterBuiltIn:
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import warnings
|
||||
|
||||
|
||||
class ClassWithDeprecatedProperty:
|
||||
@property
|
||||
def x(self):
|
||||
warnings.warn("This property is deprecated!", DeprecationWarning)
|
||||
return 42
|
||||
|
||||
|
||||
obj = ClassWithDeprecatedProperty()
|
||||
|
||||
warnings.warn("This warning should appear in the output.")
|
||||
|
||||
print(obj.x)
|
||||
print(obj)
|
||||
@@ -1875,5 +1875,29 @@ public class PythonDebuggerTest extends PyEnvTestCase {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWarningsSuppressing() {
|
||||
runPythonTest(new PyDebuggerTask("/debug", "test_warnings_suppressing.py") {
|
||||
@Override
|
||||
public void before() {
|
||||
toggleBreakpoint(getFilePath(getScriptName()), 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForPause();
|
||||
List<PyDebugValue> frameVariables = loadFrame();
|
||||
PyDebugValue obj = findDebugValueByName(frameVariables, "obj");
|
||||
loadVariable(obj);
|
||||
String out = output();
|
||||
assertTrue(out.contains("This warning should appear in the output."));
|
||||
assertFalse(out.contains("This property is deprecated!"));
|
||||
toggleBreakpoint(getFilePath(getScriptName()), 15);
|
||||
resume();
|
||||
waitForPause();
|
||||
waitForOutput("This property is deprecated!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user