Skip to content

Type checking fails when using constructor overrides in arrayconnection.py #32

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

Closed
markedwards opened this issue May 18, 2020 · 1 comment · Fixed by #33
Closed

Type checking fails when using constructor overrides in arrayconnection.py #32

markedwards opened this issue May 18, 2020 · 1 comment · Fixed by #33

Comments

@markedwards
Copy link
Contributor

markedwards commented May 18, 2020

Overriding one of the type constructors in one of the resolvers in arrayconnection.py breaks the return type of resolver.

For instance:

@dataclass
class CustomConnection:
    edges: List[Edge]
    pageInfo: PageInfo

# connection is typed as Connection, but it is actually CustomConnection
connection = connection_from_array(
    [], 
    connection_type=CustomConnection,
)

As with issue #29, this can be cleanly resolved using custom Protocol definitions, although there is the downside noted in that issue of the additional typing-extensions dependency.

Unlike the other issue, I think you could implement a partial solution using Callable, TypeVar, and overload from typing, without having the Protocol dependency. I'm pretty sure the resulting code would be extremely difficult to understand though, and it would be very verbose.

@markedwards
Copy link
Contributor Author

As with #29, I'm adding a PR here to demonstrate a solution using Protocol. Even if this is deemed unpalatable right now, it be an acceptable change in the future.

@Cito Cito closed this as completed in #33 Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant