8000 Add plugin to infer more precise regex match types by Michael0x2a · Pull Request #7803 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Add plugin to infer more precise regex match types #7803

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix test
10000
  • Loading branch information
97littleleaf11 committed Jan 5, 2022
commit 3b38dc9295433e6357b8b2e5669278edfba5b768
56 changes: 28 additions & 28 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -1598,18 +1598,18 @@ if match2:
reveal_type(match2["n1"])
reveal_type(match2["n2"])
[out]
_testRegexPluginBasicCase.py:8: note: Revealed type is 'Tuple[Union[builtins.str*, None], builtins.str*]'
_testRegexPluginBasicCase.py:9: note: Revealed type is 'Tuple[builtins.str*, builtins.str*]'
_testRegexPluginBasicCase.py:10: note: Revealed type is 'builtins.str*'
_testRegexPluginBasicCase.py:11: note: Revealed type is 'Union[builtins.str*, None]'
_testRegexPluginBasicCase.py:12: note: Revealed type is 'builtins.str*'
_testRegexPluginBasicCase.py:13: note: Revealed type is 'Tuple[builtins.str*, Union[builtins.str*, None], builtins.str*]'
_testRegexPluginBasicCase.py:18: note: Revealed type is 'Tuple[Union[builtins.bytes*, None], builtins.bytes*]'
_testRegexPluginBasicCase.py:19: note: Revealed type is 'builtins.bytes*'
_testRegexPluginBasicCase.py:20: note: Revealed type is 'Union[builtins.bytes*, None]'
_testRegexPluginBasicCase.py:21: note: Revealed type is 'builtins.bytes*'
_testRegexPluginBasicCase.py:22: note: Revealed type is 'Union[builtins.bytes*, None]'
_testRegexPluginBasicCase.py:23: note: Revealed type is 'builtins.bytes*'
_testRegexPluginBasicCase.py:8: note: Revealed type is "Tuple[Union[builtins.str*, None], builtins.str*]"
_testRegexPluginBasicCase.py:9: note: Revealed type is "Tuple[builtins.str*, builtins.str*]"
_testRegexPluginBasicCase.py:10: note: Revealed type is "builtins.str*"
_testRegexPluginBasicCase.py:11: note: Revealed type is "Union[builtins.str*, None]"
_testRegexPluginBasicCase.py:12: note: Revealed type is "builtins.str*"
_testRegexPluginBasicCase.py:13: note: Revealed type is "Tuple[builtins.str*, Union[builtins.str*, None], builtins.str*]"
_testRegexPluginBasicCase.py:18: note: Revealed type is "Tuple[Union[builtins.bytes*, None], builtins.bytes*]"
_testRegexPluginBasicCase.py:19: note: Revealed type is "builtins.bytes*"
_testRegexPluginBasicCase.py:20: note: Revealed type is "Union[builtins.bytes*, None]"
_testRegexPluginBasicCase.py:21: note: Revealed type is "builtins.bytes*"
_testRegexPluginBasicCase.py:22: note: Revealed type is "Union[builtins.bytes*, None]"
_testRegexPluginBasicCase.py:23: note: Revealed type is "builtins.bytes*"

[case testRegexPluginNoFinal]
# mypy: strict-optional
Expand All @@ -1622,8 +1622,8 @@ if match:
reveal_type(match.groups())
reveal_type(match[1])
[out]
_testRegexPluginNoFinal.py:8: note: Revealed type is 'typing.Sequence[builtins.str*]'
_testRegexPluginNoFinal.py:9: note: Revealed type is 'builtins.str*'
_testRegexPluginNoFinal.py:8: note: Revealed type is "builtins.tuple[Union[builtins.str*, Any], ...]"
_testRegexPluginNoFinal.py:9: note: Revealed type is "Union[builtins.str*, Any]"

[case testRegexPluginErrors]
# mypy: strict-optional
Expand Down Expand Up @@ -1658,12 +1658,12 @@ if match:
reveal_type(match[2])
reveal_type(match.group(0, 1, 2))
[out]
_testRegexPluginDirectMethods.py:7: note: Revealed type is 'Tuple[Union[builtins.str*, None], builtins.str*]'
_testRegexPluginDirectMethods.py:8: note: Revealed type is 'Tuple[builtins.str*, builtins.str*]'
_testRegexPluginDirectMethods.py:9: note: Revealed type is 'builtins.str*'
_testRegexPluginDirectMethods.py:10: note: Revealed type is 'Union[builtins.str*, None]'
_testRegexPluginDirectMethods.py:11: note: Revealed type is 'builtins.str*'
_testRegexPluginDirectMethods.py:12: note: Revealed type is 'Tuple[builtins.str*, Union[builtins.str*, None], builtins.str*]'
_testRegexPluginDirectMethods.py:7: note: Revealed type is "Tuple[Union[builtins.str*, None], builtins.str*]"
_testRegexPluginDirectMethods.py:8: note: Revealed type is "Tuple[builtins.str*, builtins.str*]"
_testRegexPluginDirectMethods.py:9: note: Revealed type is "builtins.str*"
_testRegexPluginDirectMethods.py:10: note: Revealed type is "Union[builtins.str*, None]"
_testRegexPluginDirectMethods.py:11: note: Revealed type is "builtins.str*"
_testRegexPluginDirectMethods.py:12: note: Revealed type is "Tuple[builtins.str*, Union[builtins.str*, None], builtins.str*]"

[case testRegexPluginUnknownArg]
# mypy: strict-optional
Expand Down Expand Up @@ -1692,13 +1692,13 @@ if match2:
match2["bad"]
match2[5]
[out]
_testRegexPluginUnknownArg.py:11: note: Revealed type is 'Tuple[Union[builtins.str*, None], builtins.str*, Union[builtins.str*, None], builtins.str*]'
_testRegexPluginUnknownArg.py:12: note: Revealed type is 'Union[builtins.str*, None]'
_testRegexPluginUnknownArg.py:13: note: Revealed type is 'Union[builtins.str*, None]'
_testRegexPluginUnknownArg.py:14: note: Revealed type is 'Tuple[builtins.str*, Union[builtins.str*, None], Union[builtins.str*, None]]'
_testRegexPluginUnknownArg.py:20: note: Revealed type is 'Tuple[builtins.str*, builtins.str*]'
_testRegexPluginUnknownArg.py:21: note: Revealed type is 'builtins.str*'
_testRegexPluginUnknownArg.py:22: note: Revealed type is 'builtins.str*'
_testRegexPluginUnknownArg.py:23: note: Revealed type is 'Tuple[builtins.str*, builtins.str*, builtins.str*]'
_testRegexPluginUnknownArg.py:11: note: Revealed type is "Tuple[Union[builtins.str*, None], builtins.str*, Union[builtins.str*, None], builtins.str*]"
_testRegexPluginUnknownArg.py:12: note: Revealed type is "Union[builtins.str*, None]"
_testRegexPluginUnknownArg.py:13: note: Revealed type is "Union[builtins.str*, None]"
_testRegexPluginUnknownArg.py:14: note: Revealed type is "Tuple[builtins.str*, Union[builtins.str*, None], Union[builtins.str*, None]]"
_testRegexPluginUnknownArg.py:20: note: Revealed type is "Tuple[builtins.str*, builtins.str*]"
_testRegexPluginUnknownArg.py:21: note: Revealed type is "builtins.str*"
_testRegexPluginUnknownArg.py:22: note: Revealed type is "builtins.str*"
_testRegexPluginUnknownArg.py:23: note: Revealed type is "Tuple[builtins.str*, builtins.str*, builtins.str*]"
_testRegexPluginUnknownArg.py:24: error: Regex does not contain group named 'bad'
_testRegexPluginUnknownArg.py:25: error: Regex has 3 total groups, given group number 5 is too big
0