[Bug]: After `obj.__class__ = C`, calling `C(arg)` for a class with a metaclass such as `ABCMeta` fails with `object.__new__() takes exactly one argument` from the third call on
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 22/100
Direzione di ricerca
The failure sits in how GraalPy resolves __new__ after __class__ is reassigned, so the search starts at the __class__ setter and the type call path for classes with a metaclass. Run the reproduction script from the issue; the fault appears from the third call at the cls(*args) line. Done when all four rounds print C and the metaclass-as-type-subclass variant also passes.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
C inherits a __new__ that accepts extra arguments and has a metaclass (here abc.ABCMeta). Once some object's __class__ has been set to C, a call site that has already called both the base class and C starts raising TypeError: object.__new__() takes exactly one argument (the type to instantiate) for C(arg), as if C had no __new__ of its own. The first two rounds work; every later round fails. CPython constructs the object every time.
Operating system
macOS
CPU architecture
ARM64
GraalPy version
25.6.5.1 (Python 3.13.14), community build from the GitHub release. Same on master 2e574af1d8.
JDK version
No response
Context configuration
No response
Steps to reproduce
import abc
class Base:
def __new__(cls, *args):
return object.__new__(cls)
def __init__(self, *args):
pass
class C(Base, metaclass=abc.ABCMeta):
pass
def make(cls, *args):
return cls(*args)
for i in range(4):
try:
make(Base, "a")
Base().__class__ = C
print(i, type(make(C, "b")).__name__)
except TypeError as e:
print(i, "TypeError:", e)
GraalPy:
0 C
1 C
2 TypeError: object.__new__() takes exactly one argument (the type to instantiate)
3 TypeError: object.__new__() takes exactly one argument (the type to instantiate)
Expected behavior
CPython 3.13.18:
0 C
1 C
2 C
3 C
Additional context
All three ingredients are needed on GraalPy:
- Without the
__class__assignment, all four rounds printC. - With
class C(Base)(metaclasstype), all four rounds printC. Anytypesubclass as metaclass fails, not onlyABCMeta. - Without the
make(Base, "a")call, so that the call site only seesC, all four rounds printC.
The same happens when the call is type(self)(*args) inside a method and self is the object whose __class__ was assigned. The traceback ends at the cls(*args) call, not inside Base.__new__, so the __new__ that gets called is object.__new__ itself.
- Lingua principale
- Python
- Stelle
- 1.7k
- Fork
- 167
- Merge medio
- 3g 11h
- PR unite (30g)
- 68
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di oracle/graalpython
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
oracle/graalpython#1105 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
oracle/graalpython#1102 ·
I maintainer di solito rispondono entro 1 giorno
-
mmap.mmap.move() is missingForse già presa @deronnax l’ha presa 3 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
oracle/graalpython#1368 ·
I maintainer di solito rispondono entro 1 giorno
-
mmap extended slicing ignores the step; negative steps raise java.lang.IndexOutOfBoundsExceptionAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
oracle/graalpython#1367 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
oracle/graalpython#1366 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di oracle/graalpython
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug improve content
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
opensafely/documentation#2102 ·
I maintainer di solito rispondono entro 1 giorno
-
difficulty:1 documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
MakazhanAlpamys/Soup#3533 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
onyx-dot-app/onyx#18730 ·
I maintainer di solito rispondono entro 1 giorno