Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

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

Closed
yt-ms opened this issue Nov 2, 2020 · 0 comments · Fixed by #60
Closed

Comments

@yt-ms
Copy link
Collaborator

yt-ms commented Nov 2, 2020

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant