Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a9d955

Browse files
committed
Format code
1 parent 23276ac commit 1a9d955

37 files changed

Lines changed: 249 additions & 176 deletions

IPython/core/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def stage_default_config_file(self):
470470
config_file = Path(self.profile_dir.location) / self.config_file_name
471471
if self.overwrite or not config_file.exists():
472472
self.log.warning("Generating default config file: %r" % (config_file))
473-
config_file.write_text(s, encoding='utf-8')
473+
config_file.write_text(s, encoding="utf-8")
474474

475475
@catch_config_error
476476
def initialize(self, argv=None):

IPython/core/crashhandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def __call__(self, etype, evalue, etb):
185185

186186
# and generate a complete report on disk
187187
try:
188-
report = open(report_name, 'w', encoding='utf-8')
188+
report = open(report_name, "w", encoding="utf-8")
189189
except:
190190
print('Could not create crash report on disk.', file=sys.stderr)
191191
return

IPython/core/display.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def _data_and_metadata(self):
349349
def reload(self):
350350
"""Reload the raw data from file or URL."""
351351
if self.filename is not None:
352-
encoding = None if 'b' in self._read_flags else 'utf-8'
352+
encoding = None if "b" in self._read_flags else "utf-8"
353353
with open(self.filename, self._read_flags, encoding=encoding) as f:
354354
self.data = f.read()
355355
elif self.url is not None:
@@ -370,8 +370,11 @@ def reload(self):
370370
if 'gzip' in response.headers['content-encoding']:
371371
import gzip
372372
from io import BytesIO
373+
373374
# assume utf-8 if encoding is not specified
374-
with gzip.open(BytesIO(data), 'rt', encoding=encoding or 'utf-8') as fp:
375+
with gzip.open(
376+
BytesIO(data), "rt", encoding=encoding or "utf-8"
377+
) as fp:
375378
encoding = None
376379
data = fp.read()
377380

IPython/core/interactiveshell.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,7 +2626,7 @@ def safe_execfile(self, fname, *where, exit_ignore=False, raise_exceptions=False
26262626

26272627
# Make sure we can open the file
26282628
try:
2629-
with fname.open('rb'):
2629+
with fname.open("rb"):
26302630
pass
26312631
except:
26322632
warn('Could not open file <%s> for safe execution.' % fname)
@@ -2684,7 +2684,7 @@ def safe_execfile_ipy(self, fname, shell_futures=False, raise_exceptions=False):
26842684

26852685
# Make sure we can open the file
26862686
try:
2687-
with fname.open('rb'):
2687+
with fname.open("rb"):
26882688
pass
26892689
except:
26902690
warn('Could not open file <%s> for safe execution.' % fname)
@@ -2706,7 +2706,7 @@ def get_cells():
27062706
if cell.cell_type == 'code':
27072707
yield cell.source
27082708
else:
2709-
yield fname.read_text(encoding='utf-8')
2709+
yield fname.read_text(encoding="utf-8")
27102710

27112711
with prepended_to_syspath(dname):
27122712
try:
@@ -3458,7 +3458,7 @@ def mktempfile(self, data=None, prefix='ipython_edit_'):
34583458
self.tempfiles.append(file_path)
34593459

34603460
if data:
3461-
file_path.write_text(data, encoding='utf-8')
3461+
file_path.write_text(data, encoding="utf-8")
34623462
return filename
34633463

34643464
def ask_yes_no(self, prompt, default=None, interrupt=None):

IPython/core/magics/code.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def _edit_macro(self,mname,macro):
538538
self.shell.hooks.editor(filename)
539539

540540
# and make a new macro object, to replace the old one
541-
mvalue = Path(filename).read_text(encoding='utf-8')
541+
mvalue = Path(filename).read_text(encoding="utf-8")
542542
self.shell.user_ns[mname] = Macro(mvalue)
543543

544544
@skip_doctest
@@ -728,25 +728,25 @@ def edit(self, parameter_s='',last_call=['','']):
728728
# XXX TODO: should this be generalized for all string vars?
729729
# For now, this is special-cased to blocks created by cpaste
730730
if args.strip() == "pasted_block":
731-
self.shell.user_ns["pasted_block"] = filepath.read_text(encoding='utf-8')
731+
self.shell.user_ns["pasted_block"] = filepath.read_text(encoding="utf-8")
732732

733733
if 'x' in opts: # -x prevents actual execution
734734
print()
735735
else:
736736
print('done. Executing edited code...')
737737
with preserve_keys(self.shell.user_ns, '__file__'):
738738
if not is_temp:
739-
self.shell.user_ns['__file__'] = filename
740-
if 'r' in opts: # Untranslated IPython code
741-
source = filepath.read_text(encoding='utf-8')
739+
self.shell.user_ns["__file__"] = filename
740+
if "r" in opts: # Untranslated IPython code
741+
source = filepath.read_text(encoding="utf-8")
742742
self.shell.run_cell(source, store_history=False)
743743
else:
744744
self.shell.safe_execfile(filename, self.shell.user_ns,
745745
self.shell.user_ns)
746746

747747
if is_temp:
748748
try:
749-
return filepath.read_text(encoding='utf-8')
749+
return filepath.read_text(encoding="utf-8")
750750
except IOError as msg:
751751
if Path(msg.filename) == filepath:
752752
warn('File not found. Did you forget to save?')

IPython/core/magics/execution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def _run_with_profiler(self, code, opts, namespace):
360360
if text_file:
361361
pfile = Path(text_file)
362362
pfile.touch(exist_ok=True)
363-
pfile.write_text(output, encoding='utf-8')
363+
pfile.write_text(output, encoding="utf-8")
364364

365365
print(
366366
f"\n*** Profile printout saved to text file {repr(text_file)}.{sys_exit}"

IPython/core/magics/packaging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _get_conda_executable():
3232

3333
# Otherwise, attempt to extract the executable from conda history.
3434
# This applies in any conda environment.
35-
history = Path(sys.prefix, "conda-meta", "history").read_text(encoding='utf-8')
35+
history = Path(sys.prefix, "conda-meta", "history").read_text(encoding="utf-8")
3636
match = re.search(
3737
r"^#\s*cmd:\s*(?P<command>.*conda)\s[create|install]",
3838
history,

IPython/core/page.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def pager_page(strng, start=0, screen_lines=0, pager_cmd=None):
199199
tmppath = Path(tmpname)
200200
try:
201201
os.close(fd)
202-
with tmppath.open("wt", encoding='utf-8') as tmpfile:
202+
with tmppath.open("wt", encoding="utf-8") as tmpfile:
203203
tmpfile.write(strng)
204204
cmd = "%s < %s" % (pager_cmd, tmppath)
205205
# tmpfile needs to be closed for windows
@@ -213,12 +213,15 @@ def pager_page(strng, start=0, screen_lines=0, pager_cmd=None):
213213
try:
214214
retval = None
215215
# Emulate os.popen, but redirect stderr
216-
proc = subprocess.Popen(pager_cmd,
217-
shell=True,
218-
stdin=subprocess.PIPE,
219-
stderr=subprocess.DEVNULL
220-
)
221-
pager = os._wrap_close(io.TextIOWrapper(proc.stdin, encoding='utf-8'), proc)
216+
proc = subprocess.Popen(
217+
pager_cmd,
218+
shell=True,
219+
stdin=subprocess.PIPE,
220+
stderr=subprocess.DEVNULL,
221+
)
222+
pager = os._wrap_close(
223+
io.TextIOWrapper(proc.stdin, encoding="utf-8"), proc
224+
)
222225
try:
223226
pager_encoding = pager.encoding or sys.stdout.encoding
224227
pager.write(strng)
@@ -277,7 +280,7 @@ def page_file(fname, start=0, pager_cmd=None):
277280
try:
278281
if start > 0:
279282
start -= 1
280-
page(open(fname, encoding='utf-8').read(),start)
283+
page(open(fname, encoding="utf-8").read(), start)
281284
except:
282285
print('Unable to show file',repr(fname))
283286

IPython/core/tests/test_application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_unicode_ipdir():
3434
ipdir = tempfile.mkdtemp(suffix=u"€")
3535

3636
# Create the config file, so it tries to load it.
37-
with open(os.path.join(ipdir, 'ipython_config.py'), "w", encoding='utf-8') as f:
37+
with open(os.path.join(ipdir, "ipython_config.py"), "w", encoding="utf-8") as f:
3838
pass
3939

4040
old_ipdir1 = os.environ.pop("IPYTHONDIR", None)
@@ -59,7 +59,7 @@ class TestApp(BaseIPythonApplication):
5959
test = Unicode().tag(config=True)
6060

6161
# Create the config file, so it tries to load it.
62-
with open(os.path.join(td, 'ipython_config.py'), "w", encoding='utf-8') as f:
62+
with open(os.path.join(td, "ipython_config.py"), "w", encoding="utf-8") as f:
6363
f.write("c.TestApp.test = 'config file'")
6464

6565
app = TestApp()

IPython/core/tests/test_completer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def test_abspath_file_completions(self):
346346
suffixes = ["1", "2"]
347347
names = [prefix + s for s in suffixes]
348348
for n in names:
349-
open(n, "w", encoding='utf-8').close()
349+
open(n, "w", encoding="utf-8").close()
350350

351351
# Check simple completion
352352
c = ip.complete(prefix)[1]
@@ -365,7 +365,7 @@ def test_local_file_completions(self):
365365
suffixes = ["1", "2"]
366366
names = [prefix + s for s in suffixes]
367367
for n in names:
368-
open(n, "w", encoding='utf-8').close()
368+
open(n, "w", encoding="utf-8").close()
369369

370370
# Check simple completion
371371
c = ip.complete(prefix)[1]
@@ -381,7 +381,7 @@ def test_quoted_file_completions(self):
381381
ip = get_ipython()
382382
with TemporaryWorkingDirectory():
383383
name = "foo'bar"
384-
open(name, "w", encoding='utf-8').close()
384+
open(name, "w", encoding="utf-8").close()
385385

386386
# Don't escape Windows
387387
escaped = name if sys.platform == "win32" else "foo\\'bar"

0 commit comments

Comments
 (0)