-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Additional type hints added to stub openpyxl #9764
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b68f9eb
Updated type hints
ArnabRollin 948d5f6
Merge branch 'python:main' into main
ArnabRollin ad01e57
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dd58853
Merge branch 'main' into main
AlexWaygood ed44b07
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 933b9f7
Add back missing import
AlexWaygood 2f0d3c5
Implement suggested changes
mynhardtburger 8ed83b4
Add overloads for `iter_rows` and `iter_cols`
AlexWaygood 04f0e7b
Suggested changes and clearing mypy_primer errors
mynhardtburger 12c1e49
Correct workbook.get_named_ranges()
mynhardtburger dd3da24
Remove unused Sequence import
mynhardtburger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
Remember that
tuple[T]
means "a single-element tuple where the sole element is of typeT
". You wanttuple[T, ...]
if you want to signify "a tuple of arbitrary length, where all elements are of typeT
".We could also possibly simplify this by just doing
Sequence[DefinedName]
(withSequence
imported fromcollections.abc
)?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.
Agreed on the
tuple[DefinedName, ...]
.collections.abc.Sequence
is broader than justlist
andtuple
. It also includesstr
andbytes
: https://docs.python.org/3/glossary.html#term-sequenceI don't think
collections.abc.Sequence
would be appropriate.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.
str
andbytes
are indeed both sequences, correct — but neither is a subtype ofSequence[DefinedName]
.str
is a subtype ofSequence[str]
, andbytes
is a subtype ofSequence[int]
. So if I were writing this PR, I would favour the simpler approach here :)But your approach isn't wrong by any means, and I don't want to be too picky :)
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.
2 things here I just noticed (sorry it's been a while that I've looked at openpyxl)
1: descriptors are not meant to be used directly for type hints. Descriptors are assigned to ClassVars of classes subtyping Serializable. Serializable members act as properties where the setter uses the descriptor for runtime vlaidation of the setter
2. Whilst the
Sequence
descriptor allows both list and tuple (https://foss.heptapod.net/openpyxl/openpyxl/-/blob/branch/3.1/openpyxl/descriptors/sequence.py#L18),DefinedNameList.definedName
specifically needs to be sliceable and appendable (at least in 3.0, this doesn't seem to be the case anymore for 3.1) https://foss.heptapod.net/openpyxl/openpyxl/-/blob/branch/3.0/openpyxl/workbook/defined_name.py#L207-209, the latter meaning it can't be a tuple.