Skip to content

Use standard formatting for note on unexpected keyword#20808

Merged
ilevkivskyi merged 2 commits intopython:masterfrom
ilevkivskyi:defined-here-standard
Feb 14, 2026
Merged

Use standard formatting for note on unexpected keyword#20808
ilevkivskyi merged 2 commits intopython:masterfrom
ilevkivskyi:defined-here-standard

Conversation

@ilevkivskyi
Copy link
Member

Closes #4773
Closes #10480
Closes #20640

Currently this is the only message that uses this non-standard formatting, while:

  • Some users find it confusing
  • We need ~400 lines of code to support this special case
  • It still has bugs that will require even more special-casing in various places to fix them.

So here I implement a minimal change I propose in #4773, namely use this (standard) format:

main.py:5: error: Unexpected keyword argument "location" for "method" of "Class"
main.py:5: note: "method" defined in "pkg.mod"

if the function is defined in a different module.

If we want to, we can add extra info (like available argument names with same type), as well as start using this note in more places in separate PRs.

@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
Member Author

Hm, looking at the mypy_primer output I think we should skip this note for builtins and typing, it doesn't look very helpful.

@github-actions
Copy link
Contributor

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

prefect (https://github.com/PrefectHQ/prefect)
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:139: note: "__init_subclass__" of "object" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:139: note: "__init_subclass__" of "object" defined here
+ src/prefect/states.py:581: note: "resolve_result_storage" defined in "prefect.results"
- src/prefect/results.py:166: note: "resolve_result_storage" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:139: note: "__init_subclass__" of "object" defined here
- src/prefect/blocks/core.py:1545: note: "register_type_and_schema" of "Block" defined here
+ src/prefect/results.py:183: note: "load" defined in "prefect.blocks.core"
- src/prefect/blocks/core.py:1137: note: "load" of "Block" defined here
- src/prefect/results.py:104: note: "get_default_result_storage" defined here
- src/prefect/results.py:166: note: "resolve_result_storage" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:139: note: "__init_subclass__" of "object" defined here
+ src/prefect/flows.py:601: note: "load_from_ref" defined in "prefect.blocks.core"
- src/prefect/blocks/core.py:1302: note: "load_from_ref" of "Block" defined here
- src/prefect/deployments/runner.py:1250: note: "from_storage" of "RunnerDeployment" defined here
+ src/prefect/flows.py:946: note: "from_storage" defined in "prefect.deployments.runner"
- src/prefect/results.py:166: note: "resolve_result_storage" defined here
+ src/prefect/flows.py:2548: note: "resolve_result_storage" defined in "prefect.results"
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:139: note: "__init_subclass__" of "object" defined here
- src/prefect/results.py:397: note: "update_for_flow" of "ResultStore" defined here
+ src/prefect/flow_engine.py:493: note: "update_for_flow" defined in "prefect.results"
+ src/prefect/flow_engine.py:813: note: "update_for_flow" defined in "prefect.results"
+ src/prefect/flow_engine.py:1097: note: "update_for_flow" defined in "prefect.results"
+ src/prefect/flow_engine.py:1414: note: "update_for_flow" defined in "prefect.results"
+ src/prefect/task_engine.py:777: note: "update_for_task" defined in "prefect.results"
- src/prefect/results.py:473: note: "update_for_task" of "ResultStore" defined here
- src/prefect/artifacts.py:84: note: "create" of "Artifact" defined here
- src/prefect/artifacts.py:151: note: "get" of "Artifact" defined here
- src/prefect/artifacts.py:248: note: "format" of "Artifact" defined here
- src/prefect/artifacts.py:334: note: "format" of "ProgressArtifact" defined here

pydantic (https://github.com/pydantic/pydantic)
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/typing.pyi:1065: note: "evaluate_forward_ref" defined here
- .../projects/_pydantic_venv/lib/python3.14/site-packages/pydantic_core/_pydantic_core.pyi:76: note: "SchemaValidator" defined here
+ pydantic/plugin/_schema_validator.py:53: note: "SchemaValidator" defined in "pydantic_core._pydantic_core"
+ pydantic/plugin/_schema_validator.py:72: note: "SchemaValidator" defined in "pydantic_core._pydantic_core"
- .../projects/_pydantic_venv/lib/python3.14/site-packages/pydantic_core/_pydantic_core.pyi:300: note: "SchemaSerializer" defined here
+ pydantic/_internal/_model_construction.py:694: note: "SchemaSerializer" defined in "pydantic_core._pydantic_core"

starlette (https://github.com/encode/starlette)
- starlette/websockets.py:21: note: "WebSocketDenialResponse" defined here
+ starlette/testclient.py:155: note: "WebSocketDenialResponse" defined in "starlette.websockets"

zulip (https://github.com/zulip/zulip)
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "SubTest" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "SubmessageFixture" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "FileFixture" defined here

strawberry (https://github.com/strawberry-graphql/strawberry)
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:139: note: "__init_subclass__" of "object" defined here

core (https://github.com/home-assistant/core)
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:139: note: "__init_subclass__" of "object" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:139: note: "__init_subclass__" of "object" defined here

aiortc (https://github.com/aiortc/aiortc)
- .../projects/_aiortc_venv/lib/python3.14/site-packages/OpenSSL-stubs/SSL.pyi:144: note: "get_peer_certificate" of "Connection" defined here
+ src/aiortc/rtcdtlstransport.py:437: note: "get_peer_certificate" defined in "OpenSSL.SSL"

discord.py (https://github.com/Rapptz/discord.py)
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/typing.pyi:1046: note: "update" of "TypedDict" defined here

ibis (https://github.com/ibis-project/ibis)
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "Any" defined here
- ibis/expr/operations/generic.py:145: note: "Literal" defined here
+ ibis/expr/operations/tests/test_generic.py:112: note: "Literal" defined in "ibis.expr.operations.generic"
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "__init__" of "object" defined here

apprise (https://github.com/caronc/apprise)
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "IRCMessage" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "IRCAction" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "IRCContext" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "IRCContext" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "XMPPConfig" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "IRCContext" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "IRCAction" defined here
- ...venv/lib/python3.14/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "XMPPConfig" defined here

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Nice! Great that this is so much cleaner too

@ilevkivskyi ilevkivskyi merged commit b8b50b1 into python:master Feb 14, 2026
24 checks passed
@ilevkivskyi ilevkivskyi deleted the defined-here-standard branch February 14, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants