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

Function signature hook returning a union #15457

Open
ikonst opened this issue Jun 17, 2023 · 0 comments
Open

Function signature hook returning a union #15457

ikonst opened this issue Jun 17, 2023 · 0 comments
Labels

Comments

@ikonst
Copy link
Contributor

ikonst commented Jun 17, 2023

Currently the function/method signature hooks must return a CallableType. This precludes cases where a union of CallableTypes would be more appropriate.

For example, given

@attrs.define
class C1:
  foo: int

@attrs.define
class C2:
  bar: int

c: C1 | C2

then the signature of attrs.evolve for c could be returned by a function signature hook to be
(c: C1, foo: int) -> C1 | (c: C2, bar: int) -> C2.

Today #14849 performs an ad-hoc "meet" operation which results in a single callable type, which could instead be left to the existing functionality that "meet"s a union's types.

p.s. that being said, the current behavior for a union of callables is not friendly, e.g.
in this playground, the given union of callables can accept a bytes arg, but if you give them the mutually incompatible int or str, it simply says that it must be the other one, instead of saying "it's compatible with item 1 of the union but incompatible with item 2", etc.

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

No branches or pull requests

1 participant