-
Notifications
You must be signed in to change notification settings - Fork 117
Update forms.py
to fix #284
#285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
An exception `AttributeError` is raised when `child.targets[0]` does not have an attribute `name`, as stated in the issue #284 . `meta.get_children()` returns all children of the `Meta` class, which in the sample code contains a dictionary assignment. The expected children are of type `Assign` whose first item in the attribute `targets` is of type `AssignName`, like `AssignName.widgets(name='widgets')`. An instruction like `widget["field"] = forms.SomeWidget` will result in a `Assign` child containing a `Subscript(ctx=<Context.Store: 2>, value=<Name.widgets ...>, slice=<Index ...>)`. This is of course unexpected. I guess other unexpected instructions in the `Meta` class can trigger similar errors, so probably the most economic solution is to enclose the code in `try... except` and ignore the `AttributeError`. Trying to identify the type of object before accessing the `name` attribute would probably incur in a slower execution.
Pull Request Test Coverage Report for Build 1258
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems cleaner than adding the isinstance
before checking for the name
, but it may need to be changed if at some point more verification is added to the children and you need to handle other types of items in targets
.
Include `Form` class to test that assigning a specific widget doesn't throw an error, as mentioned in #284.
An exception
AttributeError
is raised whenchild.targets[0]
does not have an attributename
, as stated in the issue #284 .meta.get_children()
returns all children of theMeta
class, which in the sample code contains a dictionary assignment.The expected children are of type
Assign
whose first item in the attributetargets
is of typeAssignName
, likeAssignName.widgets(name='widgets')
.An instruction like
widget["field"] = forms.SomeWidget
will result in aAssign
child containing aSubscript(ctx=<Context.Store: 2>, value=<Name.widgets ...>, slice=<Index ...>)
. This is of course unexpected.I guess other unexpected instructions in the
Meta
class can trigger similar errors, so probably the most economic solution is to enclose the code intry... except
and ignore theAttributeError
. Trying to identify the type of object before accessing thename
attribute would probably incur in a slower execution.