Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the internal prefix for value fields #647

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.6.0
rev: v2.7.1
hooks:
- id: reorder-python-imports
- repo: https://github.com/ambv/black
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/handlers/test_class_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def test_add_default_attribute(self):

ClassExtensionHandler.add_default_attribute(item, extension)
expected = AttrFactory.create(
name="@value", default=None, types=[xs_string], tag=Tag.EXTENSION
name="value", default=None, types=[xs_string], tag=Tag.EXTENSION
)

self.assertEqual(2, len(item.attrs))
Expand Down
17 changes: 0 additions & 17 deletions tests/codegen/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,6 @@ def test_copy_inner_class(self):
self.assertEqual(target.module, target.inner[0].module)
self.assertEqual(inner.qname, target.inner[0].qname)

def test_copy_inner_class_rename_simple_inner_type(self):
source = ClassFactory.create()
inner = ClassFactory.create(qname="{a}@value", module="b", package="c")
target = ClassFactory.create()
attr = AttrFactory.create(name="simple")
attr_type = AttrTypeFactory.create(forward=True, qname=inner.qname)

source.inner.append(inner)
ClassUtils.copy_inner_class(source, target, attr, attr_type)

self.assertEqual(1, len(target.inner))
self.assertIsNot(inner, target.inner[0])
self.assertEqual(target.package, target.inner[0].package)
self.assertEqual(target.module, target.inner[0].module)
self.assertEqual("{a}simple", target.inner[0].qname)
self.assertEqual("{a}simple", attr_type.qname)

def test_copy_inner_class_skip_non_forward_reference(self):
source = ClassFactory.create()
target = ClassFactory.create()
Expand Down
2 changes: 1 addition & 1 deletion tests/models/xsd/test_alternative.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class AlternativeTests(TestCase):
def test_property_real_name(self):
obj = Alternative()
self.assertEqual("@value", obj.real_name)
self.assertEqual("value", obj.real_name)

obj.id = "foo"
self.assertEqual("foo", obj.real_name)
Expand Down
2 changes: 1 addition & 1 deletion tests/models/xsd/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_is_attribute(self):

def test_real_name(self):
obj = List()
self.assertEqual("@value", obj.real_name)
self.assertEqual("value", obj.real_name)

def test_real_type(self):
obj = List()
Expand Down
2 changes: 1 addition & 1 deletion tests/models/xsd/test_restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_property_attr_types(self):

def test_property_real_name(self):
obj = Restriction()
self.assertEqual("@value", obj.real_name)
self.assertEqual("value", obj.real_name)

def test_property_bases(self):
obj = Restriction()
Expand Down
2 changes: 1 addition & 1 deletion tests/models/xsd/test_simple_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class SimpleTypeTests(TestCase):
def test_property_real_name(self):
obj = SimpleType()
self.assertEqual("@value", obj.real_name)
self.assertEqual("value", obj.real_name)

obj.name = "foo"
self.assertEqual("foo", obj.real_name)
Expand Down
2 changes: 1 addition & 1 deletion tests/models/xsd/test_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_property_is_property(self):

def test_property_real_name(self):
obj = Union()
self.assertEqual("@value", obj.real_name)
self.assertEqual("value", obj.real_name)

def test_property_attr_types(self):
obj = Union()
Expand Down
3 changes: 2 additions & 1 deletion xsdata/codegen/handlers/class_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from xsdata.models.enums import DataType
from xsdata.models.enums import NamespaceType
from xsdata.models.enums import Tag
from xsdata.utils.constants import DEFAULT_ATTR_NAME


class ClassExtensionHandler(RelativeHandlerInterface):
Expand Down Expand Up @@ -268,7 +269,7 @@ def add_default_attribute(cls, target: Class, extension: Extension):
type."""
if extension.type.datatype != DataType.ANY_TYPE:
tag = Tag.EXTENSION
name = "@value"
name = DEFAULT_ATTR_NAME
namespace = None
else:
tag = Tag.ANY
Expand Down
7 changes: 0 additions & 7 deletions xsdata/codegen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ class from the source to the target class.
clone = inner.clone()
clone.package = target.package
clone.module = target.module

# Simple type, update the name
if clone.name == "@value":
namespace, _ = namespaces.split_qname(clone.qname)
qname = namespaces.build_qname(namespace, attr.name)
clone.qname = attr_type.qname = qname

target.inner.append(clone)

@classmethod
Expand Down
3 changes: 1 addition & 2 deletions xsdata/models/xsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
from xsdata.models.mixins import ElementBase
from xsdata.utils import text
from xsdata.utils.collections import unique_sequence
from xsdata.utils.constants import DEFAULT_ATTR_NAME
from xsdata.utils.namespaces import clean_uri

docstring_serializer = XmlSerializer(
config=SerializerConfig(pretty_print=True, xml_declaration=False)
)

DEFAULT_ATTR_NAME = "@value"


@dataclass(frozen=True)
class Docstring:
Expand Down
1 change: 1 addition & 0 deletions xsdata/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

XML_FALSE = sys.intern("false")
XML_TRUE = sys.intern("true")
DEFAULT_ATTR_NAME = "value"


def return_true(*_: Any) -> bool:
Expand Down