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

The duplicate-code (R0801) can't be disabled #214

Closed
pylint-bot opened this issue Apr 25, 2014 · 52 comments · Fixed by #5446
Closed

The duplicate-code (R0801) can't be disabled #214

pylint-bot opened this issue Apr 25, 2014 · 52 comments · Fixed by #5446
Labels
Enhancement ✨ Improvement to a component Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors High priority Issue with more than 10 reactions
Milestone

Comments

@pylint-bot
Copy link

Originally reported by: Anonymous


It's seems like it's not possible to disable the duplicate code check on portions of a file. Looking at the source, I can see why as it's not a trivial thing to do (if you want to maintain the same scope semantics as other #pylint:enable/disable comments. This would be nice to have though (or I guess I could just cleanup my duplicate code).


@pylint-bot
Copy link
Author

Original comment by Radek Holý (BitBucket: PyDeq, GitHub: @PyDeQ?):


Pylint marks even import blocks as duplicates. In my case, it is:

#!python
import contextlib
import io
import itertools
import os
import subprocess
import tempfile

I doubt it is possible to clean up/refactor the code to prevent this, thus it would be nice if it would ignore imports or if it would be possible to use the disable comment.

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


I've run into this today.

My project has several setup.py files, which of course look quite similar, but can't really share code.
I tried to # pylint:disable=duplicate-code just the line in question (setup()), but it did nothing.

I'll have to turn the checker off entirely I think.

@pylint-bot pylint-bot added the Enhancement ✨ Improvement to a component label Dec 9, 2015
@gaspaio
Copy link

gaspaio commented May 4, 2016

any news on this issue ?

@PCManticore
Copy link
Contributor

No one is currently working on this. This would be nice to have fixed, but unfortunately I didn't have time to look into it. A pull request would be appreciated though and would definitely move it forward.

@PCManticore PCManticore added this to the 1.6.0 milestone May 9, 2016
@PCManticore PCManticore modified the milestones: 2.1, 2.0 Jun 16, 2016
@PCManticore PCManticore modified the milestones: 3.0, 2.2 Jun 17, 2016
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue Jul 8, 2016
We can't disable it more fine-grained:
pylint-dev/pylint#214

I think for the shown duplicate (histroy in webkittab/webenginetab) it
makes no sense to refactor things as a Mixin...
@moylop260
Copy link
Contributor

@gaspaio
FYI I have created a fix in the following PR #1055
Could you check if It work for you?

heilaaks added a commit to heilaaks/snippy that referenced this issue Jul 30, 2017
The test code contain setup and teardown that are same for
two tests. Pylint complains about these two methods in two
modules. The setup and teardown are needed because they are
called by the test framework and cannot be removed.

It seems that pylint 1.7.2 has open fault that makes disabling
of the check in portion of the code not to work /1/.

It also seems that pylint 1.7.2 the ignore-comments and
ignore-docstrings do not seem to work as expected. Even
when the values should state that these are ignored, the
min-similarity had to be increased to 8 because there are
7 lines in these two referred methods.

The target is to get the warnings down to see changes
easily. This fix could be fixed later on by setting the
min-similarity to 4 and use the ignore docstring and
comment settings combined with the code tag to ignore
the duplicated code.

/1/ pylint-dev/pylint#214

Signed-off-by: Heikki Laaksonen <laaksonen.heikki.j@gmail.com>
@YifeiZuo01
Copy link

YifeiZuo01 commented Oct 4, 2017

Is this related to duplicate-except? it cannot be disabled either.

sorry, Seems it is able to be disabled.

bmw pushed a commit to certbot/certbot that referenced this issue Dec 4, 2017
…ce (#5202)

Class inheritance based approach to distro specific overrides.

How it works:
The certbot-apache plugin entrypoint has been changed to entrypoint.ENTRYPOINT which is a variable containing appropriate override class for system, if available.

Override classes register themselves using decorator override.register() which takes a list of distribution fingerprints (ID & LIKE variables in /etc/os-release, or platform.linux_distribution() as a fallback). These end up as keys in dict override.OVERRIDE_CLASSES and values for the keys are references to the class that called the decorator, hence allowing self-registration of override classes when they are imported. The only file importing these override classes is entrypoint.py, so adding new override classes would need only one import in addition to the actual override class file.

Generic changes:

    Parser initialization has been moved to separate class method, allowing easy override where needed.
    Cleaned up configurator.py a bit, and moved some helper functions to newly created apache_util.py
    Split Debian specific code from configurator.py to debian_override.py
    Changed define_cmd to apache_cmd because the parameters are for every distribution supporting this behavior, and we're able to use the value to build the additional configuration dump commands.
    Moved add_parser_mod() from configurator to parser add_mod()
    Added two new configuration dump parsing methods to update_runtime_variables() in parser: update_includes() and update_modules().
    Changed init_modules() in parser to accommodate the changes above. (ie. don't throw existing self.modules out).
    Moved OS based constants to their respective override classes.
    Refactored configurator class discovery in tests to help easier test case creation using distribution based override configurator class.
    tests.util.get_apache_configurator() now takes keyword argument os_info which is string of the desired mock OS fingerprint response that's used for picking the right override class.

This PR includes two major generic additions that should vastly improve our parsing accuracy and quality:

    Includes are parsed from config dump from httpd binary. This is mandatory for some distributions (Like OpenSUSE) to get visibility over the whole configuration tree because of Include statements passed on in command line, and not via root httpd.conf file.
    Modules are parsed from config dump from httpd binary. This lets us jump into correct IfModule directives if for some reason we have missed the module availability (because of one being included on command line or such).

Distribution specific changes
Because of the generic changes, there are two distributions (or distribution families) that do not provide such functionality, so it had to be overridden in their respective override files. These distributions are:

    CentOS, because it deliberately limits httpd binary stdout using SELinux as a feature. We are doing opportunistic config dumps here however, in case SELinux enforcing is off.
    Gentoo, because it does not provide a way to invoke httpd with command line parsed from its specific configuration file. Gentoo relies heavily on Define statements that are passed over from APACHE2_OPTS variable /etc/conf.d/apache2 file and most of the configuration in root Apache configuration are dependent on these values.

Debian

    Moved the Debian specific parts from configurator.py to Debian specific override.

CentOS

    Parsing of /etc/sysconfig/httpd file for additional Define statements. This could hold other parameters too, but parsing everything off it would require a full Apache lexer. For CLI parameters, I think Defines are the most common ones. This is done in addition of opportunistic parsing of httpd binary config dump.
    Added CentOS default Apache configuration tree for realistic test cases.

Gentoo

    Parsing Defines from /etc/conf.d/apache2 variable APACHE2_OPTS, which holds additional Define statements to enable certain functionalities, enabling parts of the configuration in the Apache2 DOM. This is done instead of trying to parse httpd binary configuration dumps.
    Added default Apache configuration from Gentoo to testdata, including /etc/conf.d/apache2 file for realistic test cases.


* Distribution specific override functionality based on class inheritance

* Need to patch get_systemd_os_like to as travis has proper os-release

* Added pydoc

* Move parser initialization to a method and fix Python 3 __new__ errors

* Parser changes to parse HTTPD config

* Try to get modules and includes from httpd process for better visibility over the configuration

* Had to disable duplicate-code because of test setup (pylint-dev/pylint/issues/214)

* CentOS tests and linter fixes

* Gentoo override, tests and linter fixes

* Mock the process call in all the tests that require it

* Fix CentOS test mock

* Restore reseting modules list functionality for cleanup

* Move OS fingerprinting and constant mocks to parent class

* Fixes requested in review

* New entrypoint structure and started moving OS constants to override classes

* OS constants move continued, test and linter fixes

* Removed dead code

* Apache compatibility test changest to reflect OS constant restructure

* Test fix

* Requested changes

* Moved Debian specific tests to own test file

* Removed decorator based override class registration in favor of entrypoint dict

* Fix for update_includes for some versions of Augeas

* Take fedora fix into account in tests

* Review fixes
@PCManticore PCManticore removed this from the 3.0 milestone Apr 25, 2018
rmoch added a commit to openfun/richie that referenced this issue May 3, 2018
Revove this warning, at least for now, because it not disablable on-line
and we do not want to factorize reported code this early
pylint-dev/pylint#214
@DanielNoord
Copy link
Collaborator

@dothebart Thanks for the reminder, @Pierre-Sassoulas got to work quickly and we just merged the proposed PR in main. We're trying to release ASAP, so expect this to be available somewhere in the coming days/weeks 😄

@dothebart
Copy link

This is so great to hear, and I know how pleasing it is to close a Bug / Feature request after such a long time ;-)

@Vichoko
Copy link

Vichoko commented Mar 4, 2022

Where will be the usage of this feature documented?

@dothebart
Copy link

some of these took similar long... https://github.com/collectd/collectd/pulls?q=is%3Apr+author%3Adothebart+is%3Aclosed

@DanielNoord
Copy link
Collaborator

DanielNoord commented Mar 4, 2022

Where will be the usage of this feature documented?

This works the same as any other disable in pylint. So if you want to disable the message for a particular line you can add:
pylint: disable=duplicate-code. I'd refer to this page in the documentation which explains this a little more!

simonrainerson added a commit to goodbyekansas/nedryland that referenced this issue Mar 25, 2022
Default settings increased, they are too strict and it can't be ignored
with comments: pylint-dev/pylint#214 this is fixed
in 2.13.0.
abbec pushed a commit to goodbyekansas/nedryland that referenced this issue Mar 25, 2022
Default settings increased, they are too strict and it can't be ignored
with comments: pylint-dev/pylint#214 this is fixed
in 2.13.0.
windoverwater added a commit to TrustTheVote-Project/VoteTrackerPlus that referenced this issue Apr 12, 2022
@famura
Copy link

famura commented May 13, 2022

I am getting [E0011(unrecognized-inline-option), ] Unrecognized file option 'ignore' from pylint 2.13.8 when adding # pylint: ignore=duplicate-code on top of a file and/or a line of code. Am I missing something?

@JulienPalard
Copy link
Contributor

@famura Can you try # pylint: disable=duplicate-code instead?

@famura
Copy link

famura commented May 16, 2022

@JulienPalard your suggestion (+ me putting it on top of the file) made it work. The latter was necessary since pylint got triggered by the import statements, too.

Thank you.

@DanielNoord
Copy link
Collaborator

DanielNoord commented May 16, 2022

You might want to have a look at --ignore-imports: https://pylint.pycqa.org/en/latest/user_guide/configuration/all-options.html#ignore-imports

@duanyutong
Copy link

# pylint: disable=duplicate-code or # pylint: disable=R0801 isn't working for me when running pylint 2.15.5

@Pierre-Sassoulas
Copy link
Member

Could you add a reproducer and open a new bug issue @duanyutong, please ?

@Bengt
Copy link

Bengt commented Dec 11, 2022

I get flagged by R0801, when I have code like this in two files:

return_value_0,
return_value_1,
return_value_2,
return_value_3 = \
    my_function(
        parameter_0,
        parameter_1,
        parameter_2,
        parameter_3,
)

Note that while there are 10 lines in this example, it only contains a single statement, namely a single function call. Maybe R0801 should consider duplicate statements rather than duplicate lines?

@Pierre-Sassoulas
Copy link
Member

@Bengt I think it could be an option like --ignore-multiline-calls (like other similarities checker options https://pylint.pycqa.org/en/latest/user_guide/configuration/all-options.html#similarities-checker) could you open another issue please ?

sschwarzer added a commit to sschwarzer/ftputil that referenced this issue Feb 10, 2023
Increase the value to suppress the warning for common context
manager code.

I would have liked to disable the warning R0801 locally, but it
doesn't seem to be possible. See also
pylint-dev/pylint#214 .
qingchm added a commit to qingchm/aws-sam-cli that referenced this issue Feb 13, 2023
Since we cannot use # pylint: disable=duplicate-code according to pylint-dev/pylint#214, changing parameter name to remove duplication
qingchm added a commit to aws/aws-sam-cli that referenced this issue Feb 13, 2023
* Add sync state into all sync flows

* Pass in sync context instead of sync state

* Refactoring to move sync context to be with other contexts

* Update http_api_sync_flow.py

Since we cannot use # pylint: disable=duplicate-code according to pylint-dev/pylint#214, changing parameter name to remove duplication
zanderso added a commit to flutter/engine that referenced this issue May 23, 2023
This PR modifies the mac_host_engine build config to build the
FlutterEmbedder.framework for arm64, and adds a generator that creates a
fat framework containing both the intel and arm64 dylibs. The fat
framework is uploaded to the gcs bucket instead of the thin intel-only
one.

The script to create the lipo'd embedder framework is different enough
from the desktop framework to have a separate script, but this still
triggers the pylint duplicate-code check. Due to a bug in our version of
pylint (pylint-dev/pylint#214), it isn't
possible to disable per-file, so this PR also disables the check
globally.
Aciid added a commit to pvarki/docker-rasenmaeher-integration that referenced this issue Sep 29, 2023
@jenstroeger
Copy link

I’m a little unclear on how to disable the message for select occurrences, while keeping the option enabled in general. The docs don’t mention that detail either.

For example, suppose I have

************* Module foo.bar
path/to/foo/bar.py:1:0: R0801: Similar lines in 2 files
==foo.other.nip:[32:89]
==foo.bar:[37:97]

    a = b
    b = more()
    some_other_code()  (duplicate-code)

Adding a # pylint: disable=duplicate-code to lines 32 and 37 in both files, respectively, doesn’t work. How can I then silence the warning?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors High priority Issue with more than 10 reactions
Projects
None yet
Development

Successfully merging a pull request may close this issue.