Coder Social home page Coder Social logo

Comments (2)

JelleZijlstra avatar JelleZijlstra commented on July 28, 2024 1

Thanks for finding this.

It does look hard to fix. typing.Protocol before 3.11 clobbered __init__, so if you inherit from it, that's the behavior you'll get. We should simply document it, unless someone comes up with a clever way to prevent this behavior.

from typing_extensions.

AlexWaygood avatar AlexWaygood commented on July 28, 2024

Another limitation: with typing_extensions.Protocol, it is possible to create a protocol that extends typing_extensions.Buffer:

>>> import typing_extensions as te
>>> class Q(te.Buffer, te.Protocol): pass
...
>>>

But if you have both typing.Protocol and typing_extensions.Protocol in the mro, it doesn't work:

>>> import typing as t, typing_extensions as te
>>> class P(t.Protocol): pass
...
>>> class Q(P, te.Buffer, te.Protocol): pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\alexw\coding\typing_extensions\src\typing_extensions.py", line 632, in __new__
    return abc.ABCMeta.__new__(mcls, name, bases, namespace, **kwargs)
  File "C:\Users\alexw\.conda\envs\py38\lib\abc.py", line 85, in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
  File "C:\Users\alexw\.conda\envs\py38\lib\typing.py", line 1119, in __init_subclass__
    raise TypeError('Protocols can only inherit from other'
TypeError: Protocols can only inherit from other protocols, got <class 'typing_extensions.Buffer'>

This is because we have typing_extensions.Buffer in our version of _PROTO_ALLOWLIST, but it obviously doesn't exist in the typing version of _PROTO_ALLOWLIST:

_PROTO_ALLOWLIST = {
'collections.abc': [
'Callable', 'Awaitable', 'Iterable', 'Iterator', 'AsyncIterable',
'Hashable', 'Sized', 'Container', 'Collection', 'Reversible', 'Buffer',
],
'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'],
'typing_extensions': ['Buffer'],
}

from typing_extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.