Skip to content

gh-101100: Fix references in csv docs #114658

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 5 commits into from
Jan 30, 2024
Merged

Conversation

smontanaro
Copy link
Contributor

@smontanaro smontanaro commented Jan 27, 2024

This is my first attempt at this. Hopefully I've done it correctly. I would appreciate checks on my changes and the mechanics (is gh-101100 the correct issue to reference?). Thanks to @hugovk for helping me get started. There are two types of changes herein:

  1. The usual reference fixes.
  2. A small wording change to the Dialect documentation reflecting that it really doesn't have any callable methods, and – in particular – lacks a validate method. (Validation is implicit when instantiating the class.)

With these changes, nitpicky mode in Sphinx seems happy with csv.rst.


📚 Documentation preview 📚: https://cpython-previews--114658.org.readthedocs.build/

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

is #101100 the correct issue to reference?

Yep :)

With these changes, nitpicky mode in Sphinx seems happy with csv.rst.

And the CI has failed... But in a good way! It says:

Congratulations! You improved:

Doc/library/csv.rst

Please remove from Doc/tools/.nitignore

Doing this means the CI will also prevent new warnings from appearing in this file.

@@ -492,9 +492,9 @@ DictReader objects have the following public attribute:
Writer Objects
--------------

:class:`Writer` objects (:class:`DictWriter` instances and objects returned by
:class:`Writer<writer>` objects (:class:`DictWriter` instances and objects returned by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually add a space here:

Suggested change
:class:`Writer<writer>` objects (:class:`DictWriter` instances and objects returned by
:class:`Writer <writer>` objects (:class:`DictWriter` instances and objects returned by

Although, I don't see a Writer class with capital W, is it only capitalised because it begins the sentence? If so, I'd either reword so it's not first, or leave it lowercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I left it capitalized. I suspect the original author may have done it that way. I just added a proper reference. The csv module dates from the days when types (written in C) and classes (written in Python) were not quite the same thing. Type names generally weren't capitalized (I think, hence csv.writer), while classes were, hence csv.DictWriter.

@hugovk hugovk added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jan 27, 2024
@smontanaro
Copy link
Contributor Author

@hugovk I think I made all the suggested changes...

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Just want to double check the write.

@@ -88,7 +88,7 @@ The :mod:`csv` module defines the following functions:

Return a writer object responsible for converting the user's data into delimited
strings on the given file-like object. *csvfile* can be any object with a
:func:`write` method. If *csvfile* is a file object, it should be opened with
:meth:`~io.TextIOBase.write` method. If *csvfile* is a file object, it should be opened with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serhiy-storchaka Is this the correct one for write in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I mulled that over a bit before using TextIOBase, eventually deciding that since CSV files are supposed to be opened as plain text files since Python 3, that was the most reasonable link destination.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also explicitly mention that write() should accept a string argument (not bytes). And the same for the reader.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Perhaps we can rename csvwriter to writer, but it is a separate issue, and it may have pitfalls.

@@ -88,7 +88,7 @@ The :mod:`csv` module defines the following functions:

Return a writer object responsible for converting the user's data into delimited
strings on the given file-like object. *csvfile* can be any object with a
:func:`write` method. If *csvfile* is a file object, it should be opened with
:meth:`~io.TextIOBase.write` method. If *csvfile* is a file object, it should be opened with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is.

@smontanaro
Copy link
Contributor Author

Perhaps we can rename csvwriter to writer, but it is a separate issue, and it may have pitfalls.

Since there is no type called csvwriter, what pitfalls would correcting those references be?

@serhiy-storchaka
Copy link
Member

csv.writer is not a class, csv.writer() returns an instance of _csv.Writer class which is not exposed itself. writerow() is defined as a method of a fictional class csvwriter, but actually it is a description of writerow() in unrelated classes _csv.Writer and csv.DictWriter. csv.DictWriter is not a subclass of _csv.Writer or csv.writer (which is not even a class). All so complicated, that I cannot predict what Sphinx will produce. We have to try and see at the result. All can just work, or produce glitches from which we could not know how to get rid.

@hugovk
Copy link
Member

hugovk commented Jan 28, 2024

In the spirit of incremental changes, shall we merge this as-is (it does what it set out to do: fix reference warnings), and make a new PR for any further changes?

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) January 30, 2024 21:51
@serhiy-storchaka serhiy-storchaka merged commit 3911b42 into python:main Jan 30, 2024
@miss-islington-app
Copy link

Thanks @smontanaro for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @smontanaro and @serhiy-storchaka, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3911b42cc0d404e0eac87fce30b740b08618ff06 3.12

@miss-islington-app
Copy link

Sorry, @smontanaro and @serhiy-storchaka, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3911b42cc0d404e0eac87fce30b740b08618ff06 3.11

smontanaro added a commit to smontanaro/cpython that referenced this pull request Jan 30, 2024
Co-authored-by: Hugo van Kemenade <[email protected]>
(cherry picked from commit 3911b42)
@smontanaro
Copy link
Contributor Author

@serhiy-storchaka @hugovk I attempted to create the two pull requests. Please take a look and let me know if I missed something or resolved the .nitignore conflict incorrectly (quite possible).

@zware
Copy link
Member

zware commented Jan 30, 2024

I haven't reviewed the content of GH-114771 (3.12) or GH-114773 (3.11), but the diffs look a lot better with the right base branches :)

@smontanaro
Copy link
Contributor Author

smontanaro commented Jan 30, 2024

Not sure what you're referring to. I was just executing the cherry-picker commands the bedevere not have. Did I mess something up?

@zware
Copy link
Member

zware commented Jan 30, 2024

I don't know if it was you or cherry_picker, but the PRs were based on main rather than their respective 3.12 or 3.11 branch.

The PR branches themselves were fine, though. That is, the error was in the creation of the PRs, not the creation of the backports.

@smontanaro
Copy link
Contributor Author

That's weird. I did run the commands from my 3.12 and 3.11 repos.

@serhiy-storchaka serhiy-storchaka changed the title gh-101100: ref fixes for csv doc gh-101100: Fix references in csv docs Jan 31, 2024
@bedevere-app
Copy link

bedevere-app bot commented Jan 31, 2024

GH-114771 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Jan 31, 2024
@bedevere-app
Copy link

bedevere-app bot commented Jan 31, 2024

GH-114773 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Jan 31, 2024
serhiy-storchaka pushed a commit that referenced this pull request Jan 31, 2024
Co-authored-by: Hugo van Kemenade <[email protected]>
(cherry picked from commit 3911b42)
serhiy-storchaka pushed a commit that referenced this pull request Jan 31, 2024
Co-authored-by: Hugo van Kemenade <[email protected]>
(cherry picked from commit 3911b42)
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants