[issue46404] 3.11a4: a small attrs regression

2022-03-15 Thread Lumír Balhar

Lumír Balhar  added the comment:

We have the same problem reported in attrs here in dataclasses and because it's 
not tested the way to manipulate __closure__ cells changes frequently.

My plan is to implement something similar to this into dataclasses: 
https://github.com/python-attrs/attrs/blob/5c040f30e3e4b3c9c0f27c8ac6ff13d604c1818c/src/attr/_make.py#L895-L916

Basically, when a new dataclass is created (with slots=True), look for 
references to the original class and fix them.

This fixes the problem reported to attrs in dataclasses and when we fix it and 
add some tests for it, the future behavior should be more stable.

What do you think?

--

___
Python tracker 

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



[issue46404] 3.11a4: a small attrs regression

2022-03-15 Thread Eric V. Smith


Eric V. Smith  added the comment:

@frenzy: I'm not sure what your fix would do. You could either describe it in 
rough terms (if you'd like a pre-PR opinion on the approach), or I'm happy to 
wait to see your PR.

--

___
Python tracker 

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



[issue46404] 3.11a4: a small attrs regression

2022-03-15 Thread Lumír Balhar

Lumír Balhar  added the comment:

In my opinion, we should keep it simple for attrs and dataclasses to fix 
closure cells when a class is replaced and therefore it seems to be correct to 
have it mutable as it currently is in 3.11.

My plan is to implement the fix for dataclasses and some tests for these use 
cases so the behavior should not change in the future. For attrs it means one 
more branch in the code now but much simpler code when the support for older 
releases gets dropped.

Any other opinions?

--

___
Python tracker 

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



[issue46404] 3.11a4: a small attrs regression

2022-01-24 Thread Petr Viktorin


Petr Viktorin  added the comment:

I guess at least there should be a warning about this in dataclasses docs?
The reproducer with dataclasses (which exhibits the same error on 3.10 and 
3.11):

import dataclasses

@dataclasses.dataclass(slots=True)
class A:
pass


@dataclasses.dataclass(slots=True)
class B(A):
def test(self):
super()

B().test()

--
nosy: +petr.viktorin

___
Python tracker 

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



[issue46404] 3.11a4: a small attrs regression

2022-01-16 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

bisected to here:

631f9938b1604d4f893417ec339b9e0fa9196fb1 is the first new commit
commit 631f9938b1604d4f893417ec339b9e0fa9196fb1
Author: Eric Snow 
Date:   Mon Jun 7 16:52:00 2021 -0600

bpo-43693: Add the MAKE_CELL opcode and interleave fast locals offsets. 
(gh-26396)

This moves logic out of the frame initialization code and into the compiler 
and eval loop.  Doing so simplifies the runtime code and allows us to optimize 
it better.

https://bugs.python.org/issue43693

--
nosy: +Dennis Sweeney, eric.snow

___
Python tracker 

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



[issue46404] 3.11a4: a small attrs regression

2022-01-16 Thread Lumír Balhar

Change by Lumír Balhar :


--
nosy: +frenzy

___
Python tracker 

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



[issue46404] 3.11a4: a small attrs regression

2022-01-16 Thread Hynek Schlawack


Change by Hynek Schlawack :


--
nosy: +hynek

___
Python tracker 

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



[issue46404] 3.11a4: a small attrs regression

2022-01-16 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +eric.smith

___
Python tracker 

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



[issue46404] 3.11a4: a small attrs regression

2022-01-16 Thread Tin Tvrtković

New submission from Tin Tvrtković :

We've received a report over at the attrs issue tracker about our test suite 
failing on Python 3.11. Here's the link: 
https://github.com/python-attrs/attrs/issues/907

It turns out to be an issue with the no-arg `super()` calls in slotted classes. 
Here's a minimal reproducer example:

```
from attrs import define


@define
class A:
pass


@define
class B(A):
def test(self):
super()


B().test()
```

```
Traceback (most recent call last):
  File "/Users/tintvrtkovic/pg/attrs/a01.py", line 15, in 
B().test()
^^
  File "/Users/tintvrtkovic/pg/attrs/a01.py", line 12, in test
super()
^^^
TypeError: super(type, obj): obj must be an instance or subtype of type
```
This is a known issue for which we have implemented workarounds. The 
workarounds aren't effective for 3.11 though. I have implemented a fix in attrs 
(https://github.com/python-attrs/attrs/pull/910), but I still thought I'd post 
this here to maybe get the core devs opinion.

Dataclasses exhibit the exact same issue when used with `slots=True`, both in 
3.10 when `slots` was added and in 3.11. I guess no one reported it or tried 
fixing it.

A comprehensive description of the issue follows: since it's impossible to add 
*slotness* (i.e. set `__slots__`) to a class after it has been created, when 
creating a slotted class the class decorators in attrs and dataclasses actually 
replace the class they are applied to with a copy of it, with slots added. This 
works, except in the case of the no-arg `super()` being used in any of the 
class methods (and maybe another edge case that I can't remember). When the 
compiler encounters the no-arg `super()` form, it adds some state to the 
function `__closure__` cells. This state causes the exception shown above, 
since it's incorrect when the class gets replaced.

So these closure cells need to be rewritten when the class is replaced. In 
Python versions prior to 3.11, the closure cells were immutable so extra effort 
was needed to rewrite them. The functions are here: 
https://github.com/python-attrs/attrs/blob/9727008fd1e40bc55cdc6aee71e0f61553f33127/src/attr/_compat.py#L145.

In 3.11, our old closure cell rewriting doesn't work any more, but closure 
cells don't appear to be immutable either, so the fix in my attr PR linked 
above is simple. Still, it's another branch in the code to support a specific 
version.

I don't know if there's anything actionable here for Python, apart from 
confirming or denying if this behavior is expected.

--
components: Interpreter Core
messages: 410730
nosy: tinchester
priority: normal
severity: normal
status: open
title: 3.11a4: a small attrs regression
type: behavior
versions: Python 3.11

___
Python tracker 

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