sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.51k stars 65 forks source link

Do not require typehints for positional or keyword-only ( '*' or '/' ) parameters #314

Closed Josverl closed 1 year ago

Josverl commented 1 year ago

Checklist

Description

sourcery should not require typehints for positional or keyword-only ( '*' or '/' ) parameters

Annotate parameter * in public function/method publish with a type

image

Note that there are a few other params that could use a type annotation, however '*' should not be annotated.

config:

rule_settings:
  enable: 
  - default
  - require-parameter-annotation

Code snippet that reproduces issue

def publish(
    *,
    db: PysonDB,
    pkg_type,
    version: str,
    family="micropython",
    production,  # PyPI or Test-PyPi
    dryrun=False,  # don't publish , dont save to the database
    force=False,  # publish even if no changes
    clean: bool = False,  # clean up afterwards
    port: str = "",
    board: str = "",
) -> Dict[str, Any]:
  ...

Debug Information

IDE Version: VScode

Sourcery Version: Sourcery 1.0.3

Operating system and Version: Windows 11

gsnidero commented 1 year ago

I found the same issue and am using:

ruancomelli commented 1 year ago

Hello @Josverl and @gsnidero! Thank you for reporting this issue.

We are restructuring how Sourcery works internally, and hopefully this issue will be sorted out naturally in a few weeks.

Until then, I submitted a quick-fix to sourcery-rules to fix the bug you reported: https://github.com/sourcery-ai/sourcery-rules/pull/9.

Josverl commented 1 year ago

Thanks for the quick fix,

Do I need to change my config in order to use this, if so; How ?

ruancomelli commented 1 year ago

Hey @Josverl!

It depends on how you are using the GPSG rules:

  1. if you have copied the rules from the google-python-style-guide.yaml config file into a local .sourcery.yaml file, then you will need to edit it to include the fix I submitted to that repository: adding the extra not arg.equals("*") and not arg.equals("/") to the condition field of require-parameter-annotation;
  2. if you are using the GPSG rules that ship with the Sourcery CLI, then the fix will become automatically available to you after that fix is merged and a new Sourcery version is released;

I will let you know once the PR is merged and also once we release the fix.

ruancomelli commented 1 year ago

Hello @Josverl and @gsnidero!

The fix for this issue was just merged into the https://github.com/sourcery-ai/sourcery-rules repository. The next Sourcery release (probably v1.0.5) will ship with the fix.