From b4b0e18304b4056e4497cee8f7ee53521a337a5e Mon Sep 17 00:00:00 2001 From: ChandanChainani Date: Thu, 13 Oct 2022 23:12:27 +0530 Subject: [PATCH] Use `pathlib` instead of `os` in IPython/lib/demo (#12515) --- IPython/lib/demo.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/IPython/lib/demo.py b/IPython/lib/demo.py index ebffd54abde..f3295924b63 100644 --- a/IPython/lib/demo.py +++ b/IPython/lib/demo.py @@ -179,12 +179,11 @@ # #***************************************************************************** -import os import re import shlex import sys import pygments -from pathlib import Path +from pathlib import Path, PurePath from IPython.utils.text import marquee from IPython.utils import openpy @@ -251,8 +250,7 @@ def __init__(self,src,title='',arg_str='',auto_all=None, format_rst=False, # Assume it's a string or something that can be converted to one self.fname = src if title == '': - (filepath, filename) = os.path.split(src) - self.title = filename + self.title = PurePath(src).name else: self.title = title self.sys_argv = [src] + shlex.split(arg_str) @@ -405,7 +403,7 @@ def edit(self,index=None): filename = self.shell.mktempfile(self.src_blocks[index]) self.shell.hooks.editor(filename, 1) - with open(Path(filename), "r", encoding="utf-8") as f: + with Path(filename).open("r", encoding="utf-8") as f: new_block = f.read() # update the source and colored block self.src_blocks[index] = new_block