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 and fix rules (mostly 3.10 related) #78

Merged
merged 4 commits into from
Oct 21, 2021
Merged

Conversation

gousaiyang
Copy link
Contributor

@gousaiyang gousaiyang commented Oct 18, 2021

  • Add and fix rules (mostly 3.10 related).
  • types.NoneType, types.NotImplementedType and types.EllipsisType were available in Python 2, removed in Python 3.0 and reintroduced in 3.10 for typing purposes.
  • Update minimum version for some kwargs of functions in cgi and urllib.parse as they have security fix backported to 3.6.
  • Update some backport rules.
  • KWARGS_REQS is now a function taking the config parameter.
  • Add collections.UserDict to types that support dictionary union operator.
  • Remove dis opcode rules (e.g. dis.MATCH_KEYS). They are not accessible as attributes of the dis module, so these rules are invalid.
  • Fix locations where files are read in text mode without an explicitly specified encoding. EncodingWarning will appear when executing on Python 3.10 with PYTHONWARNDEFAULTENCODING=1.

- Add and fix rules (mostly 3.10 related).
- `types.NoneType`, `types.NotImplementedType` and `types.EllipsisType` were available in Python 2, removed in Python 3.0 and reintroduced in 3.10 for typing purposes.
- Update minimum version for some kwargs of functions in `cgi` and `urllib.parse` as they have security fix backported to 3.6.
- Update some backport rules.
- `KWARGS_REQS` is now a function taking the `config` parameter.
- Add `collections.UserDict` to types that support dictionary union operator.
- Remove `dis` opcode rules (e.g. `dis.MATCH_KEYS`). They are not accessible as attributes of the `dis` module, so these rules are invalid.
- Fix 3 locations where files are read in text mode without an explicitly specified encoding. [`EncodingWarning` will appear](https://docs.python.org/3/whatsnew/3.10.html#optional-encodingwarning-and-encoding-locale-option) when executing on Python 3.10 with `PYTHONWARNDEFAULTENCODING=1`.
@coveralls
Copy link

coveralls commented Oct 18, 2021

Coverage Status

Coverage increased (+0.007%) to 99.578% when pulling 7b2c41b on gousaiyang:rules310 into b070c99 on netromdk:dev.

@netromdk netromdk self-requested a review October 19, 2021 18:05
@netromdk netromdk self-assigned this Oct 19, 2021
Copy link
Owner

@netromdk netromdk left a comment

Choose a reason for hiding this comment

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

Thanks @gousaiyang. Always great changes from you! 👍

The only things that needs changing is that the encoding argument cannot be used with Python 2.7 those three places. I agree that for Python 3+ it should be used, though. One approach could be to add a custom open() in vermin/utility.py with arguments path, mode, and encoding. Then inside it it can just ignore passing encoding argument on to the built-in open() to be called internally.

It doesn't solve the issues for the config parser, though. A similar solution could be done with a local lambda/function.

- Fix more cases of open in text mode without encoding, using `open_wrapper` function which drops unsupported arguments on Python 2
- Add kwargs rules for the `open` function
@gousaiyang
Copy link
Contributor Author

I was wondering why this error wasn't caught by tests and CI. It turns out that:

  • In misc/actions/test.sh, test errors from Python 2.7 are suppressed by exit 0.
  • Although self-test will check vermin itself is 2.7+ and 3.0+, the open(encoding=...) kwargs rule was missing. I've just added related rules.

Actually I think a bunch of Python 2 vs 3 rules are missing here. I have bookmarked the following two pages, but haven't really have time to (manually) convert them into rules:

@netromdk
Copy link
Owner

Thanks a lot! 🚀

I'm going to merge your fixes and have a look at the suppressed test errors and go through missing rules from v2 to v3.

@netromdk netromdk merged commit ea260d9 into netromdk:dev Oct 21, 2021
@gousaiyang gousaiyang deleted the rules310 branch October 21, 2021 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants