Opened 3 years ago

Last modified 3 years ago

#28392 closed defect

dynamic_class: do not copy over Python 3's new __weakref__ class attribute — at Initial Version

Reported by: Nicolas M. Thiéry Owned by:
Priority: major Milestone: sage-9.0
Component: python3 Keywords:
Cc: Frédéric Chapoton, Travis Scrimshaw, Erik Bray Merged in:
Authors: Nicolas M. Thiéry Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

Python3 introduce a new attribute __weakref__ in the datastructure for classes in addition to __dict__. As such, this attribute should not be copied over by dynamic_class. Otherwise we get errors, typically upon introspection: `

sage: from inspect import getmembers sage: c = EllipticCurve?([0,0,1,-1,0]) sage: getmembers(c) --------------------------------------------------------------------------- TypeError? Traceback (most recent call last) <ipython-input-5-bef5f5512029> in <module>() ----> 1 getmembers(c)

/opt/sage-git/local/lib/python3.7/inspect.py in getmembers(object, predicate) 339 # looking in the dict. 340 try:

--> 341 value = getattr(object, key)

342 # handle the duplicate key 343 if key in processed:

TypeError?: descriptor 'weakref' for 'Sets.ParentMethods?' objects doesn't apply to 'EllipticCurve_rational_field_with_category' object

` The same error can be triggered by calling directly c.__weakref__.

This can be reduced down to: `

sage: class A: ....: pass sage: A.weakref <attribute 'weakref' of 'A' objects> sage: Foo1 = sage.structure.dynamic_class.dynamic_class("Foo", (), A) sage: "weakref" in Foo1.dict True

` (should be False).

This ticket fixes this.

Change History (0)

Note: See TracTickets for help on using tickets.