wikimedia/pywikibot

View on GitHub

Showing 708 of 708 total issues

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

        'ca': lambda m: multi(m, [
            (lambda v: dh_decAD(v, 'Dècada de %d'), lambda p: p == 1970),
            (lambda v: dh_decAD(v, 'Dècada del %d'), alwaysTrue)]),
Severity: Major
Found in pywikibot/date.py and 4 other locations - About 1 hr to fix
pywikibot/date.py on lines 1088..1090
pywikibot/date.py on lines 1105..1107
pywikibot/date.py on lines 1210..1214
pywikibot/date.py on lines 1294..1297

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

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 register_families_folder has a Cognitive Complexity of 19 (exceeds 10 allowed). Consider refactoring.
Open

def register_families_folder(folder_path: str,
                             not_exists_ok: bool = False) -> None:
    """Register all family class files contained in a directory.

    .. versionadded:: 7.0
Severity: Minor
Found in pywikibot/config.py - About 1 hr 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

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

        'el': lambda m: multi(m, [
            (lambda v: dh_centuryAD(v, '%dός αιώνας'), lambda p: p == 20),
            (lambda v: dh_centuryAD(v, '%dος αιώνας'), alwaysTrue)]),
Severity: Major
Found in pywikibot/date.py and 4 other locations - About 1 hr to fix
pywikibot/date.py on lines 868..870
pywikibot/date.py on lines 1105..1107
pywikibot/date.py on lines 1210..1214
pywikibot/date.py on lines 1294..1297

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

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

        'fr': lambda m: multi(m, [
            (lambda v: dh_millenniumAD(v, '%Rer millénaire'),
             lambda p: p == 1),
            (lambda v: dh_millenniumAD(v, '%Re millénaire'), alwaysTrue)]),
Severity: Major
Found in pywikibot/date.py and 4 other locations - About 1 hr to fix
pywikibot/date.py on lines 868..870
pywikibot/date.py on lines 1088..1090
pywikibot/date.py on lines 1105..1107
pywikibot/date.py on lines 1210..1214

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

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 16 arguments (exceeds 7 allowed). Consider refactoring.
Open

    def __init__(self, url: list[str] | str, *,
Severity: Major
Found in pywikibot/specialbots/_upload.py - About 1 hr to fix

    Function __init__ has 45 lines of code (exceeds 30 allowed). Consider refactoring.
    Open

        def __init__(self, parent=None, **kwargs) -> None:
            """Initializer."""
            for module in (idlelib, tkinter):
                if isinstance(module, ImportError):
                    raise module
    Severity: Minor
    Found in pywikibot/userinterfaces/gui.py - About 1 hr to fix

      Function main has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

      def main(*args: str) -> None:
          """
          Process command line arguments and invoke bot.
      
          If args is an empty list, sys.argv is used.
      Severity: Minor
      Found in scripts/djvutext.py - About 1 hr 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 process_entries has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

      def process_entries(cache_path, func, use_accesstime: bool | None = None,
                          output_func=None, action_func=None, *,
                          tests: int | None = None):
          """Check the contents of the cache.
      
      
      Severity: Minor
      Found in scripts/maintenance/cache.py - About 1 hr 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 allow_asynchronous has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

      def allow_asynchronous(func):
          """Decorator to make it possible to run a BasePage method asynchronously.
      
          This is done when the method is called with kwarg
          :code:`asynchronous=True`. Optionally, you can also provide kwarg
      Severity: Minor
      Found in pywikibot/page/_decorators.py - About 1 hr 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 _post_process has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

          def _post_process(prop, data) -> None:
              """Do some default handling of data. Directly modifies data."""
              # Be careful with version tests inside this here as it might need to
              # query this method to actually get the version number
      
      
      Severity: Minor
      Found in pywikibot/site/_siteinfo.py - About 1 hr 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 fromJSON has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

          def fromJSON(cls, site, data: dict[str, Any]) -> Claim:
              """Create a claim object from JSON returned in the API call.
      
              .. versionchanged:: 9.4
                 print a warning if the Claim.type is not given and missing in
      Severity: Minor
      Found in pywikibot/page/_wikibase.py - About 1 hr 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 RepeatingGenerator has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

      def RepeatingGenerator(
          generator: Callable[..., Iterable[pywikibot.page.BasePage]],
          key_func: Callable[[pywikibot.page.BasePage], Any] = lambda x: x,
          sleep_duration: int = 60,
          total: int | None = None,
      Severity: Minor
      Found in pywikibot/pagegenerators/__init__.py - About 1 hr 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 from_url has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

          def from_url(self, url: str) -> str | None:
              """Return whether this family matches the given url.
      
              It is first checking if a domain of this family is in the domain of
              the URL. If that is the case it's checking all codes and verifies that
      Severity: Minor
      Found in pywikibot/family.py - About 1 hr 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 stream_output has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

          def stream_output(self, text, targetStream=None) -> None:
              """Output text to a stream.
      
              If a character can't be displayed in the encoding used by the user's
              terminal, it will be replaced with a question mark or by a
      Severity: Minor
      Found in pywikibot/userinterfaces/terminal_interface_base.py - About 1 hr 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 allpages has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
      Open

          def allpages(
              self,
              start: str = '!',
              prefix: str = '',
              namespace: SingleNamespaceType = 0,
      Severity: Minor
      Found in pywikibot/site/_generators.py - About 1 hr 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 18 (exceeds 10 allowed). Consider refactoring.
      Open

          def __init__(self, site=None,
                       mime: dict | None = None,
                       throttle: bool = True,
                       max_retries: int | None = None,
                       retry_wait: int | None = None,
      Severity: Minor
      Found in pywikibot/data/api/_requests.py - About 1 hr 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

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

          def test_normal_versions(self):
              """Test comparison between release versions."""
              self.assertGreater(self._make('1.33'), self._make('1.32.0'))
              self.assertEqual(self._make('1.33'), self._make('1.33'))
      Severity: Major
      Found in tests/mediawikiversion_tests.py and 2 other locations - About 1 hr to fix
      tests/mediawikiversion_tests.py on lines 36..39
      tests/mediawikiversion_tests.py on lines 41..44

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

      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 _handle_titleregex(self, value: str) -> Literal[True]:
              """Handle `-titleregex` argument."""
              if not value:
                  value = pywikibot.input(
                      'What page names are you looking for?')
      Severity: Major
      Found in pywikibot/pagegenerators/_factory.py and 3 other locations - About 1 hr to fix
      pywikibot/pagegenerators/_factory.py on lines 825..831
      pywikibot/pagegenerators/_factory.py on lines 833..838
      pywikibot/pagegenerators/_factory.py on lines 840..845

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

      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 _handle_grepnot(self, value: str) -> Literal[True]:
              """Handle `-grepnot` argument."""
              if not value:
                  value = pywikibot.input('Which pattern do you want to skip?')
              self.articlenotfilter_list.append(value)
      Severity: Major
      Found in pywikibot/pagegenerators/_factory.py and 3 other locations - About 1 hr to fix
      pywikibot/pagegenerators/_factory.py on lines 817..823
      pywikibot/pagegenerators/_factory.py on lines 825..831
      pywikibot/pagegenerators/_factory.py on lines 833..838

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

      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

          def test_combined_versions(self):
              """Test comparison between wmf versions and release versions."""
              self.assertGreater(self._make('1.33wmf10'), self._make('1.32.3'))
              self.assertGreater(self._make('1.33'), self._make('1.33wmf10'))
      Severity: Major
      Found in tests/mediawikiversion_tests.py and 2 other locations - About 1 hr to fix
      tests/mediawikiversion_tests.py on lines 31..34
      tests/mediawikiversion_tests.py on lines 36..39

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

      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

      Severity
      Category
      Status
      Source
      Language