Adds reserved word check to signature generation logic.#4012
Adds reserved word check to signature generation logic.#4012samuelcolvin merged 2 commits intopydantic:masterfrom
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
|
|
||
| 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.
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>.mdfile added describing change(see changes/README.md for details)