Repository: tefra/xsdata

Issue:
default substitution "Class"->"Type" does infix substitution
When I create a python class model from the [Ecore.xsd](https://git.eclipse.org/c/emf/org.eclipse.emf.git/plain/plugins/org.eclipse.emf.ecore/model/Ecore.xsd), the [xsdata.models.config.py:GeneratorConfig.create()](https://github.com/tefra/xsdata/blob/040692db47e6e51028fd959c793e757858c392d7/xsdata/models/config.py#L443) default substitution will mangle names EClass and EClassifier to EType and ETypeifier.

anchoring the search wit `^`and `$`like so `^Class$` fixed the problem.

`<Substitution type="class" search="^Class$" replace="Type"/>`


Discussion:
sonarcloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=tefra_xsdata&pullRequest=994) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=tefra_xsdata&pullRequest=994&resolved=false&inNewCodePeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/component_measures?id=tefra_xsdata&pullRequest=994&metric=new_accepted_issues&view=list)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=tefra_xsdata&pullRequest=994&resolved=false&inNewCodePeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/no-data-16px.png '') No data about Coverage  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=tefra_xsdata&pullRequest=994&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=tefra_xsdata&pullRequest=994)


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/tefra/xsdata/pull/994?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.94%. Comparing base [(`e652e08`)](https://app.codecov.io/gh/tefra/xsdata/commit/e652e08c2fc312f85cc35e4f6b0c8c3948b9d071?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou) to head [(`cb8f3f7`)](https://app.codecov.io/gh/tefra/xsdata/pull/994?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou).


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #994      +/-   ##
==========================================
- Coverage   99.94%   99.94%   -0.01%     
==========================================
  Files         117      117              
  Lines        9143     9140       -3     
  Branches     2171     2172       +1     
==========================================
- Hits         9138     9135       -3     
  Misses          4        4              
  Partials        1        1              
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/tefra/xsdata/pull/994?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou).


Patch:
diff --git a/xsdata/codegen/handlers/create_compound_fields.py b/xsdata/codegen/handlers/create_compound_fields.py
index 8f536038..8424d224 100644
--- a/xsdata/codegen/handlers/create_compound_fields.py
+++ b/xsdata/codegen/handlers/create_compound_fields.py
@@ -246,10 +246,7 @@ class CreateCompoundFields(RelativeHandlerInterface):
         Returns:
             The new choice attr for the compound attr.
         """
-        restrictions = attr.restrictions.clone()
-        restrictions.min_occurs = None
-        restrictions.max_occurs = None
-        restrictions.sequence = None
+        restrictions = attr.restrictions.clone(min_occurs=0, sequence=None)
 
         return Attr(
             name=attr.name,
diff --git a/xsdata/formats/dataclass/filters.py b/xsdata/formats/dataclass/filters.py
index 3c1ae4b1..4d5a0f64 100644
--- a/xsdata/formats/dataclass/filters.py
+++ b/xsdata/formats/dataclass/filters.py
@@ -483,8 +483,9 @@ class Filters:
             if choice.is_nameless:
                 del metadata["name"]
 
-            default_key = self.FACTORY_KEY if choice.is_factory else self.DEFAULT_KEY
-            metadata[default_key] = self.field_default_value(choice)
+            if choice.is_tokens:
+                metadata[self.FACTORY_KEY] = self.field_default_value(choice)
+
             metadata.update(restrictions)
 
             if self.docstring_style == DocstringStyle.ACCESSIBLE and choice.help:


Test patch:
diff --git a/tests/codegen/handlers/test_create_compound_fields.py b/tests/codegen/handlers/test_create_compound_fields.py
index a17fad16..32a5ffcd 100644
--- a/tests/codegen/handlers/test_create_compound_fields.py
+++ b/tests/codegen/handlers/test_create_compound_fields.py
@@ -230,10 +230,7 @@ class CreateCompoundFieldsTests(FactoryTestCase):
             choice="abc",
             sequence=1,
         )
-        expected_res = attr.restrictions.clone()
-        expected_res.min_occurs = None
-        expected_res.max_occurs = None
-        expected_res.sequence = None
+        expected_res = attr.restrictions.clone(min_occurs=0, sequence=None)
 
         actual = self.processor.build_attr_choice(attr)
 
diff --git a/tests/formats/dataclass/test_filters.py b/tests/formats/dataclass/test_filters.py
index d079924f..a81cfe51 100644
--- a/tests/formats/dataclass/test_filters.py
+++ b/tests/formats/dataclass/test_filters.py
@@ -538,7 +538,7 @@ class FiltersTests(FactoryTestCase):
                 "wildcard": True,
                 "type": "Type[object]",
             },
-            {"default": "'aa'", "name": "bar", "type": "Type[str]"},
+            {"name": "bar", "type": "Type[str]"},
             {
                 "default_factory": "list",
                 "name": "tok",