diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py index 6a31076..d77cf8a 100644 --- a/IPython/core/magics/osm.py +++ b/IPython/core/magics/osm.py @@ -218,8 +218,9 @@ class OSMagics(Magics): os.chdir(pdir) except OSError: continue + + # use with notation for python 3.6 onward dirlist = os.scandir(path=pdir) - #with os.scandir(pdir) as dirlist: for ff in dirlist: if self.isexec(ff): fname = ff.name @@ -240,21 +241,23 @@ class OSMagics(Magics): os.chdir(pdir) except OSError: continue - with os.scandir(pdir) as dirlist: - for ff in dirlist: - fname = ff.name - base, ext = os.path.splitext(fname) - if self.isexec(ff) and base.lower() not in no_alias: - if ext.lower() == '.exe': - fname = base - try: - # Removes dots from the name since ipython - # will assume names with dots to be python. - self.shell.alias_manager.define_alias( - base.lower().replace('.',''), fname) - except InvalidAliasError: - pass - syscmdlist.append(fname) + + # use with notation for python 3.6 onward + dirlist = os.scandir(pdir) + for ff in dirlist: + fname = ff.name + base, ext = os.path.splitext(fname) + if self.isexec(ff) and base.lower() not in no_alias: + if ext.lower() == '.exe': + fname = base + try: + # Removes dots from the name since ipython + # will assume names with dots to be python. + self.shell.alias_manager.define_alias( + base.lower().replace('.',''), fname) + except InvalidAliasError: + pass + syscmdlist.append(fname) self.shell.db['syscmdlist'] = syscmdlist finally: os.chdir(savedir) diff --git a/IPython/core/profileapp.py b/IPython/core/profileapp.py index 700fcc7..2f66bd9 100644 --- a/IPython/core/profileapp.py +++ b/IPython/core/profileapp.py @@ -97,10 +97,12 @@ ipython locate profile foo # print the path to the directory for profile 'foo' def list_profiles_in(path): """list profiles in a given root directory""" profiles = [] - with os.scandir(path) as files: - for f in files: - if f.is_dir() and f.name.startswith('profile_'): - profiles.append(f.name.split('_', 1)[-1]) + + # use with notation for python 3.6 onward + files = os.scandir(path) + for f in files: + if f.is_dir() and f.name.startswith('profile_'): + profiles.append(f.name.split('_', 1)[-1]) return profiles @@ -108,10 +110,12 @@ def list_bundled_profiles(): """list profiles that are bundled with IPython.""" path = os.path.join(get_ipython_package_dir(), u'core', u'profile') profiles = [] - with os.scandir(path) as files: - for profile in files: - if profile.is_dir() and profile.name != "__pycache__": - profiles.append(profile.name) + + # use with notation for python 3.6 onward + files = os.scandir(path) + for profile in files: + if profile.is_dir() and profile.name != "__pycache__": + profiles.append(profile.name) return profiles