Skip to content

Conversation

@Eddy114514
Copy link
Collaborator

add warning for random.random() that in python 3 its string representation is longer (~18 digit) than python 2 (~14 digit).

as following:
image
image
image

@ltratt
Copy link
Member

ltratt commented Oct 22, 2025

Please force push a rebase against master before review.

@Eddy114514 Eddy114514 enabled auto-merge October 22, 2025 14:29
@Eddy114514 Eddy114514 disabled auto-merge October 22, 2025 14:29
@Eddy114514
Copy link
Collaborator Author

Please force push a rebase against master before review.

@ltratt , resolved, thanks for pointing out.

@ltratt
Copy link
Member

ltratt commented Oct 23, 2025

Please squash.

@ltratt
Copy link
Member

ltratt commented Oct 23, 2025

Hmm, actually, maybe I'm wrong.

Isn't this warning going to be annoying? Even if someone has updated their code, they're still going to get the "change your code" warning AFAICS?

@Eddy114514
Copy link
Collaborator Author

Hmm, actually, maybe I'm wrong.

Isn't this warning going to be annoying? Even if someone has updated their code, they're still going to get the "change your code" warning AFAICS?

@ltratt I think you are right about the warning behavior of my implementation. I think it is generally hard to detect whether user change their code within the warning.

Since the warning is about length of random.random(), maybe I should put warning inside of len() or __str__ method of random.random (if there is one) such that it is less frequent. But I think it still can't detect whether user change their code or not.

@ltratt
Copy link
Member

ltratt commented Oct 23, 2025

What one would need to do is track the string output by random.random and then see if someone does something "bad" on it (e.g. len). There are various ways one could do this.

For example, @nanjekyejoannah can fill you in on the bstate idea we've long been working towards. A variant of that would work here: one could (say) add a bool to PyStr that is true if the string was produced by random.random. This is pretty heavy-weight, admittedly.

Another way would be to return a "special" string-like object from random and intercept calls to it. I'm not sure how hard that might be.

@Eddy114514
Copy link
Collaborator Author

What one would need to do is track the string output by random.random and then see if someone does something "bad" on it (e.g. len). There are various ways one could do this.

For example, @nanjekyejoannah can fill you in on the bstate idea we've long been working towards. A variant of that would work here: one could (say) add a bool to PyStr that is true if the string was produced by random.random. This is pretty heavy-weight, admittedly.

Another way would be to return a "special" string-like object from random and intercept calls to it. I'm not sure how hard that might be.

@ltratt Thank you for your suggestions on improving my implementation, I will try to work on either ways and figure out which one is more suitable. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants