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
I have searched (google, github) for similar issues and couldn't find anything
I have read and followed the docs and still think this is a bug
Bug
When creating a model with a field that has an alias that is a python reserved word, the signature uses the reserved word even when allow_population_by_field_name is true.
I expect the signature to use the field name in this case. I came across this issue when generating tests using hypothesis. This uses the model signature and was creating invalid test code as it was using the reserved words in the signature.
I propose replacing these with calls to the following (new) function.
defis_valid_identifier(identifier: str) ->bool:
""" Checks that a string is a valid identifier and not a reserved word. :param identifier: The identifier to test. :return: True if the identifier is valid. """returnidentifier.isidentifier() andnotkeyword.iskeyword(identifier)
I believe that this behaviour is closer to what a user would expect in the common case that they are generating models from a schema containing python reserved words.
The text was updated successfully, but these errors were encountered:
Checks
Bug
When creating a model with a field that has an alias that is a python reserved word, the signature uses the reserved word even when
allow_population_by_field_name
is true.I expect the signature to use the field name in this case. I came across this issue when generating tests using hypothesis. This uses the model signature and was creating invalid test code as it was using the reserved words in the signature.
Suggestion
In
utils.generate_model_signature()
we have these two checks.I propose replacing these with calls to the following (new) function.
I believe that this behaviour is closer to what a user would expect in the common case that they are generating models from a schema containing python reserved words.
The text was updated successfully, but these errors were encountered: