Skip to content
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

Signature inference for attributes inherited from generic dataclasses #1780

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Code Contributors
- Andrii Kolomoiets (@muffinmad)
- Leo Ryu (@Leo-Ryu)
- Joseph Birkner (@josephbirkner)
- Brent Yi (@brentyi)

And a few more "anonymous" contributors.

Expand Down
13 changes: 12 additions & 1 deletion jedi/plugins/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,18 @@ class DataclassWrapper(ValueWrapper, ClassMixin):
def get_signatures(self):
param_names = []
for cls in reversed(list(self.py__mro__())):
if isinstance(cls, DataclassWrapper):

# Handle cases where DataclassWrapper objects are nested inside of
# Decoratee, GenericClass, etc -- these are all subclasses of ValueWrapper
# or LazyValueWrapper.
is_dataclass = False
while isinstance(cls, (ValueWrapper, LazyValueWrapper)):
if isinstance(cls, DataclassWrapper):
is_dataclass = True
break
cls = cls._wrapped_value

if is_dataclass:
filter_ = cls.as_context().get_global_filter()
# .values ordering is not guaranteed, at least not in
# Python < 3.6, when dicts where not ordered, which is an
Expand Down
20 changes: 20 additions & 0 deletions test/test_inference/test_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ class Y():
z = 5
@dataclass
class X(Y):'''), ['y']],
[dedent('''
from typing import Generic, TypeVar
T = TypeVar("T")
@dataclass
class Y(Generic[T]):
y: T
z = 5
@dataclass
class X(Y[int]):'''), ['y']],
[dedent('''
from typing import Generic, TypeVar
T = TypeVar("T")
@dataclass
class Z:
z: int
@dataclass
class Y(Z, Generic[T]):
y: T
@dataclass
class X(Y[int]):'''), ['z', 'y']],
]
)
def test_dataclass_signature(Script, skip_pre_python37, start, start_params):
Expand Down