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 default_enabled option to optional message dict #7629

Merged
merged 3 commits into from
Oct 25, 2022

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Oct 16, 2022

Description

Add a new default_enabled option to make it easier to disable a specific message by default.
This is especially useful for extensions like the CodeStyle one. I'm not so sure if we should use it for regular checks though. The expectation I believe is that all of them are enabled by default. I.e. to disable one, we should move it to an extension first.

@cdce8p cdce8p added the Enhancement ✨ Improvement to a component label Oct 16, 2022
@cdce8p cdce8p added this to the 2.16.0 milestone Oct 16, 2022
@coveralls
Copy link

coveralls commented Oct 16, 2022

Pull Request Test Coverage Report for Build 3264705099

  • 5 of 5 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 95.35%

Totals Coverage Status
Change from base Build 3260581019: 0.001%
Covered Lines: 17141
Relevant Lines: 17977

💛 - Coveralls

@github-actions

This comment has been minimized.

@DanielNoord
Copy link
Collaborator

This feels like it fixes part of #3512 but not fully.

I'm -0,5 for adding any more complexity to enabling and disabling that doesn't immediately solve that issue. It just creates more to consider before we implement the system discussed there.

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.

I think it's a good idea, we definitely need an easy way to make a check optional (beside moving code to another directory and adding or removing code during registration, that's barbaric 😄). We need a better way but plugin maintainer also need a better way imo.

I would use a positive formulation for the option name to avoid a double negative (disabled = False => enabled = True), maybe default_enabled or enabled_by_default ?

pylint/lint/pylinter.py Outdated Show resolved Hide resolved
@cdce8p cdce8p changed the title Add default_disabled option to optional message dict Add default_enabled option to optional message dict Oct 17, 2022
Copy link
Member Author

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

I think it's a good idea, we definitely need an easy way to make a check optional (beside moving code to another directory and adding or removing code during registration, that's barbaric 😄). We need a better way but plugin maintainer also need a better way imo.

I think we should be careful when considering if a check should be disabled by default. It's much easier for new ones and extensions. However, I do believe there is at least the expectation that all default checks are also enabled.

That doesn't negate that having an easy option to do so would be useful IMO.

I would use a positive formulation for the option name to avoid a double negative (disabled = False => enabled = True), maybe default_enabled or enabled_by_default ?

Done

pylint/lint/pylinter.py Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

🤖 Effect of this PR on checked open source code: 🤖

Effect on django:
The following messages are no longer emitted:

  1. invalid-name:
    Attribute name "ALLOWED_HOSTS" doesn't conform to '[a-z_][a-z0-9_]{2,}$' pattern
    https://github.com/django/django/blob/37c5b8c07be104fd5288cd87f101e48cb7a40298/django/test/utils.py#L138
  2. invalid-name:
    Attribute name "DEBUG" doesn't conform to '[a-z_][a-z0-9_]{2,}$' pattern
    https://github.com/django/django/blob/37c5b8c07be104fd5288cd87f101e48cb7a40298/django/test/utils.py#L141
  3. invalid-name:
    Attribute name "EMAIL_BACKEND" doesn't conform to '[a-z_][a-z0-9_]{2,}$' pattern
    https://github.com/django/django/blob/37c5b8c07be104fd5288cd87f101e48cb7a40298/django/test/utils.py#L144
  4. invalid-name:
    Attribute name "MIGRATION_MODULES" doesn't conform to '[a-z_][a-z0-9_]{2,}$' pattern
    https://github.com/django/django/blob/37c5b8c07be104fd5288cd87f101e48cb7a40298/django/db/backends/base/creation.py#L72

Effect on pandas:
The following messages are now emitted:

  1. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.numpy_.PandasArray to pandas.core.indexes.base.Index
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/_testing/__init__.py#L300
  2. redefined-variable-type:
    Redefinition of expected type from .ndarray to pandas.core.arrays.period.PeriodArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/string_/test_string.py#L215
  3. redefined-variable-type:
    Redefinition of expected type from .ndarray to pandas.core.arrays.period.PeriodArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/string_/test_string.py#L256
  4. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.series.Series
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/floating/test_function.py#L21
  5. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.series.Series
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/floating/test_function.py#L36
  6. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.arrays.floating.FloatingArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/floating/test_arithmetic.py#L68
  7. redefined-variable-type:
    Redefinition of res type from pandas.core.arrays.period.PeriodArray to pandas.core.arrays.floating.FloatingArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/floating/test_construction.py#L142
  8. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.series.Series
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/integer/test_function.py#L20
  9. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.arrays.floating.FloatingArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/integer/test_arithmetic.py#L117
  10. redefined-variable-type:
    Redefinition of other type from pandas.core.arrays.period.PeriodArray to .ndarray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_comparison.py#L32
  11. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.series.Series
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_function.py#L21
  12. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.series.Series
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_function.py#L64
  13. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.series.Series
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_function.py#L125
  14. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.series.Series
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_ops.py#L11
  15. redefined-variable-type:
    Redefinition of result type from pandas.core.indexes.datetimes.DatetimeIndex to pandas.core.indexes.multi.MultiIndex
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/indexes/multi/test_reshape.py#L126
  16. redefined-variable-type:
    Redefinition of expected type from list to pandas.core.arrays.period.PeriodArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arithmetic/test_datetime64.py#L239
  17. redefined-variable-type:
    Redefinition of indexer type from pandas.core.indexes.numeric.Int64Index to pandas.core.indexes.datetimes.DatetimeIndex
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/core/algorithms.py#L1426
  18. redefined-variable-type:
    Redefinition of index type from pandas.core.indexes.base.Index to pandas.core.indexes.range.RangeIndex
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/core/series.py#L467
  19. invalid-name:
    Attribute name "y" doesn't conform to '[a-z_][a-z0-9_]{2,}$' pattern
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/reshape/test_pivot.py#L1772
  20. redefined-variable-type:
    Redefinition of columns type from pandas.core.indexes.base.Index to pandas.core.indexes.range.RangeIndex
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/core/internals/construction.py#L850
  21. redefined-variable-type:
    Redefinition of other type from pandas.core.arrays.period.PeriodArray to pandas.core.arrays.interval.IntervalArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/core/arrays/interval.py#L736
  22. redefined-variable-type:
    Redefinition of new_target type from pandas.core.indexes.base.Index to pandas.core.indexes.category.CategoricalIndex
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/core/indexes/category.py#L442

The following messages are no longer emitted:

  1. redefined-variable-type:
    Redefinition of result type from pandas.core.indexes.base.Index to pandas.core.indexes.multi.MultiIndex
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/indexes/multi/test_reshape.py#L126
  2. no-member:
    Instance of 'Index' has no 'day_name' member
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/indexes/datetimes/test_misc.py#L249
  3. no-member:
    Instance of 'Index' has no 'month_name' member
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/indexes/datetimes/test_misc.py#L274
  4. redefined-variable-type:
    Redefinition of dti type from pandas.core.indexes.datetimes.DatetimeIndex to pandas.core.indexes.base.Index
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/indexes/datetimes/test_misc.py#L248
  5. redefined-variable-type:
    Redefinition of idx1 type from pandas.core.indexes.period.PeriodIndex to pandas.core.indexes.base.Index
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/frame/methods/test_set_index.py#L497
  6. invalid-unary-operand-type:
    bad operand type for unary -: IntervalArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/floating/test_arithmetic.py#L213
  7. invalid-unary-operand-type:
    bad operand type for unary +: IntervalArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/floating/test_arithmetic.py#L213
  8. invalid-unary-operand-type:
    bad operand type for unary -: IntervalArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/integer/test_arithmetic.py#L324
  9. invalid-unary-operand-type:
    bad operand type for unary +: IntervalArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/integer/test_arithmetic.py#L324
  10. redefined-variable-type:
    Redefinition of expected type from pandas.core.series.Series to pandas.core.arrays.period.PeriodArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_function.py#L28
  11. invalid-unary-operand-type:
    bad operand type for unary ~: IntervalArray
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_ops.py#L9
  12. redefined-variable-type:
    Redefinition of expected type from pandas.core.series.Series to pandas.core.frame.DataFrame
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_ops.py#L17
  13. redefined-variable-type:
    Redefinition of other type from .ndarray to pandas.core.series.Series
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/arrays/boolean/test_comparison.py#L34
  14. redefined-variable-type:
    Redefinition of expected type from pandas.core.arrays.period.PeriodArray to pandas.core.indexes.base.Index
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/_testing/__init__.py#L300
  15. invalid-name:
    Attribute name "y" doesn't conform to '[a-z_][a-z0-9_]{2,}$' pattern
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/tests/generic/test_frame.py#L136
  16. redefined-variable-type:
    Redefinition of indexer type from pandas.core.indexes.numeric.Int64Index to pandas.core.indexes.base.Index
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/core/algorithms.py#L1412
  17. redefined-variable-type:
    Redefinition of new_target type from pandas.core.indexes.category.CategoricalIndex to pandas.core.indexes.base.Index
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/core/indexes/category.py#L455
  18. redefined-variable-type:
    Redefinition of columns type from pandas.core.indexes.range.RangeIndex to pandas.core.indexes.base.Index
    https://github.com/pandas-dev/pandas/blob/8608ac919fbad7fb656d6b9bc5ddf7f09ae7a430/pandas/core/internals/construction.py#L860

Effect on sentry:
The following messages are now emitted:

  1. redefined-variable-type:
    Redefinition of orgs type from list to dict
    https://github.com/getsentry/sentry/blob/9540056fc968f5b3fd0fe5a951a57fa73ce56efb/src/sentry/api/endpoints/relay/project_configs.py#L242

This comment was generated for commit d0ced17

@Pierre-Sassoulas
Copy link
Member

I think we should be careful when considering if a check should be disabled by default.

Sure, definitely something that will help for #3512 but should not change much after that.

@DanielNoord
Copy link
Collaborator

But don't want we want to plan out that PR and then work based on that design? We're not sure how this would interact with the extending/disabling that is proposed in that issue.

@Pierre-Sassoulas
Copy link
Member

I'm pretty sure a boolean flag on each message is the simplest / most extensible / scalable way to disable / enable messages. Actually I've wanted to do that for a long time, (thank you @cdce8p). But I'm open to another design if you have one Daniel

@DanielNoord
Copy link
Collaborator

I don't have a design for the final implementation, but I think it makes sense to consider where the information is needed. If we go down a templating route it might make more sense to store such information in a default template for example. I'm just trying to avoid double work later on.
I'm not saying that this isn't the right approach, it might very well be as it seems reasonable to me, but I think future implications should at least be considered. The various flags that could be part of option dicts also caused headaches when migrating to argparse.

@Pierre-Sassoulas
Copy link
Member

Could you explain what you meant and the advantages of the template approach @DanielNoord ? I'm not sure about what it mean.

@DanielNoord
Copy link
Collaborator

Well just the whole discussion in that issue:
Do we want to create an extend-disable option?
Do we want to create shareable configuration templates? If so, how should these two interact.

The implementation of those questions might be more complicated if we add more stuff right now.

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Oct 24, 2022

Ha thank you I get it know. I think this MR won't impact the shareable template configuration, this is only a way for pylint to internally change our default values easily. I think we should not expose the default_enabled option in configuration templates.

@cdce8p
Copy link
Member Author

cdce8p commented Oct 24, 2022

Ha thank you I get it know. I think this MR won't impact the shareable template configuration, this is only a way for pylint to internally change our default values easily. I think we should not expose the default_enabled option in configuration templates.

I agree. The way I think about it, there are / will be multiple layers:

  1. The default configuration (default_enabled being part of it)
  2. Template / profiles which can overwrite the default configuration in a predefined manner. Similar to isort profiles.
  3. Custom overwrites by the user.

Since default_enabled would be part of the default config, it shouldn't impact profiles at all. Similar to the way profiles won't change message ids or descriptions.

@DanielNoord
Copy link
Collaborator

Yeah, but it might interact with how we implement extend-enable which in turn might depend on templating. If you both think this is fine please go ahead and merge, but I just wanted to point this might have unforeseen consequences for future implementations,

@Pierre-Sassoulas
Copy link
Member

I think the separation of default configuration / templated configuration / user overwrite will prevent most issue with this, I'll let you merge if you agree @cdce8p.

@cdce8p
Copy link
Member Author

cdce8p commented Oct 25, 2022

I think the separation of default configuration / templated configuration / user overwrite will prevent most issue with this, I'll let you merge if you agree @cdce8p.

I agree. It's good to be careful but I don't see an issue with default_enabled going forward. It just represents the lowest config level, i.e. the default configuration. Anything else will be on top of that.

@cdce8p cdce8p merged commit 8c7af1e into pylint-dev:main Oct 25, 2022
@cdce8p cdce8p deleted the add-default-disable-option branch October 25, 2022 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants