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

Streamline Attribute.__get__ type stubs #578

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ikonst
Copy link
Contributor

@ikonst ikonst commented Jan 3, 2019

We can use the fact that Attribute[_T] is a generic class to DRY __get__.

def is_type_safe(self, key: Any, value: Any) -> bool: ...
def validate(self) -> bool: ...

class ListAttribute(Generic[_T], Attribute[List[_T]]):
class ListAttribute(Generic[_MT], Attribute[List[_MT]]):
Copy link
Contributor Author

@ikonst ikonst Jan 3, 2019

Choose a reason for hiding this comment

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

ListAttribute's of argument is restricted to MapAttribute-based types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, that's true only if of is not None, otherwise every element of ListAttribute can be either a number, a string, a MapAttribute, etc. but we cannot really express it in type stubs alone :(

@ikonst
Copy link
Contributor Author

ikonst commented Jan 3, 2019

cc @garrettheel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants