python / python/mypy

Plugins and overloads don't interact well

Open
#7,367 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs discussion priority-0-high topic-overloads topic-plugins
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

While working on our own plugin for self-checking proper types and isinstance() I have tried to use get_function_hook() to emit some additional errors for overloaded functions. However this didn't work for three reasons:

  • The hook is called for every item in the overload, not for the overload as a whole.
  • The overload logic relies on empty Messages as a sign of successful match
  • The errors emitted during overload selection are discarded afterwards, thus discarding the plugin generated errors

This issue can be fixed in three ways:

  • Calling the hook on the overload as a whole after selecting the overload variant and type checking it (this however will be a breaking API change)
  • Use newly added error codes to only abandon a variant if the error is due to bad argument type (this is however still bad because check_call() may have an accept() call possibly triggering almost arbitrary error including a nested function call with bad argument type).
  • Use a boolean attribute somewhere that will be set by check_argument_types() and will be reset after return from every accept().

I am leaning towards the last option, since it is most principled IMO.

cc @Michael0x2a

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing get_function_hook() through overload selection, check_call(), check_argument_types(), and accept(). Compare how overload matching uses empty Messages and how plugin errors are discarded. Done means plugin-generated errors survive overload selection without incorrectly rejecting valid overload variants, while keeping the selected behavior consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.