Summary: Long post. Because of LSP, neither dict nor frozendict are a
subclass of the other.
Chris Barker wrote:
> If we REALLY had a time machine, then dict would subclass frozendict,
> and we’d be all set.
Prediction is difficult, particularly when it involves the future. - Neils Bohr.
And be
On Fri, Oct 12, 2018 at 2:41 AM Chris Barker - NOAA Federal via
Python-ideas wrote:
>
> > This violates the Liskov Substitution Principle.
>
> If we REALLY had a time machine, then dict would subclass frozendict,
> and we’d be all set.
Thanks to virtual subclassing, we can still do this. The
> This violates the Liskov Substitution Principle.
If we REALLY had a time machine, then dict would subclass frozendict,
and we’d be all set.
But to what extent do we need to support ALL the ways to check for an
interface?
Personally, I think EAFTP is the most “Pythonic”, but if folks want to
On Thu, Oct 11, 2018 at 9:54 AM, Jonathan Fine wrote:
> Summary: Long post. Because of LSP, neither dict nor frozendict are a
> subclass of the other.
given Python's dynamic typing, these issues are kinda academic :-)
> Intuition tells me that a frozen dictionary is a form of dictionary
> >
A link on https://en.wikipedia.org/wiki/Liskov_substitution_principle goes to
http://www.engr.mun.ca/~theo/Courses/sd/5895-downloads/sd-principles-3.ppt.pdf
which has a very nice example (slides 14 and 15).
Slide 14: Is immutable Square a behavioural subtype of immutable
Rectangle? And vice
BTW:
In [7]: issubclass(set, frozenset)
Out[7]: False
In [8]: issubclass(frozenset, set)
Out[8]: False
no reason to do anything different here.
and:
In [13]: issubclass(MappingProxyType, abc.Hashable)
Out[13]: False
so yes, there is a need for something different
-CHB
On Thu, Oct 11,
On Tue, 9 Oct 2018 at 15:17, Eric Fahlgren wrote:
> On Tue, Oct 9, 2018 at 3:16 AM Ivan Levkivskyi
> wrote:
>
>> class PathLike(Protocol[AnyStr]):
>>
>
> I had been working on this same problem intermittently for several months,
> so thanks, but...
>
> error: Invariant type variable
On Fri, Oct 12, 2018 at 9:16 AM Steven D'Aprano wrote:
>
> On Fri, Oct 12, 2018 at 02:45:30AM +1100, Chris Angelico wrote:
> > On Fri, Oct 12, 2018 at 2:41 AM Chris Barker - NOAA Federal via
> > Python-ideas wrote:
> > >
> > > > This violates the Liskov Substitution Principle.
> > >
> > > If we
Done https://github.com/python/mypy/issues/5775
On Thu, Oct 11, 2018 at 1:47 PM Ivan Levkivskyi
wrote:
> On Tue, 9 Oct 2018 at 15:17, Eric Fahlgren wrote:
>
>> On Tue, Oct 9, 2018 at 3:16 AM Ivan Levkivskyi
>> wrote:
>>
>>> class PathLike(Protocol[AnyStr]):
>>>
>>
>> I had been working on
On Thu, Oct 11, 2018 at 12:34:13PM -0700, Chris Barker via Python-ideas wrote:
> I don't care what is or isn't a subclass of what -- I don't think that's a
> Pythonic question. But I do think :
>
> issubclass(frozendict, abc.Mapping) and issubclass(frozendict, abc.Hashable)
>
> would be useful.
On Fri, Oct 12, 2018 at 02:45:30AM +1100, Chris Angelico wrote:
> On Fri, Oct 12, 2018 at 2:41 AM Chris Barker - NOAA Federal via
> Python-ideas wrote:
> >
> > > This violates the Liskov Substitution Principle.
> >
> > If we REALLY had a time machine, then dict would subclass frozendict,
> > and
On Thu, Oct 11, 2018 at 3:35 PM, Steven D'Aprano
wrote:
> On Thu, Oct 11, 2018 at 12:34:13PM -0700, Chris Barker via Python-ideas
> wrote:
>
> > I don't care what is or isn't a subclass of what -- I don't think that's
> a
> > Pythonic question. But I do think :
> >
> > issubclass(frozendict,
On Thu, Oct 11, 2018 at 01:27:50PM +1100, Chris Angelico wrote:
[...]
[Cameron Simpson]
> > Well, if it were called frozendict, indeed not. It should act like dict.
> >
> > So:
> >
> > def frozendict(**kw):
> > return MappingProxyType(kw)
> >
> > You could make an argument for that (or a
May be the following simple prototype of frozendict could be useful?
def frozen_error():
return RuntimeError("frozendict is not mutable")
class frozendict(dict):
#
def __setitem__(self, key, val):
raise frozen_error()
#
def setdefault(self, key, val=None):
On Thu, Oct 11, 2018 at 02:18:52AM -0700, Zaur Shibzukhov wrote:
>
> May be the following simple prototype of frozendict could be useful?
>
> def frozen_error():
>return RuntimeError("frozendict is not mutable")
>
> class frozendict(dict):
This violates the Liskov Substitution Principle.
Steve D'Aprano wrote
> Zaur Shibzukhov wrote
> > class frozendict(dict):
> This violates the Liskov Substitution Principle.
> https://en.wikipedia.org/wiki/Liskov_substitution_principle
and so, Steve said, we should not make frozendict a subclass of dict.
Perhaps Zaur was thinking of Don't
> https://en.wikipedia.org/wiki/Liskov_substitution_principle
> https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
I did an internet search for: python liskov (over the past year).
The first result was a Ruby page (but principle probably the same)
17 matches
Mail list logo