Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unicode(None) anomaly #45649

Closed
jgsack mannequin opened this issue Oct 21, 2007 · 6 comments
Closed

unicode(None) anomaly #45649

jgsack mannequin opened this issue Oct 21, 2007 · 6 comments
Labels
topic-unicode type-bug An unexpected behavior, bug, or error

Comments

@jgsack
Copy link
Mannequin

jgsack mannequin commented Oct 21, 2007

BPO 1308
Nosy @loewis

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2007-10-22.06:03:09.441>
created_at = <Date 2007-10-21.20:45:10.517>
labels = ['type-bug', 'invalid', 'expert-unicode']
title = 'unicode(None) anomaly'
updated_at = <Date 2007-10-22.06:28:39.268>
user = 'https://bugs.python.org/jgsack'

bugs.python.org fields:

activity = <Date 2007-10-22.06:28:39.268>
actor = 'jgsack'
assignee = 'none'
closed = True
closed_date = <Date 2007-10-22.06:03:09.441>
closer = 'loewis'
components = ['Unicode']
creation = <Date 2007-10-21.20:45:10.517>
creator = 'jgsack'
dependencies = []
files = []
hgrepos = []
issue_num = 1308
keywords = []
message_count = 6.0
messages = ['56628', '56629', '56630', '56634', '56640', '56641']
nosy_count = 2.0
nosy_names = ['loewis', 'jgsack']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1308'
versions = ['Python 2.5']

@jgsack
Copy link
Mannequin Author

jgsack mannequin commented Oct 21, 2007

'2.5 (r25:51908, Apr 10 2007, 10:27:40) \n[GCC 4.1.2 20070403 (Red Hat
4.1.2-8)]'

unicode(None)
u'None'

This doesn't seem right, ;-)

Regards,
,,jim

@jgsack jgsack mannequin added topic-unicode type-bug An unexpected behavior, bug, or error labels Oct 21, 2007
@loewis
Copy link
Mannequin

loewis mannequin commented Oct 21, 2007

What answer did you expect instead?

@jgsack
Copy link
Mannequin Author

jgsack mannequin commented Oct 21, 2007

(aside: Wow! that was a fast response to my posting!)

I'm not really sure what makes the most sense,
possibly:

  • an exception
  • u''
  • None

but not u'None'; not a string of length 4. That's quite unexpected!

Regards,
..jim

PS: I don't understand why I couldn't reply via email. I got an autoresponse

You are not a registered user. Please register at:

http://bugs.python.org/user?@template=register

...before sending mail to the tracker.

Unknown address: jgsack...

I tried the registration, but that failed. I thought I _was_ registered.

Oh, well. :-[
..jim

@jgsack
Copy link
Mannequin Author

jgsack mannequin commented Oct 22, 2007

Here's more:

>>> unicode(object)
u"<type 'object'>"

There seems to be an call to repr() somewhere in the process.

This seems, at least to me, to violate the principle of least surprise, and
I'm thinking that unicode(x) ought to return UnicodeDecodeError if x is not
a string.

Maybe this is argueable. If so, I'd like to be educated. :-)

Regards,
..jim

@loewis
Copy link
Mannequin

loewis mannequin commented Oct 22, 2007

Ok. This is not a bug, but by design. unicode(X)==unicode(str(X)) for
most things, and str(X)==repr(X) for most things. repr(None)=='None',
hence the result you see. Closing as invalid.

P.S. To respond via email, you have to add your email address to Your
Details (you need to add all email addresses you want to use as From
addresses).

@loewis loewis mannequin closed this as completed Oct 22, 2007
@loewis loewis mannequin added the invalid label Oct 22, 2007
@jgsack
Copy link
Mannequin Author

jgsack mannequin commented Oct 22, 2007

Martin v. Löwis wrote:

Martin v. Löwis added the comment:

Ok. This is not a bug, but by design. unicode(X)==unicode(str(X)) for
most things, and str(X)==repr(X) for most things. repr(None)=='None',
hence the result you see. Closing as invalid.

P.S. To respond via email, you have to add your email address to Your
Details (you need to add all email addresses you want to use as From
addresses).

----------
resolution: -> invalid
status: open -> closed


Tracker <report@bugs.python.org>
<http://bugs.python.org/issue1308\>


OK, thanks Martin.

Now that I think about it, I do understand.

My difficulty (and source of my surprise) was in mistakenly thinking of
unicode() as performing a string translation operation (that is, an
operation on strings).

I would now say that it is better thought of as a representation
function quite parallel to the str() function.

With that mindset, there is no surprise.

Thanks again, for your prompt attention and useful replies.

Regards,
..jim

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-unicode type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants