-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
- 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`.
There was a problem hiding this 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
I was wondering why this error wasn't caught by tests and CI. It turns out that:
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:
|
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. |
types.NoneType
,types.NotImplementedType
andtypes.EllipsisType
were available in Python 2, removed in Python 3.0 and reintroduced in 3.10 for typing purposes.cgi
andurllib.parse
as they have security fix backported to 3.6.KWARGS_REQS
is now a function taking theconfig
parameter.collections.UserDict
to types that support dictionary union operator.dis
opcode rules (e.g.dis.MATCH_KEYS
). They are not accessible as attributes of thedis
module, so these rules are invalid.EncodingWarning
will appear when executing on Python 3.10 withPYTHONWARNDEFAULTENCODING=1
.