wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

Function check_soft_redirect has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

    def check_soft_redirect(self) -> None:
        """Check for soft-redirected categories."""
        cat = self.current_page
        i18n_param = {'oldcat': cat.title(as_link=True, textlink=True)}

Severity: Minor
Found in scripts/category_redirect.py - About 35 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_chunk_size has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

def get_chunk_size(match) -> int:
    """Get chunk size."""
    if not match:
        pywikibot.error('Chunk size parameter is not valid.')
        chunk_size = 0
Severity: Minor
Found in scripts/upload.py - About 35 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 __init__ has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

    def __init__(self, **kwargs) -> None:
        """Initializer."""
        super().__init__(**kwargs)
        if self.opt.delay < 0:
            d = min(15, max(5, int(self.opt.hours * 60)))
Severity: Minor
Found in scripts/clean_sandbox.py - About 35 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 load_config has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

    def load_config(self) -> None:
        """Load and validate archiver template."""
        pywikibot.info(
            f'Looking for: {{{{{self.tpl.title()}}}}} in {self.page}')

Severity: Minor
Found in scripts/archivebot.py - About 35 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_logevent has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

    def _test_logevent(self, logtype):
        """Test a single logtype entry."""
        logentry = self._get_logentry(logtype)
        self.assertIn(logtype, logentry.__class__.__name__.lower())
        self.assertEqual(logentry._expected_type, logtype)
Severity: Minor
Found in tests/logentries_tests.py - About 35 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_edit_claims has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

    def test_edit_claims(self):
        """Test addClaim and removeClaim editing."""
        wikidata_site = pywikibot.Site('beta', 'wikidata')

        # Create claim
Severity: Minor
Found in tests/file_tests.py - About 35 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 pagebacklinks has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

    def pagebacklinks(
        self,
        page: pywikibot.Page,
        *,
        follow_redirects: bool = False,
Severity: Minor
Found in pywikibot/site/_generators.py - About 35 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 __setitem__ has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

    def __setitem__(self, name, value):
        """Set option to enabled, disabled or neither."""
        if value is True:
            if self._site_set and name not in self._valid_enable:
                raise KeyError(f'Invalid name "{name}"')
Severity: Minor
Found in pywikibot/data/api/_optionset.py - About 35 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 __init__ has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

    def __init__(self, url: list[str] | str, *,
                 url_encoding=None,
                 description: str = '',
                 use_filename=None,
                 keep_filename: bool = False,
Severity: Minor
Found in pywikibot/specialbots/_upload.py - About 35 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 12 (exceeds 10 allowed). Consider refactoring.
Open

    def run(self) -> None:
        """Run the generator and store the results on the queue."""
        iterable = any(hasattr(self.generator, key)
                       for key in ('__iter__', '__getitem__'))
        if iterable and not self.args and not self.kwargs:
Severity: Minor
Found in pywikibot/tools/threading.py - About 35 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

Avoid too many return statements within this function.
Open

        return False
Severity: Major
Found in scripts/patrol.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            return (fam.name, code)  # text before : doesn't match any known prefix
    Severity: Major
    Found in pywikibot/page/_links.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return super().skip_page(page)
      Severity: Major
      Found in scripts/add_text.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return
        Severity: Major
        Found in scripts/category_redirect.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return False
          Severity: Major
          Found in scripts/revertbot.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return add_claims(isbn_data)
            Severity: Major
            Found in scripts/create_isbn_edition.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return None
              Severity: Major
              Found in scripts/category.py - About 30 mins to fix

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

                    @need_right('edit')
                    @need_extension('Flow')
                    @deprecated(since='9.4.0')
                    def restore_topic(self, page, reason):
                        """Restore a Flow topic.
                Severity: Major
                Found in pywikibot/site/_extensions.py and 7 other locations - About 30 mins to fix
                pywikibot/site/_extensions.py on lines 612..625
                pywikibot/site/_extensions.py on lines 627..640
                pywikibot/site/_extensions.py on lines 642..655
                pywikibot/site/_extensions.py on lines 697..710
                pywikibot/site/_extensions.py on lines 712..725
                pywikibot/site/_extensions.py on lines 727..740
                pywikibot/site/_extensions.py on lines 742..755

                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 40.

                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 8 locations. Consider refactoring.
                Open

                    @need_right('flow-delete')
                    @need_extension('Flow')
                    @deprecated(since='9.4.0')
                    def delete_post(self, post, reason):
                        """Delete a Flow post.
                Severity: Major
                Found in pywikibot/site/_extensions.py and 7 other locations - About 30 mins to fix
                pywikibot/site/_extensions.py on lines 612..625
                pywikibot/site/_extensions.py on lines 627..640
                pywikibot/site/_extensions.py on lines 642..655
                pywikibot/site/_extensions.py on lines 657..670
                pywikibot/site/_extensions.py on lines 712..725
                pywikibot/site/_extensions.py on lines 727..740
                pywikibot/site/_extensions.py on lines 742..755

                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 40.

                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

                Avoid too many return statements within this function.
                Open

                        return False
                Severity: Major
                Found in pywikibot/pagegenerators/_factory.py - About 30 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language