13559.bugfix.rst


Overview

This file documents a bug fix related to the type annotation in the `pytest` testing framework, specifically concerning the `addini` method of the `pytest.Parser` class. The fix involves adding missing `int` and `float` variants to the `Literal` type annotation of the `type` parameter in the method signature.

The purpose of this fix is to enhance the accuracy and completeness of type annotations, which improves static type checking and developer experience when using or extending the `pytest` framework.


Detailed Explanation

Context

In `pytest`, configuration options can be added via the `addini` method on a `Parser` object. These options can have different expected data types, such as strings, integers, or floats. Prior to this fix, the `type` parameter's type annotation in `addini` did not explicitly include `int` and `float` as valid literals, which could cause type-checking tools to flag errors or warnings when these types were used.

Changes Introduced

No functional code changes were made; this is purely a type annotation improvement.


Classes and Methods Affected

pytest.Parser.addini


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class Parser {
        +addini(name: str, help: str, type: Literal['args', 'bool', 'path', 'linelist', 'string', 'int', 'float'] = 'string', default: Union[str, int, float, List[str], None] = None) void
    }

This class diagram highlights the `Parser` class with the updated `addini` method, showing the relevant method signature including the fixed type annotation for the `type` parameter.


Summary

This bug fix primarily enhances the typing metadata for the [pytest.Parser.addini](/projects/286/67266) method by including `int` and `float` as valid literals for the `type` parameter. It helps maintain pytest's robustness and developer friendliness without modifying any runtime logic.

By ensuring correct and comprehensive type annotations, this fix facilitates better static analysis, reduces potential bugs related to configuration option types, and supports future maintainability of the pytest codebase.