databricks-sdk-py icon indicating copy to clipboard operation
databricks-sdk-py copied to clipboard

[ISSUE] Lots of missing `Optional`s in the type hinting

Open judahrand opened this issue 1 year ago • 5 comments

Description

In lots of places the SDK's type hints look like:

foo: str = None

This typing is incorrect and should be:

foo: str | None = None

judahrand avatar Feb 26 '24 10:02 judahrand

@judahrand are you aware of mypy's --implicit-optional behaviour? The foo: str = None style is valid when using that option. (I don't know if other checkers have a similar behaviour, though it's likely they do)

I appreciate that not everyone uses that style (and I would personally discourage library authors from doing so as being explicit is usually clearer), however my understanding is that the spelling used in this project shouldn't impact how your project is type-checked. If it does, that may be a bug (e.g: https://github.com/python/mypy/issues/9208) in your type checker and/or you may need to configure handling of implicit optionals if it's intentional that this project uses that style.

PeterJCLaw avatar Feb 26 '24 11:02 PeterJCLaw

To be honest, this project doesn't make use of mypy typechecking quite yet. We've been meaning to add support for it, and I think we'd be open to discussion about whether enabling --implicit-optional is preferable or not for this project.

mgyucht avatar Feb 26 '24 12:02 mgyucht

I think that using explicit Optional is probably preferable given that not using it requires downstream consumers to have to configure their type checker correctly vs just using the defaults.

judahrand avatar Feb 26 '24 13:02 judahrand

This seems reasonable to me, especially as this seems to be the direction that mypy and the ecosystem are moving towards.

mgyucht avatar Feb 26 '24 13:02 mgyucht

This seems reasonable to me, especially as this seems to be the direction that mypy and the ecosystem are moving towards.

This might not be the right place to raise this but it would be nice if this could be changed/updated in databricks-connect too. I'd open a PR but unfortunately the source isn't available anywhere other that PyPi.

judahrand avatar Feb 26 '24 13:02 judahrand