minrk / wurlitzer

Capture C-level stdout/stderr in Python
MIT License
194 stars 24 forks source link

Improper type hits deduced by liters #80

Open SebastianMorawiec opened 7 months ago

SebastianMorawiec commented 7 months ago

As part of our project we are using wurlitzer to redirect some of the outputs into the files. The problem I am facing is that library lacks type deduction, thus linters are trying to deduce types themselves leading to errors.

Even trying out the doc example (saved as test.py):

from io import StringIO
from wurlitzer import pipes, STDOUT

out = StringIO()
with pipes(stdout=out, stderr=STDOUT):
    print("test")

stdout = out.getvalue()

When running pyright test.py

I got the following error

  //:5:19 - error: Argument of type "StringIO" cannot be assigned to parameter "stdout" of type "int"
    "StringIO" is incompatible with "int" (reportGeneralTypeIssues)

This is basically a feature request - I can workaround it by silencing linters and type checkers for individual lines in my code.