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

fix: Mark standalone None as is_optional. #12

Closed
wants to merge 1 commit into from

Conversation

DanCardin
Copy link
Collaborator

Description

This is not generally meaningful, because something is not really ever going to be annotated as foo: None.

However, when writing code that operates over something like for t in TypeView(int | None).inner_types, it can come up.

Perhaps in concert with #10, I might be able to avoid it, but... (it only occurred to me in writing this description :P), it maybe seems like the logical extension of:

assert TypeView(str | int | None).is_optional is True
assert TypeView(int | None).is_optional is True
assert TypeView(None).is_optional is True

Copy link
Contributor

@peterschutt peterschutt left a comment

Choose a reason for hiding this comment

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

Thanks, makes sense to me!

I think the collection stuff is unrelated though.

type_lens/type_view.py Outdated Show resolved Hide resolved
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/type-lens-docs-preview/12

@peterschutt
Copy link
Contributor

I'm having second thoughts on this, Optional is specifically a union that includes None in its members. Would an is_none_type property be better?

@DanCardin
Copy link
Collaborator Author

I have an is_none_type branch pending also. As i mentioned above the strip_optional() branch would also likely handle this case for my particular usecase. Thus, if you want to close this, i think i'll be fine.

But I was just thinking of the logical extension of the types. None is a special type that indicates "optional"ity, whether it's actually required or not. So i dont necessarily see the difference between int | None and None | None and None in terms of the expected result of this function, versus having the presense of None cause it to be True, but only when combined with other types.

@DanCardin DanCardin deleted the dc/is_optional branch May 15, 2024 18:39
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.

2 participants