-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Limited inference with union of callables and assignment to a union #18191
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
Comments
…require `pydantic<=2.9.2` (#2767) **Issue resolved by this Pull Request:** Resolves #2765 Resolves #2773 **Checklist:** - [x] **Commit Message Formatting**: Commit titles and messages follow guidelines in the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary). - [ ] [Changelog](https://github.com/instructlab/instructlab/blob/main/CHANGELOG.md) updated with breaking and/or notable changes for the next minor release. - [ ] Documentation has been updated, if necessary. - [ ] Unit tests have been added, if necessary. - [ ] Functional tests have been added, if necessary. - [ ] E2E Workflow tests have been added, if necessary. In the `docling-parse` v3.0.0 release, the maintainers rearranged a lot of logic and deprecated certain syntaxes, which has resulted in our InstructLab e2e tests failing to build. (See #2765 for more details.) Since `docling-parse` is indirectly pulled in via the `instructlab-sdg` package, the `docling-parse`/`docling` issues were resolved in `instructlab-sdg` release [v0.6.2](https://github.com/instructlab/sdg/releases/tag/v0.6.2) and I have therefore updated this PR to require `instructlab-sdg>=0.6.2`. Also, there was another unforeseen issue that this PR fixes: We use `mypy` to execute our linting steps, but one of `mypy`'s dependencies was recently updated with breaking changes: <img width="1316" alt="Screenshot 2024-12-09 at 5 05 51 PM" src="https://github.com/user-attachments/assets/4a14c45d-9d8c-4f42-bb50-b625d2badc29"> Doing a quick investigation, I see that `mypy` has some issues filed for this problem: - python/mypy#18191 - pydantic/pydantic#10950 To workaround this dependency issue, I pinned the related dependency, `pydantic`, to `<=v2.9.2` in our `tox.ini` file. This will force our latest `mypy` to use a compatible `pydantic`. However, note that I did also pin `mypy>=1.0,<1.14`. I did this as a safety measure for when the `mypy` maintainers inevitably fix the issue in v1.14 or later. Approved-by: nathan-weinberg Approved-by: danmcp
I am not 100% sure is related, but the following code produces a similar error. The idea is to use the outer function as a parameter for a decorator, similar to what from typing import Callable
class Failure[F]: error: F
class Success[S]: value: S
type State[F, S] = Failure[F] | Success[S]
type InnerFn[F, S] = Callable[[], State[F, S]]
type WrapperFn[F, S] = Callable[[InnerFn[F, S]], InnerFn[F, S]]
type CallerFn[F, S] = Callable[..., InnerFn[F, S]]
def decorator_with_argument[F, S](caller: CallerFn[F, S]) -> WrapperFn[F, S]:
def wrapper(fn: InnerFn[F, S]) -> InnerFn[F, S]:
return fn
return wrapper
def outer_function1[F, S](state: State[F, S]) -> InnerFn[F, S]:
@decorator_with_argument(outer_function1)
def inner_function() -> State[F, S]:
return state
return inner_function MyPy produces the following errors:
Playground link: https://mypy-play.net/?mypy=latest&python=3.12&gist=6a93abe464faa4f20505341e99a3dd49. |
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
Apologies if this was raised already. The only related issue I could find is #15887.
In Pydantic 2.10, we changed the definition of our field function to be:
While this type checks correctly for some common use cases, we get errors when the
Field
function is assigned to a union of types, or when the default factory signature isn't trivial (e.g. contains overloads). Here are some examples failing:(playground)
Note that (at least for
a
), this worked as expected with the old type inference.I first wanted to know if this can be considered a mypy limitation, or is the code really unsafe in some way? Or maybe is it because the typing spec does not provide any info regarding these use cases?
In comparison, pyright and pyre accepts the provided examples. We will currently recommend users to add a
type: ignore
comment and redirect to this issue. However, feel free to close if there's already an issue tracking this.Thanks in advance
Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: