-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Coercing strings and non-integer numbers to interpreter ID and channel ID #82186
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
Comments
Is it correct that strings, bytes objects, bytearrays, floats, fractions, decimals can be coerced to an interpreter ID? >>> import _xxsubinterpreters as interpreters
>>> id = interpreters.InterpreterID('10', force=True)
>>> id == 10
True
>>> id == 10.1
True
>>> id == '1_0'
True
>>> id == bytearray(b'10')
True Should not the constructor accept only ints and int-like objects and the comparison return True only for integer numbers? There are other bugs here: raising OverflowError on comparison with large numbers and silencing all errors in some circumstances that can lead to returning a wrong result when errors like KeyboardInterrupt, RecursionError, MemoryError are occurred. |
Urk! Having Are interpreter.InterpreterID objects hashable? If so, we've got a violation of the rule that |
PR 15652 fixes some bugs. But I am not sure that floats and strings (and bytearrays, and fractions) should be accepted in constructors and several other functions. Although there was a test for strings. What is a use case? Should not an ID be an integer? |
Regardless of the intention of the _xx... author, intransitive equality is objectionable as it violates the assumption of sets and dicts. We went through this before with decimal.Decimal when the original implementation had 1.0 == 1 == Decimal(1) but 1.0 != Decimal(1). The latter was fixed. Here, I think the fix should be to not make the id be equal to everything it can be derived from. |
I have doubts about accepting floats and bytes objects in all function that accept InterpreterID or ChannelID. Is it intentional? There are tests for strings. |
There is more serious issue: InterpreterID and ChannelID are declared as int subclasses, but actually they have incompatible structure, so using them as int causes a crash. For example, the following code is crashed:
|
I would remove also converting a string to InterpreterID. The code would be simpler without it. I left it because there was explicit tests for it, but what is a use case for InterpreterID(string)? |
Yeah, dropping str support is fine. It wouldn't be hard to add it back in if later we find it's useful. :) |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: