Skip to content

Change empty string literals to ellipsis - #377

Merged
matthiaskramm merged 1 commit into
python:masterfrom
alvarocaceres:empty_string
Jul 20, 2016
Merged

matthiaskramm merged 1 commit into
python:masterfrom
alvarocaceres:empty_string

Conversation

@alvarocaceres

Copy link
Copy Markdown
Contributor

For pytype compatibility

@matthiaskramm

Copy link
Copy Markdown
Contributor

Should that be arg: str = ...?

@JukkaL

JukkaL commented Jul 20, 2016

Copy link
Copy Markdown
Contributor

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

@alvarocaceres

Copy link
Copy Markdown
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

JukkaL commented Jul 20, 2016

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

gvanrossum commented Jul 20, 2016 via email

Copy link
Copy Markdown
Member

@JukkaL

JukkaL commented Jul 20, 2016

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@JukkaL

JukkaL commented Jul 20, 2016

Copy link
Copy Markdown
Contributor

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