Skip to content

Cannot resolve common type of logging.Handler subclasses #12690

Description

@nickeldan

I've got this MRE:

import logging

stream_handler = logging.StreamHandler()
file_handler = logging.FileHandler('output.txt')
logger = logging.getLogger()
for handler in (stream_handler, file_handler):
    logger.addHandler(handler)

mypy 0.942 with Python 3.9.5 complains

error: Argument 1 to "addHandler" of "Logger" has incompatible type "object": expected "Handler"

reveal_type says that stream_handler is a logging.StreamHandler[typing.TextIO] whereas file_handler is a logging.FileHandler.

The error doesn't appear with mypy 0.910.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-join-v-unionUsing join vs. using unions

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions