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

reportUnknownArgumentType when argument type is defined in Callable via Protocol #754

Closed
Kein opened this issue Dec 18, 2020 · 2 comments
Closed
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@Kein
Copy link

Kein commented Dec 18, 2020

Environment data

Pylance 2020.12.2
Python 3.8.5

Expected behaviour

No warnings

Actual behaviour

False-positive warning:
image

Code Snippet / Additional information

from dataclasses import dataclass
from typing import NamedTuple, Dict, Tuple, Union, Any, Protocol

VertData = NamedTuple("VertData", [('val', int)])
Prop = NamedTuple("Prop", [('size', int)])

class Reader(Protocol):
    def __call__(self, x: memoryview, y: Dict[str, Any]) -> Union[int, Tuple[float,...], VertData, None]:
        ...

@dataclass
class ParsedData:
    prop: Prop
    value: Union[int, Tuple[float,...], VertData, None]
    reader: Reader

data = memoryview(b'sadfsdfsdfsdf')
propMap = Prop(1)
propValues=dict(str1=ParsedData(prop=propMap, value=None, reader=lambda x,y: print(x)))
 
for (k,v) in propValues.items():
    vprp = v.prop
    f = v.reader
    v.value = f(data[1:0], propValues)

https://mypy-play.net/?mypy=latest&python=3.7&flags=strict&gist=202f4a912fb9b7125722676630894b6d

@erictraut
Copy link
Contributor

This will be addressed in the next release.

@erictraut erictraut added enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Dec 21, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.1.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202110-6-january-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 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