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

PEP 257: Use sys.maxsize #2629

Merged
merged 1 commit into from
Jun 6, 2022
Merged

PEP 257: Use sys.maxsize #2629

merged 1 commit into from
Jun 6, 2022

Conversation

pankwings
Copy link
Contributor

In python3, sys.maxint changed to sys.maxsize.

In python3, sys.maxint changed to sys.maxsize.
@pankwings pankwings requested a review from gvanrossum as a code owner June 6, 2022 09:28
@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Jun 6, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@Rosuav
Copy link
Contributor

Rosuav commented Jun 6, 2022

Hmm, I'm not sure that that's accurate - sys.maxsize is the maximum size of a container, which might not be the same as maxint (Python 2 had both). Python 3 simply doesn't have a maximum integer, so the idea of setting one doesn't really make sense now. Maybe it would be better to use None, or float("inf")?

@pankwings
Copy link
Contributor Author

pankwings commented Jun 6, 2022

Thank you for the response. These are my observations:
For python3:

❯ python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxint
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'sys' has no attribute 'maxint'
>>> sys.maxsize
9223372036854775807
>>>

For python2

❯ python
Python 2.7.18 (default, Mar  8 2021, 13:02:45) 
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> indent = sys.maxint
>>> sys.maxint
9223372036854775807
>>> 

The sys.maxsize in python3 and sys.maxint in python2 within the same machine can be interchangeably used as both returns the same value 9223372036854775807.

@Rosuav
Copy link
Contributor

Rosuav commented Jun 6, 2022

It so happens that, on your version of Python (and mine), Py2's maxint and maxsize are the same number as Py3's maxsize. Is it actually true that they are interchangeable though?

Another consideration might be that, since this is talking about indentation, a "stupidly big" value might be sufficient. For instance, 1<<100 is going to be way bigger than any sane indentation size, yet it's independent of machine-specific sizes.

Hard to say which is best - float("inf"), 1<<100, None (the latter truly giving a sentinel value, which is the purpose here, but that requires changing the condition slightly). I think possibly None is the best option here, but it's arguable.

@AA-Turner
Copy link
Member

AA-Turner commented Jun 6, 2022

Sphinx uses sys.maxsize [1]. I tried locally with an indent of 1,000,000,000 spaces (for a ~950MB file) and the Python interpreter didn't crash -- I'd test further but I don't have 1TB free (or several hours to wait for the completion. I think using sys.maxsize is the most pragmatic reinterpretation of the original intent, although I see Chris' point that maxsize isn't quite the same as maxint.

A

[1] https://github.com/sphinx-doc/sphinx/blob/v5.0.1/sphinx/util/docstrings.py#L60-L71

@pankwings
Copy link
Contributor Author

Yes, it seems like both are different in different versions of python. Here is the one difference I have observed between python2 and python3:

python2

Python 2.7.18 (default, Mar  8 2021, 13:02:45) 
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(type(sys.maxsize))
<type 'int'>
>>> print(type(sys.maxint))
<type 'int'>

In python version 2, type 'int' is the type obtained.

python3

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(type(sys.maxsize))
<class 'int'>

In python version 3, class 'int' is the type obtained.

@AA-Turner AA-Turner changed the title Update pep-0257.txt PEP 257: Use sys.maxsize Jun 6, 2022
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.

4 participants