Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit51ecedb

Browse files
Add autocompletion of attributes of simple expressions
there's now duplication in completers
1 parent488d5e6 commit51ecedb

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

‎bpython/autocomplete.py‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
frombpython.lineimportLinePart
4444
frombpython._py3compatimportpy3,try_decode
4545
frombpython.lazyreimportLazyReCompile
46-
frombpython.simpleevalimportsafe_eval,EvaluationError
46+
frombpython.simpleevalimport (safe_eval,evaluate_current_expression,
47+
EvaluationError)
4748

4849
ifnotpy3:
4950
fromtypesimportInstanceType,ClassType
@@ -241,7 +242,7 @@ def matches(self, cursor_offset, line, **kwargs):
241242
ifrisNone:
242243
returnNone
243244

244-
iflocals_isNone:
245+
iflocals_isNone:# TODO add a note about why
245246
locals_=__main__.__dict__
246247

247248
assert'.'inr.word
@@ -524,6 +525,41 @@ def locate(self, current_offset, line):
524525
returnlineparts.current_string_literal_attr(current_offset,line)
525526

526527

528+
classExpressionAttributeCompletion(AttrCompletion):
529+
# could replace ArrayItemMember completion and attr completion
530+
# as a more general case
531+
deflocate(self,current_offset,line):
532+
returnlineparts.current_expression_attribute(current_offset,line)
533+
534+
defmatches(self,cursor_offset,line,**kwargs):
535+
if'locals_'notinkwargs:
536+
returnNone
537+
locals_=kwargs['locals_']
538+
539+
iflocals_isNone:
540+
locals_=__main__.__dict__
541+
542+
attr=self.locate(cursor_offset,line)
543+
544+
try:
545+
obj=evaluate_current_expression(cursor_offset,line,locals_)
546+
exceptEvaluationError:
547+
returnset()
548+
withinspection.AttrCleaner(obj):
549+
# strips leading dot
550+
matches= [m[1:]forminself.attr_lookup(obj,'',attr.word)]
551+
552+
ifattr.word.startswith('__'):
553+
pass
554+
elifattr.word.startswith('_'):
555+
matches=set(matchformatchinmatches
556+
ifnotmatch.startswith('__'))
557+
else:
558+
matches=set(matchformatchinmatches
559+
ifnotmatch.split('.')[-1].startswith('_'))
560+
returnmatches
561+
562+
527563
try:
528564
importjedi
529565
exceptImportError:
@@ -638,8 +674,9 @@ def get_default_completer(mode=SIMPLE):
638674
CumulativeCompleter((GlobalCompletion(mode=mode),
639675
ParameterNameCompletion(mode=mode)),
640676
mode=mode),
641-
ArrayItemMembersCompletion(mode=mode),
642677
AttrCompletion(mode=mode),
678+
ExpressionAttributeCompletion(mode=mode),
679+
ArrayItemMembersCompletion(mode=mode),
643680
)
644681

645682

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp