wikimedia/pywikibot

View on GitHub

Showing 708 of 708 total issues

Function filter_unique has a Cognitive Complexity of 21 (exceeds 10 allowed). Consider refactoring.
Open

def filter_unique(iterable, container=None, key=None, add=None):
    """
    Yield unique items from an iterable, omitting duplicates.

    By default, to provide uniqueness, it puts the generated items into a
Severity: Minor
Found in pywikibot/tools/itertools.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 index has a Cognitive Complexity of 21 (exceeds 10 allowed). Consider refactoring.
Open

    def index(self) -> IndexPage | None:
        """Get the Index page which contains ProofreadPage.

        If there are many Index pages link to this ProofreadPage, and
        the ProofreadPage is titled Page:<index title>/<page number>,
Severity: Minor
Found in pywikibot/proofreadpage.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_regexes has a Cognitive Complexity of 21 (exceeds 10 allowed). Consider refactoring.
Open

def get_regexes(
    keys: str | Iterable[str],
    site: pywikibot.site.BaseSite | None = None
) -> list[Pattern[str]]:
    """Fetch compiled regexes.
Severity: Minor
Found in pywikibot/textlib.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 replace.py has 903 lines of code (exceeds 900 allowed). Consider refactoring.
Open

#!/usr/bin/env python3
r"""
This bot will make direct text replacements.

It will retrieve information on which pages might need changes either from
Severity: Major
Found in scripts/replace.py - About 2 hrs to fix

    Function get_redirects_from_dump has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def get_redirects_from_dump(
            self,
            alsoGetPageTitles: bool = False
        ) -> tuple[dict[str, str], set[str]]:
            """
    Severity: Minor
    Found in scripts/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 skipPage has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def skipPage(page) -> bool:
            """Determine if the page should be skipped."""
            try:
                templates_to_ignore = ignoreTemplates[page.site.code]
            except KeyError:
    Severity: Minor
    Found in scripts/commonscat.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_desc_template has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def process_desc_template(
            self,
            template: mwparserfromhell.nodes.template.Template
        ) -> bool:
            """Process description template.
    Severity: Minor
    Found in scripts/commons_information.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 setup_soft_redirect has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def setup_soft_redirect(self):
            """Setup soft redirect task."""
            pywikibot.info(f'\nChecking {self.cat.categoryinfo["subcats"]}'
                           ' category redirect pages')
            self.load_record()
    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 __init__ has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def __init__(self, fromurl, **kwargs) -> None:
            """
            Initializer.
    
            :raises pywikibot.exceptions.ServerError: a server error occurred
    Severity: Minor
    Found in pywikibot/site_detect.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 isCategoryRedirect has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def isCategoryRedirect(self) -> bool:
            """Return True if this is a category redirect page, False otherwise."""
            if not self.is_categorypage():
                return False
    
    
    Severity: Minor
    Found in pywikibot/page/_basepage.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 create_diff has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def create_diff(self) -> Iterable[str]:
            """Generator of diff text for this hunk, without formatting.
    
            Check each line ends with line feed to prevent behaviour like
            :issue:`46395`
    Severity: Minor
    Found in pywikibot/diff.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 getlangs has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def getlangs(self, w) -> None:
            """Determine site code of a family.
    
            .. versionchanged:: 8.1
               with [e]dit the interwiki list can be given delimited by
    Severity: Minor
    Found in pywikibot/scripts/generate_family_file.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 read_file_content has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
    Open

        def read_file_content(self, file_url: str):
            """Return name of temp file in which remote file is saved."""
            pywikibot.info('Reading file ' + file_url)
    
            handle, tempname = tempfile.mkstemp()
    Severity: Minor
    Found in pywikibot/specialbots/_upload.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 18 arguments (exceeds 7 allowed). Consider refactoring.
    Open

        def __init__(self, oldcat,
    Severity: Major
    Found in scripts/category.py - About 1 hr to fix

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

              'hi': lambda m: multi(m, [
                  (lambda v: dh_constVal(v, 20, 'बीसवी शताब्दी'), lambda p: p == 20),
                  # This is a dummy value, just to avoid validation testing.
                  # Later, it should be replaced with a proper 'fa' titles
                  (lambda v: dh_centuryAD(v, '%dth century'),
      Severity: Major
      Found in pywikibot/date.py and 5 other locations - About 1 hr to fix
      pywikibot/date.py on lines 972..975
      pywikibot/date.py on lines 1040..1043
      pywikibot/date.py on lines 1096..1102
      pywikibot/date.py on lines 1232..1235
      pywikibot/date.py on lines 1342..1344

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

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

              'ro': lambda m: multi(m, [
                  (lambda v: dh_constVal(v, 0, 'Primul deceniu î.Hr.'),
                   lambda p: p == 0),
                  (lambda v: dh_decBC(v, 'Anii %d î.Hr.'), alwaysTrue)]),
      Severity: Major
      Found in pywikibot/date.py and 5 other locations - About 1 hr to fix
      pywikibot/date.py on lines 972..975
      pywikibot/date.py on lines 1096..1102
      pywikibot/date.py on lines 1113..1118
      pywikibot/date.py on lines 1232..1235
      pywikibot/date.py on lines 1342..1344

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

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

              'ur': lambda m: multi(m, [
                  (lambda v: dh_constVal(v, 0, '0000مبم'), lambda p: p == 0),
                  (lambda v: dh_millenniumAD(v, '%d000مبم'), alwaysTrue)]),
      Severity: Major
      Found in pywikibot/date.py and 5 other locations - About 1 hr to fix
      pywikibot/date.py on lines 972..975
      pywikibot/date.py on lines 1040..1043
      pywikibot/date.py on lines 1096..1102
      pywikibot/date.py on lines 1113..1118
      pywikibot/date.py on lines 1232..1235

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

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

              'ro': lambda m: multi(m, [
                  (lambda v: dh_constVal(v, 1, 'Secolul I î.Hr.'), lambda p: p == 1),
                  (lambda v: dh_centuryBC(v, 'Secolul al %R-lea î.Hr.'),
                   alwaysTrue)]),
      Severity: Major
      Found in pywikibot/date.py and 5 other locations - About 1 hr to fix
      pywikibot/date.py on lines 972..975
      pywikibot/date.py on lines 1040..1043
      pywikibot/date.py on lines 1096..1102
      pywikibot/date.py on lines 1113..1118
      pywikibot/date.py on lines 1342..1344

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

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

              'ro': lambda m: multi(m, [
                  (lambda v: dh_constVal(v, 0, 'Primul deceniu d.Hr.'),
                   lambda p: p == 0),
                  (lambda v: dh_decAD(v, 'Anii %d'), alwaysTrue)]),
      Severity: Major
      Found in pywikibot/date.py and 5 other locations - About 1 hr to fix
      pywikibot/date.py on lines 1040..1043
      pywikibot/date.py on lines 1096..1102
      pywikibot/date.py on lines 1113..1118
      pywikibot/date.py on lines 1232..1235
      pywikibot/date.py on lines 1342..1344

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

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

              'fa': lambda m: multi(m, [
                  (lambda v: dh_constVal(v, 20, 'سده ۲۰ (میلادی)'),
                   lambda p: p == 20),
                  # This is a dummy value, just to avoid validation testing.
                  # Later, it should be replaced with a proper 'fa' titles
      Severity: Major
      Found in pywikibot/date.py and 5 other locations - About 1 hr to fix
      pywikibot/date.py on lines 972..975
      pywikibot/date.py on lines 1040..1043
      pywikibot/date.py on lines 1113..1118
      pywikibot/date.py on lines 1232..1235
      pywikibot/date.py on lines 1342..1344

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

      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