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

Add generic alias test cases #4239

Merged
merged 1 commit into from
Apr 10, 2021
Merged

Add generic alias test cases #4239

merged 1 commit into from
Apr 10, 2021

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Mar 16, 2021

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

Add new test cases for generic_alias to make validating any updates a bit easier.
At the moment, some errors are still undetected that should be recognized.

Related
#4206
pylint-dev/astroid#921

Type of Changes

Type
🐛 Bug fix
✨ New feature

@cdce8p
Copy link
Member Author

cdce8p commented Mar 16, 2021

These are the current non-detected errors, no false positives.

pytest tests/test_functional.py -k generic_alias

Python 3.8

test_functional[generic_alias_typing]
E       Expected in testdata:
E         66: unsubscriptable-object  # typing.ByteString[int]
E         67: unsubscriptable-object  # typing.Hashable[int]
E         68: unsubscriptable-object  # typing.Sized[int]
E        125: unsubscriptable-object  # var_bytestring2: typing.ByteString[int]
E        126: unsubscriptable-object  # var_hashable2: typing.Hashable[int]
E        127: unsubscriptable-object  # var_sized2: typing.Sized[int]

test_functional[generic_alias_postponed_evaluation_py37]
E       Expected in testdata:
E         67: unsubscriptable-object  # re.Pattern[str]
E         68: unsubscriptable-object  # re.Match[str]
E         85: abstract-method  # Derived -> Iterable
E         88: abstract-method  # Derived -> Collection
E        112: abstract-method  # Derived -> Sized, Iterable
E        114: abstract-method  # Derived -> Multiple

test_functional[generic_alias_collections_py37]
E       Expected in testdata:
E         62: unsubscriptable-object  # re.Pattern[str]
E         63: unsubscriptable-object  # re.Match[str]
E         80: abstract-method  # Derived -> Iterable
E         83: abstract-method  # Derived -> Collection
E        107: abstract-method  # Derived -> Sized, Iterable
E        109: abstract-method  # Derived -> Multiple
E        122: unsubscriptable-object  # var_pattern: re.Pattern[int]

Python 3.9

test_functional[generic_alias_typing]
E       Expected in testdata:
E         66: unsubscriptable-object  # typing.ByteString[int]
E         67: unsubscriptable-object  # typing.Hashable[int]
E         68: unsubscriptable-object  # typing.Sized[int]
E        125: unsubscriptable-object  # var_bytestring2: typing.ByteString[int]
E        126: unsubscriptable-object  # var_hashable2: typing.Hashable[int]
E        127: unsubscriptable-object  # var_sized2: typing.Sized[int]

test_functional[generic_alias_collections]
E       Expected in testdata:
E         77: abstract-method  # Derived -> Iterable
E         80: abstract-method  # Derived -> Collection
E        104: abstract-method  # Derived -> Sized, Iterable
E        106: abstract-method  # Derived -> Multiple

@Pierre-Sassoulas
Copy link
Member

Very nice ! We clearly lacked tests for python 3.9.

@cdce8p
Copy link
Member Author

cdce8p commented Mar 16, 2021

It isn't as bad as it might seem! TBH it's a small miracle that there aren't more.

I frequently get confused what works in which version and in what setting (assignment, type annotation, with or without postponed evaluation). These tests should help with that and make it at least a bit easier. Always assuming that there isn't a bug in there as well 😅

This was one of the reasons I started working on the pylint support. If pylint is able to detect the errors, it should help a lot of devs who use typing, especially until 3.10 is the default.

@cdce8p cdce8p mentioned this pull request Mar 19, 2021
2 tasks
@hippo91
Copy link
Contributor

hippo91 commented Mar 21, 2021

@cdce8p very nice job! It is a great help for setting up astroid's typing and collection brain!

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component High effort 🏋 Difficult solution or problem to solve Work in progress labels Mar 24, 2021
@cdce8p cdce8p added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Apr 9, 2021
@cdce8p cdce8p added this to the 2.7.5 milestone Apr 10, 2021
@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.594% when pulling f7e6850 on cdce8p:generic-alias into 078ebea on PyCQA:master.

@cdce8p cdce8p marked this pull request as ready for review April 10, 2021 15:10
@cdce8p cdce8p removed Needs astroid update Needs an astroid update (probably a release too) before being mergable Work in progress labels Apr 10, 2021
@cdce8p
Copy link
Member Author

cdce8p commented Apr 10, 2021

All tests pass, finally!
pytest -m acceptance -k "test_libmodule[typing.py]" works as well.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is VERY satisfying. Wow 😄

@cdce8p cdce8p merged commit 4f0dc55 into pylint-dev:master Apr 10, 2021
@cdce8p cdce8p deleted the generic-alias branch April 10, 2021 15:14
@cdce8p
Copy link
Member Author

cdce8p commented Apr 10, 2021

🎉 🥳

@hippo91
Copy link
Contributor

hippo91 commented Apr 10, 2021

Very nice job @cdce8p ! Congrats!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component High effort 🏋 Difficult solution or problem to solve
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants