Merge pull request #3166 from 6syun9/dev_warning

completer turn off warning
This commit is contained in:
Morten Enemark Lund 2019-06-17 22:09:04 +02:00 committed by GitHub
commit f08a05ba3a
Failed to generate hash of commit
2 changed files with 38 additions and 0 deletions

23
news/dev_warning.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* turn off warning on completer
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -4,6 +4,7 @@ import sys
import inspect
import builtins
import importlib
import warnings
import collections.abc as cabc
import xonsh.tools as xt
@ -184,6 +185,18 @@ def complete_python_mode(prefix, line, start, end, ctx):
return set(prefix_start + i for i in python_matches)
def _turn_off_warning(func):
"""Decorator to turn off warning temporarily."""
def wrapper(*args, **kwargs):
warnings.filterwarnings("ignore")
r = func(*args, **kwargs)
warnings.filterwarnings("once", category=DeprecationWarning)
return r
return wrapper
def _safe_eval(expr, ctx):
"""Safely tries to evaluate an expression. If this fails, it will return
a (None, None) tuple.
@ -202,6 +215,7 @@ def _safe_eval(expr, ctx):
return val, _ctx
@_turn_off_warning
def attr_complete(prefix, ctx, filter_func):
"""Complete attributes of an object."""
attrs = set()
@ -243,6 +257,7 @@ def attr_complete(prefix, ctx, filter_func):
return attrs
@_turn_off_warning
def python_signature_complete(prefix, line, end, ctx, filter_func):
"""Completes a python function (or other callable) call by completing
argument and keyword argument names.