-
Notifications
You must be signed in to change notification settings - Fork 85
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
Allow Date trait type to reject datetime instances #1429
Conversation
@kitchoi Would the change in this PR meet your needs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you.
|
||
# simplified signature | ||
_OptionalDate = Optional[datetime.date] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other trait types don't seem to need this Optional bit. I don't think I understand why this is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's there because None
is a valid value for this trait. The other trait types (Datetime
and Time
) should have this, I think, else mypy will complain about the assignment of None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And arguably, None
should not be a valid trait value here. That's where I'd like to get to, but we can't do it immediately because of backwards compatibility concerns.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it is already there for Datetime
and Time
: the possibility of None
is there in the _BaseClass
generic definition. We've switched from using _BaseInstance
as a base here to something more specific (and more accurate).
This PR makes it possible to specify that a
Date
trait should not acceptdatetime
instances, which is usually the behaviour that the user expects/wants.allow_datetime
parameter toDate
. It defaults toTrue
, for backwards compatibility.Date
to a properTraitType
subclass.Closes some but not all of #398. I'd like to leave that issue open for the question of considering changing the
allow_datetime
default under a deprecation warning.Checklist
docs/source/traits_api_reference
)[ ] Update User manual (N/A - no user documentation fordocs/source/traits_user_manual
)Date
traits-stubs