Skip to content

Narrow scope of various pylint inline disables#15364

Merged
balloob merged 2 commits intohome-assistant:devfrom
scop:narrow-pylint
Oct 10, 2018
Merged

Narrow scope of various pylint inline disables#15364
balloob merged 2 commits intohome-assistant:devfrom
scop:narrow-pylint

Conversation

@scop
Copy link
Copy Markdown
Member

@scop scop commented Jul 8, 2018

Description:

Narrow scope of various pylint inline disables. Mainly top-level ones, but some semi-random ones as well.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

@scop scop requested review from a team, amelchio, dgomes and rytilahti as code owners July 8, 2018 18:01
@ghost ghost added the in progress label Jul 8, 2018
Comment thread homeassistant/components/apcupsd.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not a big fan of in-line comment because deleting a line is way faster than marking the comment and then deleting. Also, it requires more skills with sed than if the comment is on it's own line.

Also, I see no real benefit of disabling an import-error with every import than on the top level once for all imports. We can't recover from the error in the code anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Having it on the same line is different in functionality -- same line affects that line, previous line affects that entire lexical scope. I think that should override personal preferences. And I don't quite agree that the speed of deletion or ease of sed usage should be a consideration here.

Disabling all import errors at top level once doesn't seem useful to me -- if that's what desired, then the same effect can be achieved by just disabling the error globally in pylintrc. But I don't think that's a good idea.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having it on the same line is different in functionality -- same line affects that line, previous line affects that entire lexical scope. I think that should override personal preferences.

If you have only one try-except block somewhere then it doesn't matter if disable broad-except at the beginning of block or inside the block itself (Ok, fixing it would be the way to go). For the tests the scoping is much more sophisticated because it's needed and make sense.

And I don't quite agree that the speed of deletion or ease of sed usage should be a consideration here.

Well, it should as we disable pylint at somewhere around 500 to 1000 places. There are still left-over from the last cleaning round and new entries are sneaking in from time to time which we need to remove.

Disabling all import errors at top level once doesn't seem useful to me -- if that's what desired, then the same effect can be achieved by just disabling the error globally in pylintrc. But I don't think that's a good idea.

Disabling something like import-error for a file or globally are two different shoes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Even if one can put broad-except disabling inside the try, I don't think one should, because that makes it inconsistent with a lot of other cases where such tricks are not available without undesired effects wrt scoping. (Not that I agree with it, but that inconsistency adds variability to the sed use case you mention, thus also making that harder.)

For the sed use case and acceptability of file-level import-error, I'm afraid we just have to agree to disagree. Anyway just two final data points:

For the sed use case, one should also consider lines where there are multiple symbols disabled on one line, as well as addressing possibly similar flake8 noqa comments as the pylint ones being removed. So in the big picture, being able to remove a line vs edit it doesn't really matter, more investigation/work is needed anyway. And I don't think sed is a proper tool for that job.

Top level disable=import-error in a file is a blanket permission for other bad imports to sneak into that file in addition to the ones it was originally added there for. The disable might be added there because there is a problem in CI with some imports, but the top level one may hide and let other ones through that blow up in user systems at runtime.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like that httplib should be a requirement for the platform.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

librouteros is a platform requirement and doesn't seem to be disabled.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in #15386

Comment thread homeassistant/components/eufy.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a platform requirement and doesn't seem to be disabled.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in #15386

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change will no longer cover bme680.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

True, but covering it does not appear to be necessary for the pylint tests to pass.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That looks weird.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's the least intrusive way to achieve the desired effect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Separating with two spaces from the statement looks like enough and aligning with the next comment seems unnecessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That looks weird too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's the least intrusive way to achieve the desired effect. Keeping it all on same line would require additional noqa comment for flake8.

@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 21, 2018

I'm fine with narrowing the scopes. I think import-error is probably fine at the top of the file, as it only happens with requirements that fail to install on every platform (like RPi specific DHT sensor lib).

Merge conflict and PyLint failed on this PR. After that it can be merged.

@balloob
Copy link
Copy Markdown
Member

balloob commented Oct 9, 2018

We should resolve the conflicts or close this PR.

@ghost ghost assigned scop Oct 9, 2018
@scop
Copy link
Copy Markdown
Member Author

scop commented Oct 9, 2018

Sorry, missed the review. Conflicts fixed and rebased.

@balloob balloob merged commit 707b7c2 into home-assistant:dev Oct 10, 2018
@ghost ghost removed the in progress label Oct 10, 2018
@scop scop deleted the narrow-pylint branch October 11, 2018 06:12
@balloob balloob mentioned this pull request Oct 26, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants