python / python/mypy

`--disallow-untyped-calls` reports errors in untyped functions

Open
#12,912 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Using --disallow-untyped-calls and --check-untyped-defs results in errors about calling untyped functions in a typed context, even when calling from an untyped function.

To Reproduce

Test case:

[case testDisallowUntypedCallsFromUntypedFunction]
# flags: --disallow-untyped-calls --check-untyped-defs

def f(x):
    pass

def g(y):
    f(y)

Expected Behavior

Either:

  • the documentation and the error message should be updated to specify that --disallow-untyped-calls disallows all calls to untyped functions, regardless of whether the current function has type annotations, or
  • the above code shouldn't produce any errors

Actual Behavior

The call to f in the above example produces the error "Call to untyped function "f" in typed context".

Your Environment

See https://mypy-play.net/?mypy=latest&python=3.10&flags=check-untyped-defs%2Cdisallow-untyped-calls&gist=3350fe27968b29dabc5ef1e207d008ce to reproduce.

This came up in #12901 (specifically the mypy_primer diff had an error here)

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 with the test case named testDisallowUntypedCallsFromUntypedFunction and reproduce it with --disallow-untyped-calls and --check-untyped-defs. Trace how the call to f is classified inside g, then resolve whether the intended fix is updated documentation and wording or changed behavior so the test no longer errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.