Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pathlib in utils.openpy #12559

Merged
merged 4 commits into from
Oct 13, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion IPython/utils/openpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io
from io import TextIOWrapper, BytesIO
from pathlib import Path
import re
from tokenize import open, detect_encoding

Expand Down Expand Up @@ -72,7 +73,8 @@ def read_py_file(filename, skip_encoding_cookie=True):
-------
A unicode string containing the contents of the file.
"""
with open(filename) as f: # the open function defined in this module.
filepath = Path(filename)
with filepath.open() as f: # the open function defined in this module.
Carreau marked this conversation as resolved.
Show resolved Hide resolved
if skip_encoding_cookie:
return "".join(strip_encoding_cookie(f))
else:
Expand Down