Skip to content

Sync recent typing and typing_extensions updates #3070

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 5 commits into from
Jun 18, 2019

Conversation

ilevkivskyi
Copy link
Member

This includes two things to sync up with recent runtime updates:

  • Move Final, @final, Literal, and TypedDict to typing (typing_extensions still defines or re-exports them)
  • Rename @typing.runtime to @typing.runtime_checkable, while keeping @runtime as a backwards-compatible alias in typing_extensions.

Note this might need a mypy sync (if some mypy tests fail).

cc @gvanrossum

@gvanrossum
Copy link
Member

It would be unfortunate if this were to fail with the upcoming mypy 0.710 release, so please let me know if anything is needed!

@ilevkivskyi
Copy link
Member Author

It would be unfortunate if this were to fail with the upcoming mypy 0.710 release, so please let me know if anything is needed!

This will at least need a typeshed sync, I am already working on updating the mypy part (will make a PR later today).

@gvanrossum
Copy link
Member

OK, so the typeshed sync will have to be cherry-picked into the release branch? That makes for very tight timing since I am planning to release this Wednesday. Maybe the release should be delayed? (Then it would be next Monday.) See python/mypy#7009

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

@@ -19,6 +19,8 @@ _F = TypeVar('_F', bound=Callable[..., Any])
_TC = TypeVar('_TC', bound=Type[object])
class _SpecialForm:
def __getitem__(self, typeargs: Any) -> Any: ...
def runtime_checkable(cls: _TC) -> _TC: ...
# This is just an alias for above kept for backwards compatibility.
Copy link
Member

Choose a reason for hiding this comment

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

Why not write it as runtime = runtime_checkable?

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC pytype and/or PyCharm didn't like function aliases in stubs, for example the attrs entry in https://github.com/python/typeshed/blob/master/tests/pytype_blacklist.txt may be related to this.

@JelleZijlstra If you think it should ne OK, I can update this to use an actual alias.

Copy link
Member

Choose a reason for hiding this comment

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

I don't recall that being an issue; it may have been fixed. In any case as far as I know other type checkers don't tend to use typing.pyi from typeshed.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it was only for overloads https://youtrack.jetbrains.com/issue/PY-27788. I will update now.

@ilevkivskyi ilevkivskyi merged commit 01c2fa5 into python:master Jun 18, 2019
@ilevkivskyi ilevkivskyi deleted the sync-recent-typing-updates branch June 18, 2019 01:32
ilevkivskyi added a commit to python/mypy that referenced this pull request Jun 18, 2019
This introduces the following updates:
* Allow using `typing.TypedDict` (still support all the old forms)
* Add a test for `typing.Literal` (it was already supported, but there were no tests)
* Rename `@runtime` to `@runtime_checkable`, while keeping the alias in `typing_extensions` for backwards compatibility.

(Note that `typing.Final` and `typing.Protocol` were already supported and there are tests.)
See also python/typeshed#3070
gvanrossum pushed a commit to python/mypy that referenced this pull request Jun 18, 2019
This introduces the following updates:
* Allow using `typing.TypedDict` (still support all the old forms)
* Add a test for `typing.Literal` (it was already supported, but there were no tests)
* Rename `@runtime` to `@runtime_checkable`, while keeping the alias in `typing_extensions` for backwards compatibility.

(Note that `typing.Final` and `typing.Protocol` were already supported and there are tests.)
See also python/typeshed#3070
gvanrossum pushed a commit to python/mypy that referenced this pull request Jun 18, 2019
This introduces the following updates:
* Allow using `typing.TypedDict` (still support all the old forms)
* Add a test for `typing.Literal` (it was already supported, but there were no tests)
* Rename `@runtime` to `@runtime_checkable`, while keeping the alias in `typing_extensions` for backwards compatibility.

(Note that `typing.Final` and `typing.Protocol` were already supported and there are tests.)
See also python/typeshed#3070
PattenR pushed a commit to PattenR/mypy that referenced this pull request Jun 23, 2019
This introduces the following updates:
* Allow using `typing.TypedDict` (still support all the old forms)
* Add a test for `typing.Literal` (it was already supported, but there were no tests)
* Rename `@runtime` to `@runtime_checkable`, while keeping the alias in `typing_extensions` for backwards compatibility.

(Note that `typing.Final` and `typing.Protocol` were already supported and there are tests.)
See also python/typeshed#3070
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