home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 368598394

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/1938#issuecomment-368598394 https://api.github.com/repos/pydata/xarray/issues/1938 368598394 MDEyOklzc3VlQ29tbWVudDM2ODU5ODM5NA== 1217238 2018-02-26T18:22:33Z 2018-02-26T18:22:33Z MEMBER

I made a tweaked version of dispatching to list subtypes, which probably suitable for use in xarray: https://drive.google.com/file/d/18zdyUpWLNFzFaz08GUOC5vs1GxE_jHg-/view?usp=sharing

Example behavior: ```python @dispatch(List[int]) def f(args): print('integers:', args)

@dispatch(List[str]) def f(args): print('strings:', args)

@dispatch(List[str, int]) def f(args): print('mixed str-int:', args)

f([1, 2]) # integers: [1, 2] f([1, 2, 'foo']) # mixed str-int: [1, 2, 'foo'] f(['foo', 'bar']) # strings: ['foo', 'bar'] f([[1, 2]]) # NotImplementedError: Could not find signature for f: <List[list]> ```

Differences from @llllllllll's VarArgs: - I don't actually subclass from tuple/list. You can't use the List constructor directly or do issubclass with list objects (this matches typing.List) - I added sugar so that you don't need to write the dispatch function for list, and implementations actually receive native Python list objects as arguments, not VarArgs instances. - Type caching is done based on the set of element types, not the sequence of element types. I think this is more performant/correct.

It would be straightforward to adapt this to use typing.List, but since we'll want to define our own dispatch functions anyways for our own xarray-specific multipledispatch namespace, I'm just as happy to use an internal xarray.dispatching.List type.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  299668148
Powered by Datasette · Queries took 158.106ms · About: xarray-datasette