Skip to content

Change empty string literals to ellipsis #377

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

Merged
merged 1 commit into from
Jul 20, 2016
Merged

Change empty string literals to ellipsis #377

merged 1 commit into from
Jul 20, 2016

Conversation

alvarocaceres
Copy link
Contributor

For pytype compatibility

@matthiaskramm
Copy link
Contributor

Should that be arg: str = ...?

@JukkaL
Copy link
Contributor

JukkaL commented Jul 20, 2016

It would be better to add : str annotations when it makes sense instead of just removing these.

@alvarocaceres
Copy link
Contributor Author

for all I know, some of those functions accept non-str types, so I didn't want to introduce changes. But if you're both ok with a str annotation then will add them

@JukkaL
Copy link
Contributor

JukkaL commented Jul 20, 2016

A fair point -- it's actually not trivial to see whether str is the right type for many of these. Sometimes unicode might be the right thing. Just using ... is reasonable unless the type seems obvious enough.

@alvarocaceres
Copy link
Contributor Author

could mypy give different errors for these two stubs?

def f(a=''): ...
def f(a=...): ...

I believe for pytype they're equivalent, I think the only literals that we get type information from (in stubs) are None, ints and floats

@gvanrossum
Copy link
Member

gvanrossum commented Jul 20, 2016 via email

@JukkaL
Copy link
Contributor

JukkaL commented Jul 20, 2016

They are equivalent. The reason why stubs have non-empty default values is often due to the mypy stubgen utility. It generates function stubs with default argument values to make it easier to manually annotate stubs. Often the default value gives a hint about the type of the argument. For example, if it's None, the argument should almost always be given an Optional[...] type.

@matthiaskramm
Copy link
Contributor

Would it be possible to tweak stubgen to generate a comment instead, or something along those lines?

@JukkaL
Copy link
Contributor

JukkaL commented Jul 20, 2016

Sure, it shouldn't be hard. As mypy is happy with the literals there hasn't been much of an incentive until now.

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