python - PyCharm - Expected type 'Optional[IO[str]]', got 'TextIOWrapper[str]' instead -
after updating pycharm 2017.1, new inspection warning started pop in place everything's seemingly simple , correct. looks following:
it looks open()
doesn't return expected type file
parameter, code pretty straightforward and, importantly, work expected (using python 3.5.2).
python docs mention way using stringio
, removes warning indeed, but correct pythonic way specify output stream print
? if so, why? warning important follow?
the solution found type hint pycharm correctly:
with open('output_filename', 'w') f: # type: optional[io[str]] print('some text go file...', file=f)
this keeps pycharm happy , not in way impede correct running of code.
Comments
Post a Comment