Verifying match pattern fails on destructuring dataclass type
azh-r opened this issue · comments
Azhar Desai commented
The following Python 3.10 executes correctly, but fails to pass pytype validation:
from dataclasses import dataclass
@dataclass
class Point:
x: float
y: float
if __name__ == "__main__":
p = Point(1.00, 2.00)
match p:
case Point(x, y):
print(f"({x}, {y})")
case _:
print("not matched")
The error pytype reports is for the case Point(x,y)
match pattern, where it doesn't see the auto-generated match_args provided by the Point
dataclass:
File "/private/tmp/tmp.ReLNbFNCiO/dataclass-match.py", line 11, in <module>: Point() accepts 0 positional sub-patterns (2 given) [match-error]
The fuller details are:
$ python --version
Python 3.10.10
$ python dataclass-match.py
(1.0, 2.0)
$ pytype --version
2024.01.24
$ pytype --verbosity=2 dataclass-match.py
INFO No config file found. Using default configuration.
INFO Configuration:
exclude = set()
inputs = {'/private/tmp/tmp.ReLNbFNCiO/dataclass-match.py'}
keep_going = False
jobs = 1
output = '/private/tmp/tmp.ReLNbFNCiO/.pytype'
platform = 'darwin'
pythonpath = ['/private/tmp/tmp.ReLNbFNCiO']
python_version = '3.10'
disable = []
report_errors = True
bind_decorated_methods = False
none_is_not_bool = False
overriding_renamed_parameter_count_checks = False
strict_none_binding = False
use_fiddle_overlay = False
no_return_any = False
require_override_decorator = False
precise_return = False
protocols = False
strict_import = False
strict_parameter_checks = False
strict_primitive_comparisons = False
strict_undefined_checks = False
Computing dependencies
INFO Source tree:
source: /private/tmp/tmp.ReLNbFNCiO/dataclass-match.py
deps:
[/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/_collections_abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/_typeshed/__init__.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/_winapi.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/codecs.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/collections/abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/contextlib.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/dataclasses.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/__init__.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/charset.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/contentmanager.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/header.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/message.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/policy.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/genericpath.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/machinery.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/metadata/__init__.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/metadata/_meta.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/readers.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/resources/abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/io.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/ntpath.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/os/__init__.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/os/path.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/pathlib.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/posixpath.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/re.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/sre_compile.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/sre_constants.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/sre_parse.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/subprocess.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/types.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/typing_extensions.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/zipfile.pyi]
source: [/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/_collections_abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/_typeshed/__init__.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/_winapi.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/codecs.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/collections/abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/contextlib.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/dataclasses.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/__init__.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/charset.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/contentmanager.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/header.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/message.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/policy.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/genericpath.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/machinery.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/metadata/__init__.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/metadata/_meta.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/readers.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/importlib/resources/abc.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/io.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/ntpath.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/os/__init__.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/os/path.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/pathlib.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/posixpath.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/re.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/sre_compile.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/sre_constants.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/sre_parse.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/subprocess.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/types.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/typing_extensions.pyi->/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/zipfile.pyi]
deps:
/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/stdlib/enum.pytd
/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/builtins/builtins.pytd
/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/builtins/typing.pytd
/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/stdlib/collections/__init__.pytd
/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/errors.pyi
source: /Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/stdlib/enum.pytd
deps:
/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/builtins/typing.pytd
source: /Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/builtins/builtins.pytd
deps:
/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/builtins/typing.pytd
source: /Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/stdlib/collections/__init__.pytd
deps:
/Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/builtins/typing.pytd
source: /Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/typeshed/stdlib/email/errors.pyi
source: /Users/user123/.pyenv/versions/3.10.10/envs/sss/lib/python3.10/site-packages/pytype/stubs/builtins/typing.pytd
INFO ------------- Starting pytype run. -------------
INFO infer command: /Users/user123/.pyenv/versions/3.10.10/envs/sss/bin/python3.10 -m pytype.single --imports_info $imports --module-name $module --platform darwin -V 3.10 -o $out --no-report-errors --nofail --quick $in
INFO check command: /Users/user123/.pyenv/versions/3.10.10/envs/sss/bin/python3.10 -m pytype.single --imports_info $imports --module-name $module --platform darwin -V 3.10 -o $out --analyze-annotated --nofail --quick $in
INFO check dataclass-match
imports: /private/tmp/tmp.ReLNbFNCiO/.pytype/imports/dataclass-match.imports
deps: ()
output: /private/tmp/tmp.ReLNbFNCiO/.pytype/pyi/dataclass-match.pyi
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] /Users/user123/.pyenv/versions/3.10.10/envs/sss/bin/python3.10 -m pytype.single --imports_info /private/tmp/tmp.ReLNbFNCiO/.pytype/imports/dataclass-match.imports --module-name dataclass-match --platform darwin -V 3.10 -o /private/tmp/tmp.ReLNbFNCiO/.pytype/pyi/dataclass-match.pyi --analyze-annotated --nofail --quick /private/tmp/tmp.ReLNbFNCiO/dataclass-match.py
FAILED: /private/tmp/tmp.ReLNbFNCiO/.pytype/pyi/dataclass-match.pyi
/Users/user123/.pyenv/versions/3.10.10/envs/sss/bin/python3.10 -m pytype.single --imports_info /private/tmp/tmp.ReLNbFNCiO/.pytype/imports/dataclass-match.imports --module-name dataclass-match --platform darwin -V 3.10 -o /private/tmp/tmp.ReLNbFNCiO/.pytype/pyi/dataclass-match.pyi --analyze-annotated --nofail --quick /private/tmp/tmp.ReLNbFNCiO/dataclass-match.py
File "/private/tmp/tmp.ReLNbFNCiO/dataclass-match.py", line 11, in <module>: Point() accepts 0 positional sub-patterns (2 given) [match-error]
For more details, see https://google.github.io/pytype/errors.html#match-error
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'
(sss) ➜ tmp.ReLNbFNCiO pytype dataclass-match.py
Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] check dataclass-match
FAILED: /private/tmp/tmp.ReLNbFNCiO/.pytype/pyi/dataclass-match.pyi
/Users/user123/.pyenv/versions/3.10.10/envs/sss/bin/python3.10 -m pytype.single --imports_info /private/tmp/tmp.ReLNbFNCiO/.pytype/imports/dataclass-match.imports --module-name dataclass-match --platform darwin -V 3.10 -o /private/tmp/tmp.ReLNbFNCiO/.pytype/pyi/dataclass-match.pyi --analyze-annotated --nofail --quick /private/tmp/tmp.ReLNbFNCiO/dataclass-match.py
File "/private/tmp/tmp.ReLNbFNCiO/dataclass-match.py", line 11, in <module>: Point() accepts 0 positional sub-patterns (2 given) [match-error]
For more details, see https://google.github.io/pytype/errors.html#match-error
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'
Rebecca Chen commented
I've sent a fix out for review. It'll take ~a week to be submitted, tested, and released.
Azhar Desai commented
Wow, thanks @rchen152 ! That was a quick & great fix.