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

gh-123446: Fix empty function names in TypeErrors in _csv module #123461

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Aug 29, 2024

After:

>>> import _csv
>>> _csv.reader()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    _csv.reader()
    ~~~~~~~~~~~^^
TypeError: _csv.reader expected at least 1 argument, got 0
>>> _csv.writer()
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    _csv.writer()
    ~~~~~~~~~~~^^
TypeError: _csv.writer expected at least 1 argument, got 0
>>> _csv.register_dialect()
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    _csv.register_dialect()
    ~~~~~~~~~~~~~~~~~~~~~^^
TypeError: _csv.register_dialect expected at least 1 argument, got 0

Questions:

  1. Do I need to test this? Seems minor enough
  2. _csv. or csv.? Technically the module is _csv, but users can see this when these names are re-exported in csv module. I prefer to show the real name.

CC @hauntsaninja, because you have several recent commits to this module.
CC @serhiy-storchaka, because you commented on the issue.

@hauntsaninja hauntsaninja enabled auto-merge (squash) August 29, 2024 06:50
@hauntsaninja hauntsaninja merged commit 303f92a into python:main Aug 29, 2024
40 checks passed
@@ -1072,7 +1072,7 @@ csv_reader(PyObject *module, PyObject *args, PyObject *keyword_args)
return NULL;
}

if (!PyArg_UnpackTuple(args, "", 1, 2, &iterator, &dialect)) {
if (!PyArg_UnpackTuple(args, "_csv.reader", 1, 2, &iterator, &dialect)) {
Copy link
Member

Choose a reason for hiding this comment

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

This unnecessary exposes the implementation detail (the private module name).

>>> import csv
>>> csv.reader
<built-in function reader>
>>> csv.reader()
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    csv.reader()
    ~~~~~~~~~~^^
TypeError: _csv.reader expected at least 1 argument, got 0

Compare with:

>>> import os
>>> os.mkdir()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    os.mkdir()
    ~~~~~~~~^^
TypeError: mkdir() missing required argument 'path' (pos 1)

Copy link
Member Author

@sobolevn sobolevn Aug 29, 2024

Choose a reason for hiding this comment

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

Yes, this was my open question. I will remove the module name.

@hauntsaninja sorry, I should have made this more clear :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants