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

Add __new__ to str and int stubs in both Pythons. #1352

Merged
merged 3 commits into from Jun 13, 2017

Conversation

sproshev
Copy link
Contributor

No description provided.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

What concrete problem does this solve? I'm hesitant to change stubs as basic as these without a clear justification.

@overload
def __init__(self, x: SupportsInt = ...) -> None: ...
@overload
def __init__(self, x: Union[str, bytes], base: int = 10) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

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

All defaults should be ....

@sproshev
Copy link
Contributor Author

We have the issue https://youtrack.jetbrains.com/issue/PY-23540 where we raise a warning on return str.__new__( cls, *args, **kwargs ) line.

@sproshev
Copy link
Contributor Author

Not sure how to fix compatibility issue inside IntEnum :(

@JelleZijlstra
Copy link
Member

Thanks, that makes sense. mypy also gives a spurious error on calling int.__new__(int, '3', 10).

I don't have a great solution for the test failures either. We could # type: ignore them away, but I think mypy's parser won't accept that.

…nd `str`.

Add `__new__` to `enum.IntEnum` to override inherited `__new__`.
@sproshev
Copy link
Contributor Author

Fixed!

@JelleZijlstra
Copy link
Member

Yes, this seems to work. I tested it on my codebase too and got no errors. I'll leave this open a few more days in case other maintainers have concerns, then merge it.

@gvanrossum
Copy link
Member

Hm, mypy on the issue from the PyCharm tracker reports this, both with and without the change:

__tmp__.py:19: error: Inconsistent metaclass structure for 'MyString'
__tmp__.py:24: error: Name 'spam' is not defined
__tmp__.py:24: error: "MyString" expects no type arguments, but 1 given

Other than that, no much difference. (Though I wonder what would happen if someone were to add SupportsInt as a base class to str, or when PEP 544 (duck typing) is introduced.

@JelleZijlstra JelleZijlstra merged commit fed4e03 into python:master Jun 13, 2017
@sproshev sproshev deleted the sproshev/str_int_new branch June 13, 2017 16:17
JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this pull request Jul 5, 2017
matthiaskramm pushed a commit that referenced this pull request Jul 6, 2017
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.

None yet

3 participants