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:

screenshot

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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -