[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Eric V. Smith


Eric V. Smith  added the comment:

I (and many others) think the error message is fine the way it is. Also, it's 
hard for the error to be more specific about the method it's being called on. 
But if you have some concrete suggestions that can be implemented, you can add 
them to this issue.

--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


Alex Zaslavskis  added the comment:

What about adding alert message for beginners that can stuck with that in docs? 
To warn others , is that good idea you think. Or it is redundant ?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


Alex Zaslavskis  added the comment:

Thanks that really works. 
So as I understand that b''.split() != ''.split()

--
resolution:  -> not a bug

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Eric V. Smith


Eric V. Smith  added the comment:

You said: 
"""
b''.split(',') # gives strange error message.

TypeError: a bytes-like object is required, not 'str'
"""

It is not a strange error message. You passed in a str (the ','), and you 
should have passed in bytes.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


Alex Zaslavskis  added the comment:

Moreover according Python docs : This exception may be raised by user code to 
indicate that an attempted operation on an object is not supported. But also 
the Python interpreter gives that  a bytes-like object is required, not 'str' 
that I am already passing , so it says that all fine. But the question is why 
then TypeError happens .

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


Alex Zaslavskis  added the comment:

''.split(',') # works as it should be 
b''.split(',') # gives strange error message.

TypeError: a bytes-like object is required, not 'str'

The problem here is that message is saying that for fix error you should use 
bytes-like object that not a true. In reality the string or None is required .

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


Alex Zaslavskis  added the comment:

I am not really sure that it is working as it should be. Even with your example 
it gives : 
TypeError: a bytes-like object is required, not 'str'
The problem is why error message says that  bytes-like is  required , when the 
string is required.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Eric V. Smith


Eric V. Smith  added the comment:

This is working as designed. The error is telling you that the argument to 
bytes.split() must be a string:

>>> b''.split(',')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: a bytes-like object is required, not 'str'

>>> b''.split(b',')
[b'']

Same for str.split():

>>> ''.split(b',')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: must be str or None, not bytes

>>> ''.split(',')
['']

--
components:  -Argument Clinic
nosy: +eric.smith -larry

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


Change by Alex Zaslavskis :


Removed file: https://bugs.python.org/file50257/bug_in_python.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


Change by Alex Zaslavskis :


Added file: https://bugs.python.org/file50258/bug_in_python.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


Change by Alex Zaslavskis :


--
type: compile error -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45087] Confusing error message when trying split bytes.

2021-09-02 Thread Alex Zaslavskis


New submission from Alex Zaslavskis :

If we will try to split bytes we will got quite strange error in console. 

Traceback (most recent call last):
  File "C:/Users/ProAdmin/Desktop/bug_in_python.py", line 6, in 
byte_message.split(",")
TypeError: a bytes-like object is required, not 'str'

The problem here is that object should be string and in if I convert it to 
string the error is going. So that mean that there are error in mistake . 
Correct variant should be :
Traceback (most recent call last):
  File "C:/Users/ProAdmin/Desktop/bug_in_python.py", line 6, in 
byte_message.split(",")
TypeError:  str is required, not a bytes-like object


message = 'Python is fun'
byte_message = bytes(message, 'utf-8')
print(byte_message)
#byte_message.split(",") causes error
str(byte_message).split(",") # works

--
components: Argument Clinic
files: bug_in_python.py
messages: 400948
nosy: larry, sahsariga111
priority: normal
severity: normal
status: open
title: Confusing error message when trying split bytes.
type: compile error
versions: Python 3.9
Added file: https://bugs.python.org/file50257/bug_in_python.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com