Skip to content

Cannot resolve common type of logging.Handler subclasses #12690

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
nickeldan opened this issue Apr 28, 2022 · 1 comment
Closed

Cannot resolve common type of logging.Handler subclasses #12690

nickeldan opened this issue Apr 28, 2022 · 1 comment
Labels
bug mypy got something wrong topic-join-v-union Using join vs. using unions

Comments

@nickeldan
Copy link

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.

@nickeldan nickeldan added the bug mypy got something wrong label Apr 28, 2022
@JelleZijlstra JelleZijlstra added the topic-join-v-union Using join vs. using unions label Apr 28, 2022
@brianschubert
Copy link
Collaborator

Fixed in #17408, which was released with v1.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-join-v-union Using join vs. using unions
Projects
None yet
Development

No branches or pull requests

3 participants