I am using rsplit
to split up a path name,
rootPath = os.path.abspath(__file__)
rootPath = (rootPath.rsplit('/', 1)[0]).rsplit('/', 1)[0]
But Pycharm warns,
expected type
optional [bytes]
, gotstr
instead
In python doc
, it stated using sep
as the delimiter string.
So how to fix this?
In general, what PyCharm and the error is essentially warning you about is that the parameter has to either be None or bytes. That's what Optional means, Optional [type] is either None or type which in your case is bytes. In a simple Python REPL the message is slightly different but the gist is the same:
If it's getting it wrong, it's best to raise a ticket with them to see if it can be fixed. On the sidebar, click Inspections (under the Editor category) PyCharm should now stop issuing warnings about incorrect function arguments. Doesn't work. Tested on PyCharm 2019.1.2 (Community Edition).
@Stack: I don't get an error. Only the warning from PyCharm. If you actually run expit (0.0) you get neither an error, nor a warning, just the result. I think the question whether to modify the code or to ignore/disable the warning depends mostly on taste and personal preference.
It seems like rootPath is being treated as a bytes object (a small bug maybe?) or the warning is for another part. In general, what PyCharm and the error is essentially warning you about is that the parameter has to either be None or bytes. That's what Optional means, Optional [type] is either None or type which in your case is bytes.
It seems like rootPath
is being treated as a bytes object (a small bug maybe?) or the warning is for another part.
In general, what PyCharm and the error is essentially warning you about is that the parameter has to either be None
or bytes
. That's what Optional
means, Optional[type]
is either None
or type
which in your case is bytes
.
In a simple Python REPL the message is slightly different but the gist is the same:
b'hello/world'.rsplit('/') # error bytes-like object required
Instead you need to supply a byte
separator:
b'hello/world'.rsplit(b'/')
or None
in order to get it to work.
Either there's a small bug in PyCharm and it's reporting rsplit
incorrectly here or the warning is for another part of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With