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

Make slice() arguments optional #833

Merged
merged 1 commit into from
Jan 18, 2017
Merged

Make slice() arguments optional #833

merged 1 commit into from
Jan 18, 2017

Conversation

froomzy
Copy link
Contributor

@froomzy froomzy commented Jan 14, 2017

Changed slice to take Optional[int] rather than just straight int. Fix for #832.

Copy link
Contributor

@ambv ambv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good improvement! Just some minutiae to take care of.

@@ -472,7 +472,7 @@ class slice:
start = 0
step = 0
stop = 0
def __init__(self, start: int, stop: int = 0, step: int = 0) -> None: ...
def __init__(self, start: Optional[int], stop: Optional[int] = 0, step: Optional[int] = 0) -> None: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the step's default value to be None. In fact, it cannot be 0 :) Same for stop, the default value is None, behavior is different if 0 is given.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default really should be ..., in stubs the value of the default is irrelevant, only its presence is used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how PyCharm could use actual defaults to help with auto-completion but yes, ... is indeed the canonical default value.

@gvanrossum gvanrossum changed the title Updated the stub for builtins Make slice() arguments optional Jan 18, 2017
@gvanrossum
Copy link
Member

I wonder if the .start, .stop and .step attributes should also be made Optional? OTOH that may cause breakage of user code. See discussions here:

@ambv
Copy link
Contributor

ambv commented Jan 18, 2017

From looking at this it seems to me adding Slice[T, S, R] to typing is the correct way to go. So in the mean time, should we accept this as an incremental (if incomplete) improvement for the common case?

@gvanrossum
Copy link
Member

gvanrossum commented Jan 18, 2017 via email

@ambv
Copy link
Contributor

ambv commented Jan 18, 2017

OK, given that the 0 default value is ignored anyway, I'm just going to merge it.

@ambv ambv merged commit 6339f88 into python:master Jan 18, 2017
@ambv
Copy link
Contributor

ambv commented Jan 18, 2017

Thank you, @froomzy ✨ 🍰 ✨

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