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

In functools.partial, container of subclass is not recognized as container of baseclass #4044

Closed
RmZeta2718 opened this issue Mar 5, 2023 · 2 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@RmZeta2718
Copy link

Environment data

  • Language Server version: v2023.3.10
  • OS and version: ubuntu18.04
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda python3.10

Code Snippet

from functools import partial

class BaseClass:
    pass

class SubClass(BaseClass):
    pass

def func(base: BaseClass):
    pass

def func_list(base: list[BaseClass]):
    pass

def func_set(base: set[BaseClass]):
    pass

sub = SubClass()

func(sub)  # works fine
func_list([sub])  # works fine
func_set({sub})  # works fine

partial(func, sub)  # works fine
partial(func_list, [sub])  # error
partial(func_set, {sub})  # error

Expected behavior

No errors reported.

Actual behavior

Argument of type "list[SubClass]" cannot be assigned to parameter "base" of type "list[BaseClass]" in function func_list" Pylance(reportGeneralTypeIssues)

Argument of type "set[SubClass]" cannot be assigned to parameter "base" of type "set[BaseClass]" in function "func_set" Pylance(reportGeneralTypeIssues)

erictraut pushed a commit to microsoft/pyright that referenced this issue Mar 5, 2023
…`functools.partial` call along with false positive errors. The problem is that the special-case logic for `functools.partial` was not applying bidirectional type inference when evaluating the arg type. This addresses microsoft/pylance-release#4044.
@erictraut
Copy link
Contributor

Thanks for the bug report. This will be addressed in the next release.

@debonte debonte added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage-needed labels Mar 6, 2023
@debonte
Copy link
Contributor

debonte commented Mar 9, 2023

This issue has been fixed in prerelease version 2023.3.21, which we've just released. You can find the changelog here: CHANGELOG.md

@debonte debonte closed this as completed Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants