wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

Similar blocks of code found in 4 locations. Consider refactoring.
Open

    def test_with_h4_and_h2_sections(self):
        """Test for text having h4 and h2 sections."""
        text = ('text\n\n'
                '====title====\n'
                '==title 2==\n'
Severity: Major
Found in tests/textlib_tests.py and 3 other locations - About 1 hr to fix
tests/textlib_tests.py on lines 1594..1605
tests/textlib_tests.py on lines 1621..1636
tests/textlib_tests.py on lines 1666..1676

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 46.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function __init__ has 11 arguments (exceeds 7 allowed). Consider refactoring.
Open

    def __init__(self, lat: float, lon: float, alt: float | None = None,
Severity: Major
Found in pywikibot/_wbtypes.py - About 1 hr to fix

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        def _handle_mysqlquery(self, value: str) -> HANDLER_GEN_TYPE:
            """Handle `-mysqlquery` argument."""
            if not value:
                value = pywikibot.input('Mysql query string:')
            return MySQLPageGenerator(value, site=self.site)
    Severity: Major
    Found in pywikibot/pagegenerators/_factory.py and 3 other locations - About 1 hr to fix
    pywikibot/pagegenerators/_factory.py on lines 509..513
    pywikibot/pagegenerators/_factory.py on lines 623..627
    pywikibot/pagegenerators/_factory.py on lines 900..904

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 46.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        def test_with_comments(self):
            """Test section headers surrounded by comments."""
            text = ('text\n\n'
                    '<!--\n multiline comment\n-->== title ==\n'
                    'content\n\n'
    Severity: Major
    Found in tests/textlib_tests.py and 3 other locations - About 1 hr to fix
    tests/textlib_tests.py on lines 1594..1605
    tests/textlib_tests.py on lines 1608..1618
    tests/textlib_tests.py on lines 1666..1676

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 46.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        if missing_parameters:
            messages.append('Missing parameter{s} "{params}".'
                            .format(s='s' if len(missing_parameters) > 1 else '',
                                    params='", "'.join(missing_parameters)))
    Severity: Major
    Found in pywikibot/bot.py and 2 other locations - About 1 hr to fix
    pywikibot/bot.py on lines 931..934
    pywikibot/bot.py on lines 935..939

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 46.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        def test_old_version_sites(self):
            """Test detection of old MediaWiki sites."""
            for url in self.old_version_sites:
                with self.subTest(url=urlparse(url).netloc):
                    self.assertNoSite(url)
    Severity: Major
    Found in tests/site_detect_tests.py and 3 other locations - About 1 hr to fix
    tests/site_detect_tests.py on lines 106..110
    tests/site_detect_tests.py on lines 118..122
    tests/site_detect_tests.py on lines 130..134

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 46.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function parse has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

    def parse(argv: Sequence[str],
              generator_factory: pagegenerators.GeneratorFactory
              ) -> dict[str, bool | str]:
        """Parses our arguments and provide a dictionary with their values.
    
    
    Severity: Minor
    Found in scripts/add_text.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function treat_page has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def treat_page(self) -> None:
            """Process one page from the generator."""
            if self.opt.undelete:
                self.current_page.undelete(self.summary)
                self.counter['undelete'] += 1
    Severity: Minor
    Found in scripts/delete.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_dump_name has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def get_dump_name(db_name, typ, dumpdate):
            """Check if dump file exists locally in a Toolforge server."""
            db_path = f'/public/dumps/public/{db_name}/'
            if os.path.isdir(db_path):
                dump_filepath_template = (
    Severity: Minor
    Found in scripts/download_dump.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function treat_disamb_only has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def treat_disamb_only(self, ref_page, disamb_page) -> str:
            """Resolve the links to disamb_page but don't look for its redirects.
    
            :param disamb_page: the disambiguation page or redirect we don't want
                anything to link to
    Severity: Minor
    Found in scripts/solve_disambiguation.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function addReferences has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def addReferences(self, oldText) -> str:
            """Add a references tag into an existing section where it fits into.
    
            If there is no such section, creates a new section containing
            the references tag. Also repair malformed references tags.
    Severity: Minor
    Found in scripts/noreferences.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function __iter__ has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def __iter__(self) -> Generator[pywikibot.Page]:
            """Yield pages."""
            # TODO: start yielding before all referring pages have been found
            refs = list(self.page.getReferences(with_template_inclusion=False,
                                                namespaces=0 if self.main_only
    Severity: Minor
    Found in scripts/solve_disambiguation.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function run has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def run(self) -> None:
            """Main function of CategoryGraphBot."""
            self.scan_level(self.cat, int(self.args.depth))
            # reduce too big graph
            if self.counter > 1000:
    Severity: Minor
    Found in scripts/category_graph.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function lacksReferences has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def lacksReferences(self, text) -> bool:
            """Check whether or not the page is lacking a references tag."""
            oldTextCleaned = textlib.removeDisabledParts(text)
            if self.referencesR.search(oldTextCleaned) \
               or self.referencesTagR.search(oldTextCleaned):
    Severity: Minor
    Found in scripts/noreferences.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function test_watchlist_revs has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def test_watchlist_revs(self):
            """Test the site.watchlist_revs() method."""
            mysite = self.get_site()
            wl = list(mysite.watchlist_revs(total=10))
            self.assertLessEqual(len(wl), 10)
    Severity: Minor
    Found in tests/site_generators_tests.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function daemonize has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

    def daemonize(close_fd: bool = True,
                  chdir: bool = True,
                  redirect_std: str | None = None) -> None:
        """Daemonize the current process.
    
    
    Severity: Minor
    Found in pywikibot/daemonize.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function handle has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def handle(self) -> Any:
            """Handle by either applying the new section or label."""
            if not self.replacer:
                raise ValueError('LinkChoice requires a replacer')
    
    
    Severity: Minor
    Found in pywikibot/bot_choice.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function create_diff has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def create_diff(self) -> Iterable[str]:
            """Generator of diff text for this hunk, without formatting.
    
            Check each line ends with line feed to prevent behaviour like
            :issue:`46395`
    Severity: Minor
    Found in pywikibot/diff.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _upload has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def _upload(self, ignore_warnings, report_success,
                    file_key=None, offset=0) -> bool:
            """Recursive Upload method.
    
            :param file_key: Reuses an already uploaded file using the
    Severity: Minor
    Found in pywikibot/site/_upload.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function translateMagicWords has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def translateMagicWords(self, text: str) -> str:
            """Use localized magic words."""
            # not wanted at ru
            # arz uses English stylish codes
            # no need to run on English wikis
    Severity: Minor
    Found in pywikibot/cosmetic_changes.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Severity
    Category
    Status
    Source
    Language