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

str is number methods don't recognize '.' #62940

Closed
ronadam mannequin opened this issue Aug 14, 2013 · 6 comments
Closed

str is number methods don't recognize '.' #62940

ronadam mannequin opened this issue Aug 14, 2013 · 6 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ronadam
Copy link
Mannequin

ronadam mannequin commented Aug 14, 2013

BPO 18740
Nosy @brettcannon, @ned-deily, @ezio-melotti

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 2013-08-14.18:55:05.408>
created_at = <Date 2013-08-14.16:55:43.345>
labels = ['interpreter-core', 'type-bug']
title = "str is number methods don't recognize '.'"
updated_at = <Date 2013-08-16.13:10:03.637>
user = 'https://bugs.python.org/ronadam'

bugs.python.org fields:

activity = <Date 2013-08-16.13:10:03.637>
actor = 'ezio.melotti'
assignee = 'none'
closed = True
closed_date = <Date 2013-08-14.18:55:05.408>
closer = 'brett.cannon'
components = ['Interpreter Core']
creation = <Date 2013-08-14.16:55:43.345>
creator = 'ron_adam'
dependencies = []
files = []
hgrepos = []
issue_num = 18740
keywords = []
message_count = 6.0
messages = ['195186', '195188', '195197', '195203', '195204', '195323']
nosy_count = 4.0
nosy_names = ['brett.cannon', 'ron_adam', 'ned.deily', 'ezio.melotti']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue18740'
versions = ['Python 3.4']

@ronadam
Copy link
Mannequin Author

ronadam mannequin commented Aug 14, 2013

Shouldn't at least isdecimal return True?

>>> '123.0'.isdecimal()
False
>>> '123.0'.isalnum()
False
>>> '123.0'.isnumeric()
False
>>> '123.0'.isdigit()
False

@ronadam ronadam mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Aug 14, 2013
@ned-deily
Copy link
Member

isdecimal() is working as documented, isn't it? A period character serving as a decimal point is not the same as a decimal character.

"Return true if all characters in the string are decimal characters and there is at least one character, false otherwise. Decimal characters are those from general category “Nd”. This category includes digit characters, and all characters that can be used to form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO."

@brettcannon
Copy link
Member

Ned is right, everything is working as documented and intended: as a way to avoid using a regex to test a simple case instead of trying to do anything fancy like identify a number.

@ronadam
Copy link
Mannequin Author

ronadam mannequin commented Aug 14, 2013

I get the same resluts if I make the string by str(123.0). I was thinking it should test True for the isdecimal case for that.

It seems I missunderstood their purpose/use. This seems like it would be a very common misunderstanding.

It appears, (Because it isn't stated in the doc strings), that they are for testing what specific sub-group of unicode data, the individual character(s) are in. I think the methods doc strings should say this and be worded so they are more character specific.

""" Tests each character, and returns true if
all of them are in the unicode _______ sub-group. """

As for testing weather or not a string as a whole represents a number value, it seems try/except is still the best way. :-/

@brettcannon
Copy link
Member

Feel free to submit an issue suggesting better docstrings as that sounds like it could stand to get some TLC.

@ezio-melotti
Copy link
Member

it seems try/except is still the best way. :-/

Indeed: http://docs.python.org/dev/glossary#term-eafp

@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
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants