- Revision
- 11204
- Author
- pje
- Date
- 2006-07-19 11:22:23 -0700 (Wed, 19 Jul 2006)
Log Message
Fix bug #6276: "Annotations can't point to themselves".
Annotations can point to themselves, they just couldn't do it using strings as
forward references. This change makes it work for strings too.
Note that using strings to name types is an undocumented feature that was used
to assist porting the schema from XML. Please see the schema API documentation
at:
http://chandler.osafoundation.org/docs/0.7/parcel-schema-guide.html#bi-directional-references
for an explanation of how to create bidirectional references without using
strings to name types.
Annotations can point to themselves, they just couldn't do it using strings as
forward references. This change makes it work for strings too.
Note that using strings to name types is an undocumented feature that was used
to assist porting the schema from XML. Please see the schema API documentation
at:
http://chandler.osafoundation.org/docs/0.7/parcel-schema-guide.html#bi-directional-references
for an explanation of how to create bidirectional references without using
strings to name types.
Modified Paths
Diff
Modified: trunk/chandler/application/schema.py (11203 => 11204)
--- trunk/chandler/application/schema.py 2006-07-19 17:19:12 UTC (rev 11203) +++ trunk/chandler/application/schema.py 2006-07-19 18:22:23 UTC (rev 11204) @@ -343,7 +343,8 @@ continue # don't set type to None else: val = itemFor(val, view) # works for Kind and TypeReference - + if isinstance(val, AnnotationItem): + val = itemFor(val.annotates, view) setattr(attr,aspect,val) if not hasattr(self,'otherName') and self.inverse is not None: @@ -1359,7 +1360,7 @@ if cb is not None: queue.append(cb) while queue and not level: - queue.pop(0)() # invoke callbacks + queue.pop(0)() # invoke callbacks finally: view._schema_init_level = level
Modified: trunk/chandler/application/tests/TestSchemaAPI.py (11203 => 11204)
--- trunk/chandler/application/tests/TestSchemaAPI.py 2006-07-19 17:19:12 UTC (rev 11203) +++ trunk/chandler/application/tests/TestSchemaAPI.py 2006-07-19 18:22:23 UTC (rev 11204) @@ -29,6 +29,7 @@ class Other(schema.Item): thing = schema.One(Dummy, inverse="other") + TEST_PATH = "//this/is/a/test" class Mixed(Dummy, Types.Type): @@ -42,6 +43,15 @@ extraInfo = schema.One(schema.Text) otherItem = schema.One(schema.Item, inverse=schema.Sequence()) +class ForwardAnnotation(schema.Annotation): + schema.kindInfo(annotates=Dummy) + fwd_attr1 = schema.One("ForwardAnnotation") + fwd_attr2 = schema.One(inverse="TestSchemaAPI.OtherForward.foo") + +class OtherForward(schema.Annotation): + schema.kindInfo(annotates=Dummy) + foo = schema.One() + class SchemaTestCase(unittest.TestCase): """Reset the schema API between unit tests""" @@ -104,7 +114,7 @@ schema.synchronize(self.rv, this_module) path = "//parcels/%s/" % this_module.replace('.','/') - # Everything should exist now, including the default parent objects + # Everything should exist now, including the default parent objects self.assertNotEqual( self.rv.findPath(TEST_PATH), None) self.assertNotEqual( self.rv.findPath("//userdata"), None) self.assertNotEqual( self.rv.findPath(path+'Dummy'), None) @@ -121,7 +131,10 @@ [kind_kind] ) + def testAnnotateForwardRefs(self): + schema.itemFor(ForwardAnnotation, self.rv) + def test_schema_api(): import doctest return doctest.DocFileSuite(
_______________________________________________ Commits mailing list [email protected] http://lists.osafoundation.org/mailman/listinfo/commits
