-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Incompatible types in assignment for property setter #8348
Comments
We are having a similar issue. We are taking a str_date and a format and trying to do a strptime error: Incompatible types in assignment (expression has type "datetime", variable has type "str") The below section of code is where we are getting the error from date_formats = ['%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M:%S', '%Y-%m-%d']
event_dates = {
"date_1": event_date_1,
"date_2": event_date_2
}
for key, date in event_dates.items():
for date_format in date_formats:
try:
date = datetime.strptime(date, date_format) # This is the offending line
if date < datetime.strptime('1900-01-01', '%Y-%m-%d'):
event_dates[key] = None
except (ValueError, TypeError):
pass |
@bsdtux I think your issue is unrelated; pretty sure you're running into https://mypy.readthedocs.io/en/stable/common_issues.html#redefinitions-with-incompatible-types. You might be able to get around it by renaming the variable (to, eg, |
thanks @hauntsaninja it looks like what it was upset about was that we were taking the date variable in the loop and going from a string to a date object. So after taking your advice we change the date in the for loop to be date_str and the date variable holding the output of strptime was changed to new_date and now mypy is happy. |
@tamuhey I wonder if yours is the same where you define the x property of having a list type but then on the setter, you are saying it takes an iterable. What happens if you set the getter for x to be type iterable as well? |
The users of |
Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues
Please provide more information to help us understand the issue:
bug
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
No error because setter requires
Iterable[int]
, notList[int]
Do you see the same issue after installing mypy from Git master?
master
no flag
the full traceback below.
The text was updated successfully, but these errors were encountered: