avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fo...@apache.org
Subject [avro] branch master updated: AVRO-2183 Provide name only for named schema (#313)
Date Sat, 10 Nov 2018 09:19:21 GMT
This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new ca1ef06  AVRO-2183 Provide name only for named schema (#313)
ca1ef06 is described below

commit ca1ef06d87424630f80ade31afcd8a1108dd5fed
Author: Michael A. Smith <michael@smith-li.com>
AuthorDate: Sat Nov 10 04:19:16 2018 -0500

    AVRO-2183 Provide name only for named schema (#313)
    
    Otherwise, allow python to raise an AttributeError
---
 lang/py3/avro/schema.py            | 18 ++++++------------
 lang/py3/avro/tests/test_schema.py | 13 +++++++++++++
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/lang/py3/avro/schema.py b/lang/py3/avro/schema.py
index 0ebd41f..2fc7302 100644
--- a/lang/py3/avro/schema.py
+++ b/lang/py3/avro/schema.py
@@ -184,18 +184,6 @@ class Schema(object, metaclass=abc.ABCMeta):
       self._props.update(other_props)
 
   @property
-  def name(self):
-    """Returns: the simple name of this schema."""
-    return self._props['name']
-
-  @property
-  def fullname(self):
-    """Returns: the fully qualified name of this schema."""
-    # By default, the full name is the simple name.
-    # Named schemas override this behavior to include the namespace.
-    return self.name
-
-  @property
   def namespace(self):
     """Returns: the namespace this schema belongs to, if any, or None."""
     return self._props.get('namespace', None)
@@ -625,6 +613,12 @@ class PrimitiveSchema(Schema):
     # The name of a primitive type is the type itself.
     return self.type
 
+  @property
+  def fullname(self):
+    """Returns: the fully qualified name of this schema."""
+    # The full name is the simple name for primitive schema.
+    return self.name
+
   def to_json(self, names=None):
     if len(self.props) == 1:
       return self.fullname
diff --git a/lang/py3/avro/tests/test_schema.py b/lang/py3/avro/tests/test_schema.py
index c836528..fa70567 100644
--- a/lang/py3/avro/tests/test_schema.py
+++ b/lang/py3/avro/tests/test_schema.py
@@ -472,6 +472,19 @@ class TestSchema(unittest.TestCase):
     # it could be reparsed.
     self.assertEqual("X", t.fields[0].type.name)
 
+  def testNoName(self):
+    """Test that schema without a name
+    raise AttributeError when you try
+    to access their name."""
+    cases = [
+      '{"type": "array", "items": "int"}',
+      '{"type": "map", "values": "int"}',
+      '["null", "int"]',
+    ]
+    for case in (schema.Parse(case) for case in cases):
+      self.assertRaises(AttributeError, lambda: case.name)
+      self.assertEqual(getattr(case, "name", "default"), "default")
+
   def testParse(self):
     correct = 0
     for iexample, example in enumerate(EXAMPLES):


Mime
View raw message