wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

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

    @need_right('flow-suppress')
    @need_extension('Flow')
    @deprecated(since='9.4.0')
    def suppress_topic(self, page, reason):
        """Suppress 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 657..670
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-suppress')
    @need_extension('Flow')
    @deprecated(since='9.4.0')
    def suppress_post(self, post, reason):
        """Suppress 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 697..710
pywikibot/site/_extensions.py on lines 712..725
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/site/_namespace.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            return any(function(data) for function in self.filter['any'])
    Severity: Major
    Found in pywikibot/comms/eventstreams.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_post(self, post, reason):
              """Restore 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 697..710
      pywikibot/site/_extensions.py on lines 712..725
      pywikibot/site/_extensions.py on lines 727..740

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

              data.found_in[self.pages['fr']] = [self.pages['en'], self.pages['pl']]
      Severity: Minor
      Found in tests/interwiki_graph_tests.py and 2 other locations - About 30 mins to fix
      tests/interwiki_graph_tests.py on lines 55..55
      tests/interwiki_graph_tests.py on lines 57..57

      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-hide')
          @need_extension('Flow')
          @deprecated(since='9.4.0')
          def hide_post(self, post, reason):
              """Hide 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 697..710
      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 3 locations. Consider refactoring.
      Open

              data.found_in[self.pages['pl']] = [self.pages['en'], self.pages['fr']]
      Severity: Minor
      Found in tests/interwiki_graph_tests.py and 2 other locations - About 30 mins to fix
      tests/interwiki_graph_tests.py on lines 55..55
      tests/interwiki_graph_tests.py on lines 56..56

      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 True
      Severity: Major
      Found in pywikibot/pagegenerators/_factory.py - About 30 mins to fix

        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_topic(self, page, reason):
                """Delete 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 627..640
        pywikibot/site/_extensions.py on lines 642..655
        pywikibot/site/_extensions.py on lines 657..670
        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

        Avoid too many return statements within this function.
        Open

                return True
        Severity: Major
        Found in pywikibot/tools/djvu.py - About 30 mins to fix

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

              @need_right('flow-hide')
              @need_extension('Flow')
              @deprecated(since='9.4.0')
              def hide_topic(self, page, reason):
                  """Hide 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 642..655
          pywikibot/site/_extensions.py on lines 657..670
          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 3 locations. Consider refactoring.
          Open

                  data.found_in[self.pages['en']] = [self.pages['fr'], self.pages['pl']]
          Severity: Minor
          Found in tests/interwiki_graph_tests.py and 2 other locations - About 30 mins to fix
          tests/interwiki_graph_tests.py on lines 56..56
          tests/interwiki_graph_tests.py on lines 57..57

          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

          Function skip_page has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
          Open

              def skip_page(self, page):
                  """Skip if -exceptUrl matches or page does not exists."""
                  if page.exists():
                      if self.opt.createonly:
                          pywikibot.warning(f'Skipping because {page} already exists')
          Severity: Minor
          Found in scripts/add_text.py - About 25 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 main has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
          Open

          def main() -> None:
              """Print environment variables."""
              _pwb_dir = os.path.abspath(os.path.join(
                  os.path.split(__file__)[0], '..', '..'))
              _pwb_dir = first_upper(_pwb_dir)
          Severity: Minor
          Found in tests/pwb/print_env.py - About 25 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 11 (exceeds 10 allowed). Consider refactoring.
          Open

              def run(self) -> None:
                  """Run bot."""
                  self.site.login()
                  while True:
                      self.wait = False
          Severity: Minor
          Found in scripts/clean_sandbox.py - About 25 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 main has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
          Open

          def main(*args: str) -> None:
              """Process command line arguments and invoke ParserFunctionCountBot."""
              local_args = pywikibot.handle_args(*args)
              options = {}
          
          
          Severity: Minor
          Found in scripts/parser_function_count.py - About 25 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 11 (exceeds 10 allowed). Consider refactoring.
          Open

              def __init__(self, **kwargs) -> None:
                  """Initializer."""
                  super().__init__(**kwargs)
                  self._use_fake_user_agent = config.fake_user_agent_default.get(
                      'reflinks', False)
          Severity: Minor
          Found in scripts/reflinks.py - About 25 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_search has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
          Open

              def test_search(self):
                  """Test the site.search() method."""
                  mysite = self.site
                  try:
                      se = list(mysite.search('wiki', total=100, namespaces=0))
          Severity: Minor
          Found in tests/site_generators_tests.py - About 25 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 11 (exceeds 10 allowed). Consider refactoring.
          Open

              def __iter__(self):
                  """Iterator."""
                  n = 0
                  while self._total is None or n < self._total:
                      if not hasattr(self, 'source'):
          Severity: Minor
          Found in tests/eventstreams_tests.py - About 25 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