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
Adds reserved word check to signature generation logic. #4012
Adds reserved word check to signature generation logic. #4012
Conversation
I found this issue and PR via some reports about Hypothesis, and this is exactly how I'd fix it 👍 (plus the traditional better-error-message in Hypothesis, of course 😅) |
please review |
@samuelcolvin since my PR was accepted by CPython, this is now a bugfix for Python 3.11.0b1 and later; without it you'll get unhandled |
Congrats, I'll merge this once I get 1.9.1 out. |
1.9.1 is out, so would you mind merging this? |
pydantic/utils.py
Outdated
@@ -192,6 +194,15 @@ def in_ipython() -> bool: | |||
return True | |||
|
|||
|
|||
def is_valid_identifier(identifier: str) -> bool: | |||
""" | |||
Checks that a string is a valid identifier and not a reserved word. |
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.
Based on official iskeyword doc I would
Checks that a string is a valid identifier and not a reserved word. | |
Checks that a string is a valid identifier and not a Python keyword. |
Thanks @strue36 for the patch 👍 I just left a small comment regarding the function docstring. |
please update |
Let me know if you want me to squash both commits together. |
No, we will squash it when merging. |
thanks so much. |
Change Summary
Adds a check within
utils.generate_model_signature()
to treat reserved words as invalid identifiers.Related issue number
fix #4011"
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)