Skip to content

[BUG]: SupportsInt and SupportsFloat changes cause type checking failures on python classes that override these functions #5767

@daltairwalter

Description

@daltairwalter

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

3.0.0

Problem description

#5540 changed type hints from int and float to SupportsInt and SupportsFloat. While these may be nice for use cases where a C++ module is exposed to python, this is causing a lot of type problems for cases where a C++ function is trampolined and overridden in python. The base class is now using SupportsInt and SupportsFloat and this is more generic than the python derived classes that uses int, float so mypy issues errors like:

Argument 1 of "pdf" is incompatible with supertype "Distribution"; supertype defines the argument
type as "SupportsFloat" [override]
def pdf(self, x: float) -> float:

Am I missing something here, or is there a way to turn this feature off?

Reproducible example code


Is this a regression? Put the last known working version here if it is.

smartholder branch on 2024-08-09

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions