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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -