Skip to content

TypeError: cannot inherit frozen dataclass from a non-frozen one and TypeError: unsupported operand type(s) for |: 'str' and 'str' #1148

Description

@leon1995

I am trying to parse the schema from ws-discovery but I get the following error

xsdata generate /path/to/schema.xsd --package package_path

========= xsdata v24.11 / Python 3.12.7 / Platform win32 =========

Parsing schema file:///<schema>/xsd/ws-discovery.xsd
Parsing schema http://www.w3.org/2006/03/addressing/ws-addr.xsd
Compiling schema http://www.w3.org/2006/03/addressing/ws-addr.xsd
Builder: 27 main and 0 inner classes
Compiling schema file:///<schema>/xsd/ws-discovery.xsd
Builder: 31 main and 0 inner classes
Analyzer input: 58 main and 0 inner classes
Analyzer output: 49 main and 0 inner classes
Generating package: init
Generating package:package_path.ws_addr
Generating package: package_path.ws_discovery
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "<venv>\.venv\Scripts\xsdata.exe\__main__.py", line 8, in <module>
  File "<venv>\.venv\Lib\site-packages\xsdata\__main__.py", line 9, in main
    cli()
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 1442, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 1363, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 1830, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 1226, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 794, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\xsdata\cli.py", line 135, in generate
    transformer.process(uris, cache=cache)
  File "<venv>\.venv\Lib\site-packages\xsdata\codegen\transformer.py", line 138, in process
    self.process_classes()
  File "<venv>\.venv\Lib\site-packages\xsdata\codegen\transformer.py", line 288, in process_classes
    writer.write(classes)
  File "<venv>\.venv\Lib\site-packages\xsdata\codegen\writer.py", line 43, in write
    for result in self.generator.render(classes):
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\xsdata\formats\dataclass\generator.py", line 91, in render
    self.validate_imports()
  File "<venv>\.venv\Lib\site-packages\xsdata\formats\dataclass\generator.py", line 112, in validate_imports
    import_package(self.package_name(package))
  File "<venv>\.venv\Lib\site-packages\xsdata\formats\dataclass\generator.py", line 108, in import_package
    importlib.import_module(name)
  File "<user>\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<venv>\arctos\testxsd\eventing.py", line 275, in <module>
    @dataclass(frozen=True, slots=True)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<user>\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\dataclasses.py", line 1265, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<user>\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\dataclasses.py", line 1029, in _process_class
    raise TypeError('cannot inherit frozen dataclass from a '
TypeError: cannot inherit frozen dataclass from a non-frozen one

when using with the --frozen flag

xsdata generate /path/to/schema.xsd --package package_path --frozen

========= xsdata v24.11 / Python 3.12.7 / Platform win32 =========

Parsing schema file:///<schema>/xsd/ws-discovery.xsd
Parsing schema http://www.w3.org/2006/03/addressing/ws-addr.xsd
Compiling schema http://www.w3.org/2006/03/addressing/ws-addr.xsd
Builder: 27 main and 0 inner classes
Compiling schema file:///<schema>/xsd/ws-discovery.xsd
Builder: 31 main and 0 inner classes
Analyzer input: 58 main and 0 inner classes
Analyzer output: 49 main and 0 inner classes
Generating package: init
Generating package: arctos.testxsd.ws_addr
Generating package: arctos.testxsd.ws_discovery
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "<venv>\.venv\Scripts\xsdata.exe\__main__.py", line 8, in <module>
  File "<venv>\.venv\Lib\site-packages\xsdata\__main__.py", line 9, in main
    cli()
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 1442, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 1363, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 1830, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 1226, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\click\core.py", line 794, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\xsdata\cli.py", line 135, in generate
    transformer.process(uris, cache=cache)
  File "<venv>\.venv\Lib\site-packages\xsdata\codegen\transformer.py", line 138, in process
    self.process_classes()
  File "<venv>\.venv\Lib\site-packages\xsdata\codegen\transformer.py", line 288, in process_classes
    writer.write(classes)
  File "<venv>\.venv\Lib\site-packages\xsdata\codegen\writer.py", line 43, in write
    for result in self.generator.render(classes):
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<venv>\.venv\Lib\site-packages\xsdata\formats\dataclass\generator.py", line 91, in render
    self.validate_imports()
  File "<venv>\.venv\Lib\site-packages\xsdata\formats\dataclass\generator.py", line 112, in validate_imports
    import_package(self.package_name(package))
  File "<venv>\.venv\Lib\site-packages\xsdata\formats\dataclass\generator.py", line 108, in import_package
    importlib.import_module(name)
  File "<user>\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<package>\testxsd\mod.py", line 290, in <module>
    class TOperation(TExtensibleDocumented):
  File "<package>\testxsd\mod.py", line 295, in TOperation
    "TOperation.Input" | "TOperation.Output" | TFault
    ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for |: 'str' and 'str'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions