8000 Allow overloads in source files, not just stubs by sixolet · Pull Request #2603 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Allow overloads in source files, not just stubs #2603

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 18 commits into from
Mar 27, 2017
Merged
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
Prev Previous commit
Next Next commit
Properties count as overloads too
  • Loading branch information
sixolet committed Feb 17, 2017
commit bb5fdae5d7b374cc02a8d0429a37db5eecfd8fb2
14 changes: 10 additions & 4 deletions mypy/sharedparse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Union, Tuple

from mypy.nodes import Decorator, NameExpr, Statement
from mypy.nodes import Decorator, NameExpr, Statement, MemberExpr

"""Shared logic between our three mypy parser files."""

Expand Down Expand Up @@ -101,7 +101,13 @@ def special_function_elide_names(name: str) -> bool:
def argument_elide_name(name: Union[str, Tuple, None]) -> bool:
return isinstance(name, str) and name.startswith("__")

def _is_overload_decorator(dec):
if isinstance(dec, NameExpr) and dec.name in {'overload', 'property', 'abstractproperty'}:
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment explaining why properties are also considered overloads? Is this just because the same parse tree structure is used to support a sequence of @property, @f.getter and/or @f.deleter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instead I deferred it to semanalysis time, where it belongs

return True
elif isinstance(dec, MemberExpr) and dec.name in {'setter', 'deleter'}:
return True
return False

def is_overload_part(stmt: Statement) -> bool:
return isinstance(stmt, Decorator) and any(
isinstance(dec, NameExpr) and dec.name == 'overload'
for dec in stmt.decorators)
return isinstance(stmt, Decorator) and any(_is_overload_decorator(dec)
for dec in stmt.decorators)
0