Repository navigation
MNT: Run PTH flake test in prep for supporting pathlib (io.ascii) #16954
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import typing | ||
| import warnings | ||
| from io import StringIO | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
|
|
||
|
|
@@ -144,9 +145,8 @@ def _probably_html(table, maxchars=100000): | |
| return True | ||
|
|
||
| # Filename ending in .htm or .html which exists | ||
| if re.search(r"\.htm[l]?$", table[-5:], re.IGNORECASE) and os.path.exists( | ||
| os.path.expanduser(table) | ||
| ): | ||
| table_path = Path(table).expanduser() | ||
| if re.search(r"\.htm[l]?$", table[-5:], re.IGNORECASE) and table_path.is_file(): | ||
| return True | ||
|
|
||
| # Table starts with HTML document type declaration | ||
|
|
@@ -331,9 +331,8 @@ def _expand_user_if_path(argument): | |
| ) | ||
| if not is_str_data: | ||
| # Remain conservative in expanding the presumed-path | ||
| ex_user = os.path.expanduser(argument) | ||
| if os.path.exists(ex_user): | ||
| argument = ex_user | ||
| if (ex_user := Path(argument).expanduser()).exists(): | ||
| argument = str(ex_user) | ||
| return argument | ||
|
|
||
|
|
||
|
|
@@ -1006,7 +1005,7 @@ def write( | |
| ) | ||
|
|
||
| if isinstance(output, (str, bytes, os.PathLike)): | ||
| output = os.path.expanduser(output) | ||
| output = os.path.expanduser(output) # noqa: PTH111 | ||
| if not overwrite and os.path.lexists(output): | ||
| raise OSError(NOT_OVERWRITING_MSG.format(output)) | ||
|
|
||
|
|
@@ -1059,10 +1058,9 @@ def write( | |
| # behavior is for Python to translate \r\n (which we write because | ||
| # of os.linesep) into \r\r\n. Specifying newline='' disables any | ||
| # auto-translation. | ||
| output = open(output, "w", newline="") | ||
| output.write(outstr) | ||
| output.write(os.linesep) | ||
| output.close() | ||
|
Comment on lines
-1062
to
-1065
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should just be changed to an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| with open(output, "w", newline="") as output: | ||
| output.write(outstr) | ||
| output.write(os.linesep) | ||
| else: | ||
| output.write(outstr) | ||
| output.write(os.linesep) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taldcroft just out of pure curiosity, what is the purpose of the + "" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is to trigger a
TypeErroriftableisn't a string ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly what @neutrinoceros said. This is a very old idiom to check for string-like (somewhat like a protocol, asking if it supports appending a
str) instead of an explicitstrtype check.What's the best way to check for string-like? Or does
isinstance(table, str)cover all realistic use cases?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isinstanceis definitely more idiomatic here; I can't think of any type other thanstrthat accepts anotherstrin__add__Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From
BaseReader.readin core.py below, which uses the same construct, the only other input cases are file-like or list of strings (the table lines), so they should all be covered.