pystac icon indicating copy to clipboard operation
pystac copied to clipboard

alternative constructors shouldn't hardcode their return types

Open TomAugspurger opened this issue 3 years ago • 2 comments

Currently, alternative constructors like Collection.from_dict define the return type as "Collection". https://github.com/stac-utils/pystac/blob/2e76a877b02eccf4d8e8ec6ad7b4aa7cf09aa268/pystac/collection.py#L607-L615

This makes is hard for subclasses to properly override the methods, since they'll be returning the subclasses type.

See something like https://stackoverflow.com/a/44644576/1889400 or https://mypy.readthedocs.io/en/stable/more_types.html?highlight=classmethod#precise-typing-of-alternative-constructors.

TomAugspurger avatar Jul 28 '22 18:07 TomAugspurger

I've used the technique described in the first stack overflow link with success, example

lossyrob avatar Jul 28 '22 19:07 lossyrob

I'm working on fixing this.

TomAugspurger avatar Jul 29 '22 14:07 TomAugspurger

Incorrectly auto-closed by #962

gadomski avatar Feb 10 '23 15:02 gadomski