Skip to content

Add function definition notes for too_many_positional_arguments errors#21410

Open
KevinRK29 wants to merge 3 commits into
python:masterfrom
KevinRK29:note-defined-here
Open

Add function definition notes for too_many_positional_arguments errors#21410
KevinRK29 wants to merge 3 commits into
python:masterfrom
KevinRK29:note-defined-here

Conversation

@KevinRK29

@KevinRK29 KevinRK29 commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Followup to #20794

Adds the "foo" is defined in "bar" note for the too_many_positional_arguments error case

@github-actions

This comment has been minimized.

@KevinRK29 KevinRK29 marked this pull request as ready for review May 5, 2026 04:49
@KevinRK29 KevinRK29 requested review from JukkaL and ilevkivskyi May 5, 2026 04:49
Comment thread mypy/messages.py Outdated
@@ -972,6 +972,7 @@ def too_many_positional_arguments(self, callee: CallableType, context: Context)
msg = "Too many positional arguments" + for_function(callee)
self.fail(msg, context)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Looking at the primer, I think I may need to change it to self.fail(msg, context, code=codes.CALL_ARG) similar to the error cases above?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Usually we try to avoid changing the error code. But in this case this looks like an oversight. I leave this up to @JukkaL to decide.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's try switching to CALL_ARG and see if the mypy primer looks any worse. The current error code is inconsistent, so it's reasonable to change it if it doesn't cause a big fallout. If there are many new errors, we can use the misc error code for the note as well -- they both need to use the same error code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

looking at the latest primer, it seems like a lot of these new errors are from the projects that had # type: ignore[misc] silencing this error but now that we changed the error code and cause of that, an unused-ignore error. Not sure if this is an acceptable amount of errors, but if not, I can update the note to use the misc error code as well.

@github-actions

This comment has been minimized.

@JukkaL

JukkaL commented May 29, 2026

Copy link
Copy Markdown
Collaborator

There's one more thing that you can try. We support defining sub error codes by passing sub_code_of to ErrorCode. You could try defining a variant of call-arg error code that is a sub error code code of misc. It wouldn't replace the current call-arg error code but would only be used for this specific error that this PR deals with, i.e. there would be two slightly different call-arg error codes.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

mypy (https://github.com/python/mypy)
+ mypy/test/testtypes.py:239: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]

urllib3 (https://github.com/urllib3/urllib3)
+ test/with_dummyserver/test_poolmanager.py:659: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ tests/test_string_accessors.py:226: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/test_string_accessors.py:290: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:177: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:186: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:491: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:552: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:567: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:971: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:972: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:973: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:974: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:975: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:976: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/series/test_series.py:977: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]

cryptography (https://github.com/pyca/cryptography)
+ tests/hazmat/asn1/test_api.py:259: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/hazmat/asn1/test_api.py:574: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/hazmat/primitives/test_kbkdf.py:369: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ tests/hazmat/primitives/test_kbkdf.py:819: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]

xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_deprecation_helpers.py:18: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:22: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:26: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:34: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:42: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:46: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:60: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:83: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:87: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:91: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:100: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:104: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:113: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:117: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_deprecation_helpers.py:132: error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]
+ xarray/tests/test_groupby.py:2980: error: Unused "type: ignore[misc]" comment, use narrower [call-arg] instead of [misc] code  [unused-ignore]

@KevinRK29

Copy link
Copy Markdown
Collaborator Author

@ilevkivskyi @JukkaL is this an acceptable error in the primer? it only occurs when they use --warn-unused-ignores I believe, so I'd assume they'd want to know this information
error: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code [unused-ignore]

@JukkaL

JukkaL commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Yes, the primer looks acceptable. Can you look at the self check CI failures?

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