Remove UP007/UP045 ignores and fix guess_field_type for UnionType#8977
Draft
Remove UP007/UP045 ignores and fix guess_field_type for UnionType#8977
Conversation
Fix Optional[X] -> X | None and Union[X,Y] -> X | Y across branch/models.py, graph/constraints.py, graph/schema.py, and node/standard.py; remove dead UP007 ignore for core/query/**.py. The guess_field_type method now checks for both typing.Union and types.UnionType so that X | None fields are handled correctly at runtime in to_db/from_db after the annotation syntax change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Update to use modern version of optional types.
What changed
Fix Optional[X] -> X | None and Union[X,Y] -> X | Y across branch/models.py, graph/constraints.py, graph/schema.py, and node/standard.py; remove dead UP007 ignore for core/query/**.py.
The guess_field_type method now checks for both typing.Union and types.UnionType so that X | None fields are handled correctly at runtime in to_db/from_db after the annotation syntax change.
Summary by cubic
Migrate type hints to PEP 604 unions (
X | Y) and fix runtime type detection soX | Nonefields serialize/deserialize correctly. Removes now-unneededUP007/UP045ignores.Bug Fixes
guess_field_typeto recognize bothtyping.Unionandtypes.UnionType, ensuringX | Noneworks into_db/from_db.Refactors
Optional[X]withX | NoneandUnion[X, Y]withX | Yincore/branch/models.py,core/graph/{constraints.py,schema.py}, andcore/node/standard.py.UP007/UP045ignores inpyproject.toml(including the deadcore/query/**.pyrule).Written for commit 2c1b450. Summary will update on new commits.