mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
added a descriptor, to ignore unbound methods in Python 2
This commit is contained in:
@@ -90,3 +90,14 @@ else:
|
||||
return True
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
class Python3Method(object):
|
||||
def __init__(self, func):
|
||||
self.func = func
|
||||
|
||||
def __get__(self, obj, objtype):
|
||||
if obj is None:
|
||||
return lambda *args, **kwargs: self.func(*args, **kwargs)
|
||||
else:
|
||||
return lambda *args, **kwargs: self.func(obj, *args, **kwargs)
|
||||
|
||||
|
||||
23
parsing.py
23
parsing.py
@@ -29,7 +29,7 @@ Ignored statements:
|
||||
- exec (dangerous - not controllable)
|
||||
"""
|
||||
from _compatibility import (next, literal_eval, tokenize_func, BytesIO,
|
||||
property, is_py3k)
|
||||
property, is_py3k, Python3Method)
|
||||
|
||||
import tokenize
|
||||
import re
|
||||
@@ -164,6 +164,7 @@ class Scope(Simple):
|
||||
string = indent_block(string, indention=indention)
|
||||
return string
|
||||
|
||||
@Python3Method
|
||||
def get_set_vars(self):
|
||||
"""
|
||||
Get all the names, that are active and accessible in the current
|
||||
@@ -172,15 +173,6 @@ class Scope(Simple):
|
||||
:return: list of Name
|
||||
:rtype: list
|
||||
"""
|
||||
return self._get_set_vars(self)
|
||||
|
||||
@staticmethod
|
||||
def _get_set_vars(self):
|
||||
"""
|
||||
This is a hack, because Python 2 has another understanding of methods,
|
||||
than Python 3. In Python 2 it is not possible to use a method without
|
||||
the `self` being an instance of the class.
|
||||
"""
|
||||
n = []
|
||||
for stmt in self.statements:
|
||||
try:
|
||||
@@ -207,6 +199,17 @@ class Scope(Simple):
|
||||
"""
|
||||
return not (self.imports or self.subscopes or self.statements)
|
||||
|
||||
@Python3Method
|
||||
def get_statement_for_position(self, pos):
|
||||
for s in self.statements:
|
||||
if s.start_pos <= pos < self.end_pos:
|
||||
return s
|
||||
|
||||
for s in self.subscopes:
|
||||
p = s.get_statement_for_position(pos)
|
||||
if p:
|
||||
return p
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
name = self.name
|
||||
|
||||
Reference in New Issue
Block a user