[issue32953] Dataclasses: frozen should not be inherited for non-dataclass derived classes

2018-03-18 Thread Eric V. Smith

Change by Eric V. Smith :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32953] Dataclasses: frozen should not be inherited for non-dataclass derived classes

2018-03-18 Thread Eric V. Smith

Eric V. Smith  added the comment:


New changeset 45648312e540cda3b10109b6a808cbf6955c84eb by Eric V. Smith (Miss 
Islington (bot)) in branch '3.7':
bpo-32953: Dataclasses: frozen should not be inherited for non-dataclass 
derived classes (GH-6147) (GH-6148)
https://github.com/python/cpython/commit/45648312e540cda3b10109b6a808cbf6955c84eb


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32953] Dataclasses: frozen should not be inherited for non-dataclass derived classes

2018-03-18 Thread miss-islington

Change by miss-islington :


--
pull_requests: +5906

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32953] Dataclasses: frozen should not be inherited for non-dataclass derived classes

2018-03-18 Thread Eric V. Smith

Eric V. Smith  added the comment:


New changeset f199bc655eb50c28e94010714629b376bbbd077b by Eric V. Smith in 
branch 'master':
bpo-32953: Dataclasses: frozen should not be inherited for non-dataclass 
derived classes (#6147)
https://github.com/python/cpython/commit/f199bc655eb50c28e94010714629b376bbbd077b


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32953] Dataclasses: frozen should not be inherited for non-dataclass derived classes

2018-03-18 Thread Eric V. Smith

Change by Eric V. Smith :


--
keywords: +patch
pull_requests: +5905
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32953] Dataclasses: frozen should not be inherited for non-dataclass derived classes

2018-02-28 Thread Eric V. Smith

Eric V. Smith  added the comment:

See https://mail.python.org/pipermail/python-dev/2018-February/152320.html for 
a discussion.

--
title: Dataclasses: frozen should not be inherited -> Dataclasses: frozen 
should not be inherited for non-dataclass derived classes

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32953] Dataclasses: frozen should not be inherited

2018-02-25 Thread Eric V. Smith

Eric V. Smith  added the comment:

A related issue is that dataclasses derived from frozen dataclasses are 
automatically "promoted" to being frozen.

>>> @dataclass(frozen=True)
... class A:
... i: int
...
>>> @dataclass
... class B(A):
... j: int
...
>>> b = B(1, 2)
>>> b.j = 3
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\home\eric\local\python\cpython\lib\dataclasses.py", line 452, in 
_frozen_setattr
raise FrozenInstanceError(f'cannot assign to field {name!r}')
dataclasses.FrozenInstanceError: cannot assign to field 'j'

If this can't be addressed before 3.7, maybe it should be an error to declare B 
as non-frozen and then we can properly fix it in a future release.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32953] Dataclasses: frozen should not be inherited

2018-02-25 Thread Eric V. Smith

New submission from Eric V. Smith :

Reported by Raymond Hettinger:

When working on the docs for dataclasses, something unexpected came up.  If a 
dataclass is specified to be frozen, that characteristic is inherited by 
subclasses which prevents them from assigning additional attributes:

>>> @dataclass(frozen=True)
class D:
x: int = 10

>>> class S(D):
pass

>>> s = S()
>>> s.cached = True
Traceback (most recent call last):
  File "", line 1, in 
s.cached = True
  File 
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py",
 line 448, in _frozen_setattr
raise FrozenInstanceError(f'cannot assign to field {name!r}')
dataclasses.FrozenInstanceError: cannot assign to field 'cached'

Other immutable classes in Python don't behave the same way:


>>> class T(tuple):
pass

>>> t = T([10, 20, 30])
>>> t.cached = True

>>> class F(frozenset):
pass

>>> f = F([10, 20, 30])
>>> f.cached = True

>>> class B(bytes):
pass

>>> b = B()
>>> b.cached = True


Raymond

--
assignee: eric.smith
components: Library (Lib)
messages: 312866
nosy: eric.smith, rhettinger
priority: normal
severity: normal
status: open
title: Dataclasses: frozen should not be inherited
type: behavior
versions: Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com