wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

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

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 820..826
pywikibot/pagegenerators/_factory.py on lines 828..833
pywikibot/pagegenerators/_factory.py on lines 835..840

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

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

    def run(self) -> bool:
        """Run the installer script.

        :return: True if no error occurs, else False
        """
Severity: Minor
Found in make_dist.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 run has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
Open

    def run(self) -> None:
        """Run thread."""
        while not self.killed:
            if not self.queue:
                if self.finishing:
Severity: Minor
Found in scripts/weblinkchecker.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 treat has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
Open

    def treat(self, page) -> None:
        """Process one page."""
        # Load the page's text from the wiki
        new_text = page.text
        raw_text = textlib.removeDisabledParts(new_text)
Severity: Minor
Found in scripts/reflinks.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 generator has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
Open

    def generator(self) -> Generator[pywikibot.User, None, None]:
        """Retrieve new users."""
        while True:
            if globalvar.timeoffset != 0:
                start = self.site.server_time() - timedelta(
Severity: Minor
Found in scripts/welcome.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 17 (exceeds 10 allowed). Consider refactoring.
Open

    def __init__(self, code: str, fam=None, user=None) -> None:
        """Initializer.

        :param code: the site's language code
        :type code: str
Severity: Minor
Found in pywikibot/site/_basesite.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_from_entity_uri_no_item(self):
        """Test ItemPage.from_entity_uri with non-existent item."""
        repo = self.get_repo()
        entity_uri = 'http://www.wikidata.org/entity/Q999999999999999999'
        regex = r"^Page .+ doesn't exist\.$"
Severity: Major
Found in tests/wikibase_tests.py and 2 other locations - About 1 hr to fix
tests/wikibase_tests.py on lines 585..592
tests/wikibase_tests.py on lines 594..600

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

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_from_entity_uri_invalid_title(self):
        """Test ItemPage.from_entity_uri with an invalid item title format."""
        repo = self.get_repo()
        entity_uri = 'http://www.wikidata.org/entity/Nonsense'
        regex = r"^'.+' is not a valid .+ page title$"
Severity: Major
Found in tests/wikibase_tests.py and 2 other locations - About 1 hr to fix
tests/wikibase_tests.py on lines 585..592
tests/wikibase_tests.py on lines 602..608

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

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

def main(*args: str) -> None:
    """Print pywikibot version and important settings.

    .. versionchanged:: 9.1.2
       usernames are not printed with ``-nouser`` option.
Severity: Minor
Found in pywikibot/scripts/version.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 get has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
Open

    def get(
        self,
        key: str,
        get_default: bool = True,
        cache: bool = True,
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

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

    def test_from_entity_uri_wrong_repo(self):
        """Test ItemPage.from_entity_uri with unexpected item repo."""
        repo = self.get_repo()
        entity_uri = 'http://test.wikidata.org/entity/Q124'
        regex = (r'^The supplied data repository \(.+\) does not '
Severity: Major
Found in tests/wikibase_tests.py and 2 other locations - About 1 hr to fix
tests/wikibase_tests.py on lines 594..600
tests/wikibase_tests.py on lines 602..608

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

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

Consider simplifying this complex logical expression.
Open

        if (not self.workonme  # we don't work on it anyway
            or not self.untranslated and not self.conf.askhints
            or self.hintsAsked
            or not self.origin
            or not self.origin.exists()
Severity: Critical
Found in scripts/interwiki.py - About 1 hr to fix

    Function testNamespaceCompare has 38 lines of code (exceeds 30 allowed). Consider refactoring.
    Open

        def testNamespaceCompare(self):
            """Test Namespace comparisons."""
            a = Namespace(id=0, canonical_name='')
    
            self.assertEqual(a, 0)
    Severity: Minor
    Found in tests/namespace_tests.py - About 1 hr to fix

      Function test_last_match_and_replace has 37 lines of code (exceeds 30 allowed). Consider refactoring.
      Open

          def test_last_match_and_replace(self):
              """Test that pattern matches and removes items correctly."""
              txt_with_one_match = 'this string has 3000, 1999 and 3000 in it'
              txt_with_two_match = 'this string has 1998, 1999 and 3000 in it'
              txt_with_no_match = 'this string has no match'
      Severity: Minor
      Found in tests/timestripper_tests.py - About 1 hr to fix

        Function test_WbTime_normalization has 37 lines of code (exceeds 30 allowed). Consider refactoring.
        Open

            def test_WbTime_normalization(self):
                """Test WbTime normalization."""
                repo = self.get_repo()
                # flake8 is being annoying, so to reduce line length, I'll make
                # some aliases here
        Severity: Minor
        Found in tests/wbtypes_tests.py - About 1 hr to fix

          Function _test_fromPage_noitem has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
          Open

              def _test_fromPage_noitem(self, link):
                  """Helper function to test a page without an associated item.
          
                  It tests two of the ways to fetch an item:
                  1. the Page already has props, which should contain an item id if
          Severity: Minor
          Found in tests/wikibase_tests.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 move_contents has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
          Open

              def move_contents(self, old_cat_title: str, new_cat_title: str,
                                edit_summary: str) -> tuple[int, int]:
                  """The worker function that moves pages out of oldCat into newCat."""
                  old_cat = pywikibot.Category(self.site, self.catprefix + old_cat_title)
                  new_cat = pywikibot.Category(self.site, self.catprefix + new_cat_title)
          Severity: Minor
          Found in scripts/category_redirect.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 guess_reason_for_deletion has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
          Open

              def guess_reason_for_deletion(self, page):
                  """Find a default reason for speedy deletion."""
                  # TODO: The following check loads the page 2 times.
                  # Find a better way to do it.
                  if page.isTalkPage() and (page.toggleTalkPage().isRedirectPage()
          Severity: Minor
          Found in scripts/speedy_delete.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

          Severity
          Category
          Status
          Source
          Language