Expected type 'optional[bytes]' got 'str' instead
Peter Otten
__peter__ at web.de
Fri Sep 16 03:54:17 EDT 2016
> Daiyue Weng wrote:
[Please answer to the mailing list instead of sending private emails]
> On 13 September 2016 at 12:37, Peter Otten <__peter__ at web.de> wrote:
>> Daiyue Weng wrote:
>>> Hi, I have the following piece of code,
>>>
>>> rootPath = os.path.abspath(__file__)
>>>
>>> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0]
>>>
>>>
>>> PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit,
>>>
>>> Expected type 'optional[bytes]' got 'str' instead
>>>
>>>
>>> If I changed it to,
>>>
>>> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit(b'\\', 1)[0]
>>>
>>> Python game me errors,
>>>
>>> TypeError: Can't convert 'bytes' object to str implicitly
>>>
>>> How to fix it?
>>
>> Do you use Python 2 or 3?
>>
>> Is your version the one PyCharm expects and supports? If yes, consider
>> filing a bug report (for PyCharm, not Python).
>>
>> You should of course still follow Chris' advice and use os.path to
>> manipulate file paths.
> Hi, I am using Python 3.5.1 on PyCharm. Is it a bug in PyCharm?
I think it is.
More information about the Python-list
mailing list