8000 Provide hint when Union type with None may not have been narrowed by angelawuuu · Pull Request #17178 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Provide hint when Union type with None may not have been narrowed #17178

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added new circumstance of having NONE as the second object of a union…
… with warning message
  • Loading branch information
kr321 authored and kr321 committed Apr 23, 2024
commit 80f9788a4087e469e53d51102fcfefe86cbe7c50
23 changes: 17 additions & 6 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,23 @@ def has_no_attr(
type(item) == NoneType for item in original_type.items
):
typ_format = '"None"'
self.fail(
'Item {} of {} has no attribute "{}"{}'.format(
typ_format, orig_type_format, member, extra
),
context,
code=codes.UNION_ATTR,
if typ_format == '"None"':(
self.fail(
'Item {} of {} has no attribute "{}"{}. ADD HINT HERE'.format(
typ_format, orig_type_format, member, extra
),
context,
code=codes.UNION_ATTR,
)
)
else:(
self.fail(
'Item {} of {} has no attribute "{}"{}'.format(
typ_format, orig_type_format, member, extra
),
context,
code=codes.UNION_ATTR,
)
)
return codes.UNION_ATTR
elif isinstance(original_type, TypeVarType):
Expand Down
0