8000 False negative: Incorrect return type overlooked when it is an alias to Union[T, …] · Issue #15803 · python/mypy · GitHub
[go: up one dir, main page]

10000 Skip to content
False negative: Incorrect return type overlooked when it is an alias to Union[T, …] #15803
@lukasjuhrich

Description

@lukasjuhrich

Bug Report

This may be related to #12211.
When extracting a type annotation like -> t.AnyStr | int to a t.Union alias, mypy fail to detect incorrect return types.

The actual problem for me was that annotating flask view functions with ResponseValueType did not find obvious return type violations, but (as I found out during writing of this issue) a workaround seems to have been added.

I'm unsure what to expect of mypy here but silently allowing everything seems like a big hazard to me.

To Reproduce
See the functions foo2 and bar2 in the following gist:
https://mypy-play.net/?mypy=latest&python=3.11&gist=04f598b90124f58021cf19209a7df967.

Expected Behavior

the return statements of foo2 and bar2 should cause an error, either the same error as foo and bar or the same as foo3 and bar3.

Actual Behavior

foo2 and bar2 don't cause an error

Your Environment

  • Mypy version used: 1.4.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0