Skip to content

Commit

Permalink
formatted2
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Feb 18, 2024
1 parent 261da82 commit 8359e25
Show file tree
Hide file tree
Showing 286 changed files with 32,488 additions and 33,457 deletions.
40 changes: 19 additions & 21 deletions _pydev_bundle/_pydev_calltip_util.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'''
"""
License: Apache 2.0
Author: Yuli Fitterman
'''
"""
import types

from _pydevd_bundle.pydevd_constants import IS_JYTHON

try:
import inspect
except:
import traceback;
import traceback

traceback.print_exc() # Ok, no inspect available (search will not work)

Expand All @@ -18,7 +18,7 @@

def is_bound_method(obj):
if isinstance(obj, types.MethodType):
return getattr(obj, '__self__', getattr(obj, 'im_self', None)) is not None
return getattr(obj, "__self__", getattr(obj, "im_self", None)) is not None
else:
return False

Expand All @@ -28,7 +28,7 @@ def get_class_name(instance):


def get_bound_class_name(obj):
my_self = getattr(obj, '__self__', getattr(obj, 'im_self', None))
my_self = getattr(obj, "__self__", getattr(obj, "im_self", None))
if my_self is None:
return None
return get_class_name(my_self)
Expand All @@ -40,8 +40,8 @@ def get_description(obj):
except:
ob_call = None

if isinstance(obj, type) or type(obj).__name__ == 'classobj':
fob = getattr(obj, '__init__', lambda: None)
if isinstance(obj, type) or type(obj).__name__ == "classobj":
fob = getattr(obj, "__init__", lambda: None)
if not isinstance(fob, (types.FunctionType, types.MethodType)):
fob = obj
elif is_bound_method(ob_call):
Expand All @@ -55,16 +55,16 @@ def get_description(obj):
if isinstance(fob, (types.FunctionType, types.MethodType)):
spec_info = inspect.getfullargspec(fob)
argspec = inspect.formatargspec(*spec_info)
fn_name = getattr(fob, '__name__', None)
if isinstance(obj, type) or type(obj).__name__ == 'classobj':
fn_name = getattr(fob, "__name__", None)
if isinstance(obj, type) or type(obj).__name__ == "classobj":
fn_name = "__init__"
fn_class = getattr(obj, "__name__", "UnknownClass")
elif is_bound_method(obj) or is_bound_method(ob_call):
fn_class = get_bound_class_name(obj) or "UnknownClass"

else:
fn_name = getattr(fob, '__name__', None)
fn_self = getattr(fob, '__self__', None)
fn_name = getattr(fob, "__name__", None)
fn_self = getattr(fob, "__self__", None)
if fn_self is not None and not isinstance(fn_self, types.ModuleType):
fn_class = get_class_name(fn_self)

Expand All @@ -77,7 +77,7 @@ def create_method_stub(fn_name, fn_class, argspec, doc_string):
doc_string = "" if doc_string is None else doc_string
fn_stub = create_function_stub(fn_name, argspec, doc_string, indent=1 if fn_class else 0)
if fn_class:
expr = fn_class if fn_name == '__init__' else fn_class + '().' + fn_name
expr = fn_class if fn_name == "__init__" else fn_class + "()." + fn_name
return create_class_stub(fn_class, fn_stub) + "\n" + expr
else:
expr = fn_name
Expand All @@ -87,10 +87,10 @@ def create_method_stub(fn_name, fn_class, argspec, doc_string):
restored_signature, _ = signature_from_docstring(doc_string, fn_name)
if restored_signature:
return create_method_stub(fn_name, fn_class, restored_signature, doc_string)
return create_function_stub('unknown', '(*args, **kwargs)', doc_string) + '\nunknown'
return create_function_stub("unknown", "(*args, **kwargs)", doc_string) + "\nunknown"

else:
return ''
return ""


def get_docstring(obj):
Expand All @@ -105,21 +105,20 @@ def get_docstring(obj):
from _pydev_bundle import _pydev_jy_imports_tipper

is_method, infos = _pydev_jy_imports_tipper.ismethod(obj)
ret = ''
ret = ""
if is_method:
for info in infos:
ret += info.get_as_doc()
return ret

else:

doc = inspect.getdoc(obj)
if doc is not None:
return doc
except:
pass
else:
return ''
return ""
try:
# if no attempt succeeded, try to return repr()...
return repr(obj)
Expand All @@ -129,17 +128,16 @@ def get_docstring(obj):
return str(obj.__class__)
except:
# if all fails, go to an empty string
return ''
return ""


def create_class_stub(class_name, contents):
return "class %s(object):\n%s" % (class_name, contents)


def create_function_stub(fn_name, fn_argspec, fn_docstring, indent=0):

def shift_right(string, prefix):
return ''.join(prefix + line for line in string.splitlines(True))
return "".join(prefix + line for line in string.splitlines(True))

fn_docstring = shift_right(inspect.cleandoc(fn_docstring), " " * (indent + 1))
ret = '''
Expand All @@ -148,7 +146,7 @@ def %s%s:
pass
''' % (fn_name, fn_argspec, fn_docstring)
ret = ret[1:] # remove first /n
ret = ret.replace('\t', " ")
ret = ret.replace("\t", " ")
if indent:
prefix = " " * indent
ret = shift_right(ret, prefix)
Expand Down
60 changes: 30 additions & 30 deletions _pydev_bundle/_pydev_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
try:
import java.lang # @UnusedImport
from _pydev_bundle import _pydev_jy_imports_tipper

_pydev_imports_tipper = _pydev_jy_imports_tipper
except ImportError:
IS_JYTHON = False
Expand All @@ -17,13 +18,13 @@
dir2 = _pydev_imports_tipper.generate_imports_tip_for_module


#=======================================================================================================================
# =======================================================================================================================
# _StartsWithFilter
#=======================================================================================================================
# =======================================================================================================================
class _StartsWithFilter:
'''
Used because we can't create a lambda that'll use an outer scope in jython 2.1
'''
"""
Used because we can't create a lambda that'll use an outer scope in jython 2.1
"""

def __init__(self, start_with):
self.start_with = start_with.lower()
Expand All @@ -32,13 +33,12 @@ def __call__(self, name):
return name.lower().startswith(self.start_with)


#=======================================================================================================================
# =======================================================================================================================
# Completer
#
# This class was gotten from IPython.completer (dir2 was replaced with the completer already in pydev)
#=======================================================================================================================
# =======================================================================================================================
class Completer:

def __init__(self, namespace=None, global_namespace=None):
"""Create a new completer for the command line.
Expand Down Expand Up @@ -82,7 +82,7 @@ def complete(self, text):
"""
if self.use_main_ns:
# In pydev this option should never be used
raise RuntimeError('Namespace must be provided!')
raise RuntimeError("Namespace must be provided!")
self.namespace = __main__.__dict__ # @UndefinedVariable

if "." in text:
Expand Down Expand Up @@ -148,15 +148,15 @@ def attr_matches(self, text):


def generate_completions(frame, act_tok):
'''
"""
:return list(tuple(method_name, docstring, parameters, completion_type))
method_name: str
docstring: str
parameters: str -- i.e.: "(a, b)"
completion_type is an int
See: _pydev_bundle._pydev_imports_tipper for TYPE_ constants
'''
"""
if frame is None:
return []

Expand Down Expand Up @@ -189,21 +189,21 @@ def completions_to_xml(completions):

for comp in completions:
msg.append('<comp p0="')
msg.append(valid_xml(quote(comp[0], '/>_= \t')))
msg.append(valid_xml(quote(comp[0], "/>_= \t")))
msg.append('" p1="')
msg.append(valid_xml(quote(comp[1], '/>_= \t')))
msg.append(valid_xml(quote(comp[1], "/>_= \t")))
msg.append('" p2="')
msg.append(valid_xml(quote(comp[2], '/>_= \t')))
msg.append(valid_xml(quote(comp[2], "/>_= \t")))
msg.append('" p3="')
msg.append(valid_xml(quote(comp[3], '/>_= \t')))
msg.append(valid_xml(quote(comp[3], "/>_= \t")))
msg.append('"/>')
msg.append("</xml>")

return ''.join(msg)
return "".join(msg)


identifier_start = ascii_letters + '_'
identifier_part = ascii_letters + '_' + digits
identifier_start = ascii_letters + "_"
identifier_part = ascii_letters + "_" + digits

identifier_start = set(identifier_start)
identifier_part = set(identifier_part)
Expand All @@ -213,18 +213,18 @@ def isidentifier(s):
return s.isidentifier()


TokenAndQualifier = namedtuple('TokenAndQualifier', 'token, qualifier')
TokenAndQualifier = namedtuple("TokenAndQualifier", "token, qualifier")


def extract_token_and_qualifier(text, line=0, column=0):
'''
"""
Extracts the token a qualifier from the text given the line/colum
(see test_extract_token_and_qualifier for examples).
:param unicode text:
:param int line: 0-based
:param int column: 0-based
'''
"""
# Note: not using the tokenize module because text should be unicode and
# line/column refer to the unicode text (otherwise we'd have to know
# those ranges after converted to bytes).
Expand All @@ -234,32 +234,32 @@ def extract_token_and_qualifier(text, line=0, column=0):
column = 0

if isinstance(text, bytes):
text = text.decode('utf-8')
text = text.decode("utf-8")

lines = text.splitlines()
try:
text = lines[line]
except IndexError:
return TokenAndQualifier(u'', u'')
return TokenAndQualifier("", "")

if column >= len(text):
column = len(text)

text = text[:column]
token = u''
qualifier = u''
token = ""
qualifier = ""

temp_token = []
for i in range(column - 1, -1, -1):
c = text[i]
if c in identifier_part or isidentifier(c) or c == u'.':
if c in identifier_part or isidentifier(c) or c == ".":
temp_token.append(c)
else:
break
temp_token = u''.join(reversed(temp_token))
if u'.' in temp_token:
temp_token = temp_token.split(u'.')
token = u'.'.join(temp_token[:-1])
temp_token = "".join(reversed(temp_token))
if "." in temp_token:
temp_token = temp_token.split(".")
token = ".".join(temp_token[:-1])
qualifier = temp_token[-1]
else:
qualifier = temp_token
Expand Down
4 changes: 3 additions & 1 deletion _pydev_bundle/_pydev_execfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
def execfile(file, glob=None, loc=None):
if glob is None:
import sys

glob = sys._getframe().f_back.f_globals
if loc is None:
loc = glob

import tokenize

with tokenize.open(file) as stream:
contents = stream.read()

# execute the script (note: it's important to compile first to have the filename set in debug mode)
exec(compile(contents + "\n", file, 'exec'), glob, loc)
exec(compile(contents + "\n", file, "exec"), glob, loc)
36 changes: 19 additions & 17 deletions _pydev_bundle/_pydev_filesystem_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,42 @@


def __getfilesystemencoding():
'''
"""
Note: there's a copy of this method in interpreterInfo.py
'''
"""
try:
ret = sys.getfilesystemencoding()
if not ret:
raise RuntimeError('Unable to get encoding.')
raise RuntimeError("Unable to get encoding.")
return ret
except:
try:
#Handle Jython
# Handle Jython
from java.lang import System # @UnresolvedImport

env = System.getProperty("os.name").lower()
if env.find('win') != -1:
return 'ISO-8859-1' #mbcs does not work on Jython, so, use a (hopefully) suitable replacement
return 'utf-8'
if env.find("win") != -1:
return "ISO-8859-1" # mbcs does not work on Jython, so, use a (hopefully) suitable replacement
return "utf-8"
except:
pass

#Only available from 2.3 onwards.
if sys.platform == 'win32':
return 'mbcs'
return 'utf-8'
# Only available from 2.3 onwards.
if sys.platform == "win32":
return "mbcs"
return "utf-8"


def getfilesystemencoding():
try:
ret = __getfilesystemencoding()

#Check if the encoding is actually there to be used!
if hasattr('', 'encode'):
''.encode(ret)
if hasattr('', 'decode'):
''.decode(ret)
# Check if the encoding is actually there to be used!
if hasattr("", "encode"):
"".encode(ret)
if hasattr("", "decode"):
"".decode(ret)

return ret
except:
return 'utf-8'
return "utf-8"
Loading

0 comments on commit 8359e25

Please sign in to comment.