Skip to content

“no-matching-overload” instantiating logging.StreamHandler #258

@turian

Description

@turian

Summary

error: lint\:no-matching-overload: No overload of bound method `__init__` matches arguments

for this minimal example:

import logging
h = logging.StreamHandler()          # ← error

Why this is unexpected

  • The CPython docs and runtime accept a zero-argument constructor that defaults to sys.stderr.

  • typeshed’s logging/__init__.pyi reflects that signature:

      class StreamHandler(Handler):
          def __init__(self, stream: IO[str] | None = ...) -> None: ...
    
  • Ty’s own stub—red_knot/builtins/logging.pyi—still exposes the old overloads that take filename | PathLike and therefore rejects the common no-argument form.

Because of that divergence, projects that pass mypy/ruff/mkdocs etc. must add:

handler = logging.StreamHandler()          # ty: ignore

and then hit issue #130 when the code is split across lines.

Repro

  1. echo 'import logging; logging.StreamHandler()' > t.py
  2. ty check t.py

Expected

No diagnostics.

Actual

lint:no-matching-overload

Proposed fix

Import logging and update the StreamHandler overloads in Ty’s stdlib stubs to match typeshed (i.e., make the first positional argument an optional IO[str], default None).


This bug is separate from #130 (“unused suppression for type: ignore”) – that issue only appears because we’re forced to ignore this stub mismatch.

Version

0.0.0-alpha.7 (905a3e1 2025-05-07)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggenericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions