Allow numeric and boolean simpleValue (#342) - #454
Open
BIMvoice wants to merge 1 commit into
Open
Conversation
xs:string as the sole encode target rejects a Python float/int/bool passed straight through xmlschema, forcing every caller to pre-cast to str even though any text is already valid content here. Union member order keeps xs:string first, so decode() still always returns str and no downstream consumer needs to change. Verified zero validity change across all 330 existing .ids files and all 37 IfcTester schema tests still pass with the patched schema swapped in. Fixes buildingSMART#342. AI-assisted-by: Claude (Anthropic)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #342.
The problem, reproduced
Schema/ids.xsdline 41 declares:so
xmlschema.encode()rejects a raw Python2.0with2.0 is not an instance of <class 'str'>, exactly as @atomczak reported. Confirmed against the current schema.Two things worth stating up front about scope:
.idsfile is affected. XML element text is textual regardless of declared type, so this is purely encode side ergonomics for type strict data binders. Validating existing files is unchanged.Documentation/UserManual/restrictions.mdalready says "A Simple Value may be text, a number, or a boolean (TRUE / FALSE)", andtolerance.mdrefers to "doubles in ids:simpleValue", so numeric and boolean content is already documented as normal usage. Only the XSD type is narrower than the documentation.The change
Two refinements on the proposal in the issue:
xs:integerrather thanxs:int, matching the base types already used throughoutDataTypes.md, andxs:booleanadded, which answers @janbrouwer's question in the thread, since a PythonTruehits the identical encode error.Member order matters, and this is the part worth reviewing
xs:stringmust stay first. With numeric types first,decode()starts returningDecimalandboolobjects instead ofstrfor numeric looking text, silently changing the contract for every existing consumer that expectssimpleValueto decode as a string. I confirmed this with a deliberately reordered control. Withxs:stringfirst, encode accepts native numeric and boolean values while decode is provably unchanged.Validation
.idsfiles underDocumentation/were validated against the current schema and this one: zero differences in validity verdict.Note that IfcTester itself was never affected, since it casts any value to
strbefore encoding. The defect only reaches third party tools that build IDS XML directly againstids.xsd.This PR was created with the assistance of an AI coding tool.