Skip to content

int allowed in places expecting float #11385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cristicbz opened this issue Oct 25, 2021 · 2 comments
Closed

int allowed in places expecting float #11385

cristicbz opened this issue Oct 25, 2021 · 2 comments
Labels
bug mypy got something wrong

Comments

@cristicbz
Copy link

cristicbz commented Oct 25, 2021

Bug Report

Mypy seems to treat int as a subtype of float even though python doesn't think so and in some cases they are not interchangeable. We hit this multiple times: with FFI, using some strict runtime type assertions, and comparing json output of "equal" inputs where the inputs differed in float-ness and therefore the strings ended up having .0 only some of the time.

While I understand why, in some less-strict codebases this may be desireable, it would be good to at least be able to opt out of this.

To Reproduce

def foo(x: float) -> None:
    assert isinstance(x, float)

foo(10) 

Expected Behavior

mypy rejects the call to foo in the example

Actual Behavior

mypy accepts the call to foo in the example, but the program fails at runtime.

Your Environment

  • Mypy version used: mypy==0.910
  • Mypy command-line flags: mypy example.py
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
exclude=.*_pb2[.]py
check_untyped_defs=True
disallow_any_generics=True
disallow_incomplete_defs=True
disallow_subclassing_any=True
disallow_untyped_defs=True
ignore_missing_imports=True
no_implicit_optional=True
strict_optional=True
warn_return_any=True
warn_unused_ignores=True
plugins = pydantic.mypy

[pydantic-mypy]
init_typed = True
  • Python version used: 3.8.10
  • Operating system and version: Ubuntu 20.04
@cristicbz cristicbz added the bug mypy got something wrong label Oct 25, 2021
@cristicbz cristicbz changed the title int allowed in places expecting `float int allowed in places expecting float Oct 25, 2021
@cristicbz
Copy link
Author

Related to, but different from #6060

@srittau
Copy link
Contributor

srittau commented Oct 25, 2021

This behavior is mandated by PEP 484.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants