Skip to content

Commit

Permalink
[types] Fix type errors and lint errors.
Browse files Browse the repository at this point in the history
Minor style changes.
  • Loading branch information
Andy Chu committed Mar 21, 2020
1 parent 9cdc686 commit 089e2f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
36 changes: 16 additions & 20 deletions core/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from core.comp_ui import _IDisplay
from core import optview
from osh.cmd_exec import Executor
from core.state import SearchPath
from core.state import SearchPath, Mem
from mycpp import mylib


Expand Down Expand Up @@ -185,11 +185,12 @@ def Open(self, path, mode='r'):
return f

def _WriteFdToMem(self, fd_name, fd):
# type: (string, int) -> None
# type: (str, int) -> None
if self.mem:
self.mem.SetVar(lvalue.Named(fd_name), value.Str(str(fd)), scope_e.Dynamic)

def _ReadFdFromMem(self, fd_name):
# type: (string) -> int
# type: (str) -> int
if self.mem is None: return NO_FD

val = self.mem.GetVar(fd_name)
Expand Down Expand Up @@ -232,18 +233,13 @@ def _PushSave(self, fd):

return need_restore

def _PushDup(self, fd1, fd2, fd2name=None):
# type: (int, int, string) -> bool
"""Save fd2, and dup fd1 onto fd2.
Mutates self.cur_frame.saved.
Returns:
success Bool
"""
if fd1 == fd2: return True
def _PushDup(self, fd1, fd2, fd2_name=None):
# type: (int, int, str) -> bool
"""Save fd2, and dup fd1 onto fd2. Returns bool success."""
if fd1 == fd2:
return True

if fd2name:
if fd2_name:
try:
new_fd = fcntl.fcntl(fd1, fcntl.F_DUPFD, 10)
except IOError as e:
Expand All @@ -253,7 +249,7 @@ def _PushDup(self, fd1, fd2, fd2name=None):
raise
return False

self._WriteFdToMem(fd2name, new_fd)
self._WriteFdToMem(fd2_name, new_fd)
return True

need_restore = self._PushSave(fd2)
Expand All @@ -276,18 +272,18 @@ def _PushDup(self, fd1, fd2, fd2name=None):
return True

def _PushCloseFd(self, fd, fd_name):
# type: (int, string) -> bool
# type: (int, str) -> bool
if fd_name:
fd = self._ReadFdFromMem(fd_name)
if fd == NO_FD: return False

self._PushSave(fd)
return True

def _PushMoveFd(self, fd1, fd2, fd2name=None):
# type: (int, int) -> bool
def _PushMoveFd(self, fd1, fd2, fd2_name=None):
# type: (int, int, str) -> bool

if fd2name:
if fd2_name:
try:
new_fd = fcntl.fcntl(fd1, fcntl.F_DUPFD, 10)
except IOError as e:
Expand All @@ -297,7 +293,7 @@ def _PushMoveFd(self, fd1, fd2, fd2name=None):
raise
return False

self._WriteFdToMem(fd2name, new_fd)
self._WriteFdToMem(fd2_name, new_fd)
posix.close(fd1)
self.cur_frame.saved.append((new_fd, fd1, False))
return True
Expand Down
1 change: 0 additions & 1 deletion osh/cmd_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from asdl import runtime
from core import error
from core import ui
from core import process
from core.util import log, p_die
from frontend import match
from frontend import reader
Expand Down

0 comments on commit 089e2f0

Please sign in to comment.