You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Linting error when class has a property with the same name after snake case #1117
In OpenAPI specs where a property has the same name as the snake cased class name (in the example below, the snake casing is the lower case, but if it was, ex, InstagramId, then this would happen with a property named instagram_id) the code generated has a duplicated variable name (see image below).
The suggested fix is that the return variable name should have an underscore _, in this example, email_.
Another option would be to change the name we use for the temporary value that's eventually returned, that way the property can keep its normal name.
The challenge will be picking a name that is unlikely to be used as a property. I suppose _email, since we try to avoid generating "private" names for properties?
This is an external API that I'm consuming so I can't really change the name of the property. I can, however, change the name of the class, which I changed to EmailObj.
But this is a temporary solution. The code should be fixed, imo.
The return variable name could be named return_obj, _return, obj, value or something neutral like that.
Seems to me like the only reason there's a variable name at all in that last part is that additional_properties needs to be set separately— it's been deliberately declared as not settable via the initializer (which also makes it not settable by evolve), for reasons I'm unclear on. Otherwise it could just be:
Seems to me like the only reason there's a variable name at all in that last part is that additional_properties needs to be set separately— it's been deliberately declared as not settable via the initializer (which also makes it not settable by evolve), for reasons I'm unclear on. Otherwise it could just be:
I'm having the same issue. For now, I've just replaced {% module_name %} with {% module_name %}_obj in a custom template to avoid the mypy error, but your approach looks cleaner to me.
@dbanty Is there a reason why additional_properties cannot be set during initialisation? If not, I could implement this and open a PR.
Activity
joaonc commentedon Sep 3, 2024
Note: I understand that
openapi-python-clientusesruff, but I also usemypyon the autogenerated code as it's part of a greater CI/CD workflow.dbanty commentedon Sep 4, 2024
Another option would be to change the name we use for the temporary value that's eventually returned, that way the property can keep its normal name.
The challenge will be picking a name that is unlikely to be used as a property. I suppose
_email, since we try to avoid generating "private" names for properties?joaonc commentedon Sep 4, 2024
This is an external API that I'm consuming so I can't really change the name of the property. I can, however, change the name of the class, which I changed to
EmailObj.But this is a temporary solution. The code should be fixed, imo.
The return variable name could be named
return_obj,_return,obj,valueor something neutral like that.eli-bl commentedon Nov 5, 2024
Seems to me like the only reason there's a variable name at all in that last part is that
additional_propertiesneeds to be set separately— it's been deliberately declared as not settable via the initializer (which also makes it not settable byevolve), for reasons I'm unclear on. Otherwise it could just be:micha91 commentedon Jul 1, 2025
I'm having the same issue. For now, I've just replaced
{% module_name %}with{% module_name %}_objin a custom template to avoid the mypy error, but your approach looks cleaner to me.@dbanty Is there a reason why
additional_propertiescannot be set during initialisation? If not, I could implement this and open a PR.dbanty commentedon Jul 3, 2025
@micha91 not that I remember 😅 so feel free to make a PR for it. Should be a pretty small change I think!