wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

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

    def test_set_math(self):
        """Test setting claim of math type."""
        wikidata = self.get_repo()
        claim = pywikibot.Claim(wikidata, 'P2535')
        self.assertEqual(claim.type, 'math')
Severity: Major
Found in tests/wikibase_tests.py and 3 other locations - About 2 hrs to fix
tests/wikibase_tests.py on lines 927..934
tests/wikibase_tests.py on lines 964..971
tests/wikibase_tests.py on lines 984..991

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

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_set_identifier(self):
        """Test setting claim of external-id type."""
        wikidata = self.get_repo()
        claim = pywikibot.Claim(wikidata, 'P214')
        self.assertEqual(claim.type, 'external-id')
Severity: Major
Found in tests/wikibase_tests.py and 3 other locations - About 2 hrs to fix
tests/wikibase_tests.py on lines 927..934
tests/wikibase_tests.py on lines 955..962
tests/wikibase_tests.py on lines 984..991

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

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_set_musical_notation(self):
        """Test setting claim of musical-notation type."""
        wikidata = self.get_repo()
        claim = pywikibot.Claim(wikidata, 'P6604')
        self.assertEqual(claim.type, 'musical-notation')
Severity: Major
Found in tests/wikibase_tests.py and 3 other locations - About 2 hrs to fix
tests/wikibase_tests.py on lines 927..934
tests/wikibase_tests.py on lines 955..962
tests/wikibase_tests.py on lines 964..971

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

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

File _datasite.py has 932 lines of code (exceeds 900 allowed). Consider refactoring.
Open

"""Objects representing API interface to Wikibase site."""
#
# (C) Pywikibot team, 2012-2024
#
# Distributed under the terms of the MIT license.
Severity: Major
Found in pywikibot/site/_datasite.py - About 2 hrs to fix

    Function pywikibot_script_docstring_fixups has a Cognitive Complexity of 25 (exceeds 10 allowed). Consider refactoring.
    Open

    def pywikibot_script_docstring_fixups(app, what, name, obj, options, lines):
        """Pywikibot specific conversions."""
        from scripts.cosmetic_changes import warning
    
        if what != 'module' or 'scripts.' not in name:
    Severity: Minor
    Found in docs/conf.py - About 2 hrs 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_siteinfo has a Cognitive Complexity of 25 (exceeds 10 allowed). Consider refactoring.
    Open

        def _get_siteinfo(self, prop, expiry) -> dict:
            """Retrieve a siteinfo property.
    
            All properties which the site doesn't
            support contain the default value. Because pre-1.12 no data was
    Severity: Minor
    Found in pywikibot/site/_siteinfo.py - About 2 hrs 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 deprecated has a Cognitive Complexity of 25 (exceeds 10 allowed). Consider refactoring.
    Open

    def deprecated(*args, **kwargs):
        """Decorator to output a deprecation warning.
    
        .. versionchanged:: 7.0
           `since` keyword must be a release number, not a timestamp.
    Severity: Minor
    Found in pywikibot/tools/_deprecate.py - About 2 hrs 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_page_info has a Cognitive Complexity of 25 (exceeds 10 allowed). Consider refactoring.
    Open

        def _get_page_info(self, force: bool = False):
            """Return a dict of tuples for all pages of djvu file.
    
            The tuples consist of (id, (size, dpi)).
            :param force: if True, refresh the cached data
    Severity: Minor
    Found in pywikibot/tools/djvu.py - About 2 hrs 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

    File _wbtypes.py has 931 lines of code (exceeds 900 allowed). Consider refactoring.
    Open

    """Wikibase data type classes."""
    #
    # (C) Pywikibot team, 2013-2024
    #
    # Distributed under the terms of the MIT license.
    Severity: Major
    Found in pywikibot/_wbtypes.py - About 2 hrs to fix

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

      def UnCategorizedTemplateGenerator(
          total: int = 100,
          site: BaseSite | None = None
      ) -> Iterable[pywikibot.page.Page]:
          """Uncategorized template generator.
      Severity: Major
      Found in pywikibot/pagegenerators/_generators.py and 4 other locations - About 2 hrs to fix
      pywikibot/pagegenerators/_generators.py on lines 619..630
      pywikibot/pagegenerators/_generators.py on lines 633..644
      pywikibot/pagegenerators/_generators.py on lines 705..716
      pywikibot/pagegenerators/_generators.py on lines 719..730

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

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

          def format(self, default: str | None = None) -> str:
              """Return a formatted string showing the range."""
              value: int | None = None
      
              if default is not None and self.test(default):
      Severity: Minor
      Found in pywikibot/bot_choice.py - About 2 hrs 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

      def UnCategorizedImageGenerator(
          total: int = 100,
          site: BaseSite | None = None
      ) -> Iterable[pywikibot.page.FilePage]:
          """Uncategorized file generator.
      Severity: Major
      Found in pywikibot/pagegenerators/_generators.py and 4 other locations - About 2 hrs to fix
      pywikibot/pagegenerators/_generators.py on lines 633..644
      pywikibot/pagegenerators/_generators.py on lines 647..658
      pywikibot/pagegenerators/_generators.py on lines 705..716
      pywikibot/pagegenerators/_generators.py on lines 719..730

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

      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

      def DeadendPagesPageGenerator(
          total: int = 100,
          site: BaseSite | None = None
      ) -> Iterable[pywikibot.page.Page]:
          """Dead-end page generator.
      Severity: Major
      Found in pywikibot/pagegenerators/_generators.py and 4 other locations - About 2 hrs to fix
      pywikibot/pagegenerators/_generators.py on lines 619..630
      pywikibot/pagegenerators/_generators.py on lines 633..644
      pywikibot/pagegenerators/_generators.py on lines 647..658
      pywikibot/pagegenerators/_generators.py on lines 705..716

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

      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

      def UnCategorizedPageGenerator(
          total: int = 100,
          site: BaseSite | None = None
      ) -> Iterable[pywikibot.page.Page]:
          """Uncategorized page generator.
      Severity: Major
      Found in pywikibot/pagegenerators/_generators.py and 4 other locations - About 2 hrs to fix
      pywikibot/pagegenerators/_generators.py on lines 619..630
      pywikibot/pagegenerators/_generators.py on lines 647..658
      pywikibot/pagegenerators/_generators.py on lines 705..716
      pywikibot/pagegenerators/_generators.py on lines 719..730

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

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

          def cleanUpLinks(self, text: str) -> str:
              """Tidy up wikilinks found in a string.
      
              This function will:
      
      
      Severity: Minor
      Found in pywikibot/cosmetic_changes.py - About 2 hrs 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

      def WantedPagesPageGenerator(
          total: int = 100,
          site: BaseSite | None = None
      ) -> Iterable[pywikibot.page.Page]:
          """Wanted page generator.
      Severity: Major
      Found in pywikibot/pagegenerators/_generators.py and 4 other locations - About 2 hrs to fix
      pywikibot/pagegenerators/_generators.py on lines 619..630
      pywikibot/pagegenerators/_generators.py on lines 633..644
      pywikibot/pagegenerators/_generators.py on lines 647..658
      pywikibot/pagegenerators/_generators.py on lines 719..730

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

      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

      TestSiteGenerators has 33 functions (exceeds 30 allowed). Consider refactoring.
      Open

      class TestSiteGenerators(DefaultSiteTestCase):
      
          """Test cases for Site methods."""
      
          cached = True
      Severity: Minor
      Found in tests/site_generators_tests.py - About 2 hrs to fix

        Function bad_name_filer has a Cognitive Complexity of 23 (exceeds 10 allowed). Consider refactoring.
        Open

            def bad_name_filer(self, name, force: bool = False) -> bool:
                """Check for bad names."""
                if not globalvar.filt_bad_name:
                    return False
        
        
        Severity: Minor
        Found in scripts/welcome.py - About 2 hrs 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 templatesWithParams has a Cognitive Complexity of 23 (exceeds 10 allowed). Consider refactoring.
        Open

            def templatesWithParams(  # noqa: N802
                self,
            ) -> list[tuple[pywikibot.Page, list[str]]]:
                """Return templates used on this Page.
        
        
        Severity: Minor
        Found in pywikibot/page/_page.py - About 2 hrs 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 members has a Cognitive Complexity of 23 (exceeds 10 allowed). Consider refactoring.
        Open

            def members(self, *,
                        recurse: bool = False,
                        total: int | None = None,
                        **kwargs: Any) -> Generator[Page, None, None]:
                """Yield all category contents (subcats, pages, and files).
        Severity: Minor
        Found in pywikibot/page/_category.py - About 2 hrs 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