GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — factor out current function · MarkTseng/bpython@134fb1e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bpython
    • repl.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bpython/repl.py‎

Copy file name to clipboardExpand all lines: bpython/repl.py
+18-13Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -477,22 +477,14 @@ def get_object(self, name):
477477
obj = getattr(obj, attributes.pop(0))
478478
return obj
479479

480-
def get_args(self):
481-
"""Check if an unclosed parenthesis exists, then attempt to get the
482-
argspec() for it. On success, update self.funcprops,self.arg_pos and
483-
return True, otherwise set self.funcprops to None and return False"""
484-
485-
self.current_func = None
480+
@classmethod
481+
def _funcname_and_argnum(cls, line):
482+
"""Name of the current function and where we are in args
486483
487-
if not self.config.arg_spec:
488-
return False
489-
490-
# Get the name of the current function and where we are in
491-
# the arguments
484+
Returns (None, None) if can't be found."""
492485
stack = [['', 0, '']]
493486
try:
494-
for (token, value) in PythonLexer().get_tokens(
495-
self.current_line):
487+
for (token, value) in PythonLexer().get_tokens(line):
496488
if token is Token.Punctuation:
497489
if value in '([{':
498490
stack.append(['', 0, value])
@@ -522,8 +514,21 @@ def get_args(self):
522514
stack.pop()
523515
_, arg_number, _ = stack.pop()
524516
func, _, _ = stack.pop()
517+
return func, arg_number
525518
except IndexError:
519+
return None, None
520+
521+
def get_args(self):
522+
"""Check if an unclosed parenthesis exists, then attempt to get the
523+
argspec() for it. On success, update self.funcprops,self.arg_pos and
524+
return True, otherwise set self.funcprops to None and return False"""
525+
526+
self.current_func = None
527+
528+
if not self.config.arg_spec:
526529
return False
530+
531+
func, arg_number = self._funcname_and_argnum(self.current_line)
527532
if not func:
528533
return False
529534

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.