Skip to content
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

More annotations #3088

Merged
merged 4 commits into from
Jul 9, 2019
Merged

More annotations #3088

merged 4 commits into from
Jul 9, 2019

Conversation

crusaderky
Copy link
Contributor

A little incremental addition to type annotations. By no means complete, but it should be ready for merge in its own right nonetheless.

def set_coords(self, names, inplace=None):
def set_coords(
self,
names: 'Union[Hashable, Iterable[Hashable]]',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been nicer to use Collection[Hashable], but Collection requires Python 3.6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Sequence is NOT ok, because sets are not sequences

names = [names]
else:
names = list(names)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forced casting could have been avoided with Collection :(

@codecov
Copy link

codecov bot commented Jul 7, 2019

Codecov Report

Merging #3088 into master will decrease coverage by 0.03%.
The diff coverage is 94.82%.

@@            Coverage Diff             @@
##           master    #3088      +/-   ##
==========================================
- Coverage   92.68%   92.65%   -0.04%     
==========================================
  Files          63       63              
  Lines       12773    12787      +14     
  Branches     2906     2906              
==========================================
+ Hits        11839    11848       +9     
- Misses        619      623       +4     
- Partials      315      316       +1

def update(self, other, inplace=None):
def update(
self,
other: 'Union[Dataset, Mapping[Hashable, DataArray]]',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure about this - are there more options available for 'other'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes through the merge machinery (same as Dataset.__init__), so in principle I think you can put Variable objects or tuples of Variable arguments in the mapping values, too.

Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thanks @crusaderky !

@@ -161,13 +161,15 @@ class AttrAccessMixin:
_initialized = False

@property
def _attr_sources(self):
"""List of places to look-up items for attribute-style access"""
def _attr_sources(self) -> List[Mapping[Hashable, Any]]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Mapping[Hashable, Any] identical to Mapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no requirement for the keys of a Mapping to be hashable. This is relevant for the various setter methods Dataset.attrs which cast any Mapping to an OrderedDict.

@pep8speaks
Copy link

pep8speaks commented Jul 9, 2019

Hello @crusaderky! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-07-09 15:59:46 UTC

@shoyer shoyer merged commit 681893e into pydata:master Jul 9, 2019
@shoyer
Copy link
Member

shoyer commented Jul 9, 2019

thanks @crusaderky !

@crusaderky crusaderky deleted the annotations branch July 9, 2019 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants