[Python-ideas] Re: Protocols Subclassing Normal Classes

2023-04-24 Thread Jelle Zijlstra
The formal term for that is intersection types. There is a long-standing thread about that at https://github.com/python/typing/issues/213; there are some uses but the feature would greatly complicate the type system, so it's not clear that it's worth adding. At this point, what Intersection needs

[Python-ideas] Re: Protocols Subclassing Normal Classes

2023-04-24 Thread Mathew Elman
Rather than changing Protocols and affecting lots of users, it seems like was you really want is a generic class that is the "and" to Union's "or"? e.g. def foo(thing: All[Thread, SupportsStop]): ... which seems reasonable. If that appeals to you, then you probably want to raise that on

[Python-ideas] Re: Protocols Subclassing Normal Classes

2023-04-21 Thread Chris Angelico
On Fri, 21 Apr 2023 at 22:57, Jordan Macdonald wrote: > However, I then encountered an issue: I could define a Protocol that > specified the 'stop()' method easily enough, but if I annotated the manager > as taking that, it would accept any class which implemented a method named > 'stop()',