Skip to content

Allow OverloadedFuncDef to have no items #6174

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

Merged
merged 2 commits into from
Jan 10, 2019
Merged
Changes from all commits
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
7 changes: 5 additions & 2 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,11 @@ class OverloadedFuncDef(FuncBase, SymbolNode, Statement):

def __init__(self, items: List['OverloadPart']) -> None:
super().__init__()
assert len(items) > 0
self.items = items
self.unanalyzed_items = items.copy()
self.impl = None
self.set_line(items[0].line)
if len(items) > 0:
self.set_line(items[0].line)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe try using self.impl to set line, like in the name() method just below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does not work, as self.impl is None at this point (see line above).

Copy link
Member

Choose a reason for hiding this comment

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

OK, I see, maybe then set line in deserialize() method below? For example under the if data.get('impl') is not None: branch if items is empty (with a comment explaining that if overload items are empty then the line will not be set in __init__).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I added it, works for me locally 👍

self.is_final = False

def name(self) -> str:
Expand Down Expand Up @@ -478,6 +478,9 @@ def deserialize(cls, data: JsonDict) -> 'OverloadedFuncDef':
for d in data['items']])
if data.get('impl') is not None:
res.impl = cast(OverloadPart, SymbolNode.deserialize(data['impl']))
# set line for empty overload items, as not set in __init__
if len(res.items) > 0:
res.set_line(res.impl.line)
if data.get('type') is not None:
res.type = mypy.types.deserialize_type(data['type'])
res._fullname = data['fullname']
Expand Down