Midnighter / structurizr-python

A Python 3 port of Simon Brown's Structurizr diagrams-as-code architecture description tool.
https://structurizr.com/
Apache License 2.0
65 stars 16 forks source link

Make error message more intuitive if you get a wrong parameter on an element constructor #50

Closed yt-ms closed 3 years ago

yt-ms commented 3 years ago

Problem description

It's easy to get a constructor argument wrong, but at the moment the error you get back isn't very helpful:

>>> Container(name="Container", bar=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  ...
  File "c:\...\structurizr-python\src\structurizr\model\model_item.py", line 86, in __init__
    super().__init__(**kwargs)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

This should be more in line with a regular object:

>>> class Foo:
...   def __init__(self):
...     pass
...
>>> Foo(bar=7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'bar'

Code Sample

Create a minimal, complete, verifiable example.

from structurizr.model import Container
Container(name="container", foobar=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\...\structurizr-python\src\structurizr\model\container.py", line 98, in __init__
    super().__init__(**kwargs)
  File "c:\...\structurizr-python\src\structurizr\model\element.py", line 71, in __init__
    super().__init__(**kwargs)
  File "c:\...\structurizr-python\src\structurizr\mixin\model_ref_mixin.py", line 35, in __init__
    super().__init__(**kwargs)
  File "c:\...\structurizr-python\src\structurizr\model\model_item.py", line 86, in __init__
    super().__init__(**kwargs)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

Context

``` System Information ================== OS Windows OS-release 10 Python 3.7.5 Package Versions ================ depinfo 1.5.4 httpx 0.16.1 importlib_metadata 1.7.0 ordered-set 3.1 pip 20.2.4 pydantic 1.7.1 python-dotenv 0.14.0 setuptools 41.2.0 structurizr-python 0.1.1+32.g8fa91ab.dirty ```