Skip to content

Fix abstract classes for Python 3 - #2239

Merged
JelleZijlstra merged 5 commits into
python:masterfrom
JelleZijlstra:moreabcmeta
Jun 16, 2018
Merged

JelleZijlstra merged 5 commits into
python:masterfrom
JelleZijlstra:moreabcmeta

Conversation

@JelleZijlstra

Copy link
Copy Markdown
Member

Related: #1476 and python/mypy#5223.

This makes typeshed pass in Python 3.7 under my mypy PR (and probably in all of Python 3; haven't tried yet). I'll send more PRs for 2.7.

This found an embarrassing typo in the contextvars stub I had previously written.

I changed google.protobuf.internal.containers.BaseContainer into a Sequence instead of MutableSequence to reflect the implementation at https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/containers.py#L185.

I similarly changed the base class of urllib3.response.HTTPResponse to match the implementation.

Comment thread stdlib/3/typing.pyi Outdated
if sys.version_info >= (3, 6):
@runtime
class Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ...
class Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co], metaclass=ABCMeta): ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hm, I think this should be not needed. Having an explicit Protocol base should be enough. Protocols can't be instantiated at runtime anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense, I can add that to my mypy PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, changed it in mypy here: python/mypy@e505c0d.

Comment thread stdlib/3/typing.pyi Outdated
else:
@runtime
class _Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ...
class _Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co], metaclass=ABCMeta): ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

@JelleZijlstra
JelleZijlstra merged commit 94ab32b into python:master Jun 16, 2018
@JelleZijlstra
JelleZijlstra deleted the moreabcmeta branch June 16, 2018 17:18
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
* add metaclass=ABCMeta to some classes

* mark some more classes as explicitly abstract

* make some more classes concrete
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.

2 participants