SonarCloud code smell being raised in Python code that is compliant with PEP589 TypedDict

There are custom defined type sub-classes (inheriting from TypedDict) as per PEP589. We also have a workflow that uses the Pyright type checker and 0 errors are raised by this.

  • ALM used: GitHub

  • CI system used: GitHub Actions

  • Scanner command used when applicable:
    - name: SonarCloud Scan
    uses: SonarSource/sonarcloud-github-action@master
    with:
    args: >
    -Dsonar.python.coverage.reportPaths=coverage.xml

  • Languages of the repository: Python

  • Link to PR: BENCH-186: Add openapi documentation by MichaelOSullivanAnswer · Pull Request #63 · AnswerConsulting/AnswerKing-Python · GitHub

  • Error observed:
    Assign to “product_example” a value of type “ProductType” instead of “dict” or update its type hint.

  • Steps to reproduce: Workflow triggered for each new pull request and each push to that branch

  • Potential workaround: None

Hi,

Welcome to the community!

I don’t see any issues raised in that PR.

Could you provide a reproducer and the rule id, please?

 
Ann

I am also getting “Arguments given to functions should be of an expected type python:S5655” errors on valid PEP589 TypedDict types.

Try:

from typing import TypedDict

class Movie(TypedDict):
    name: str
    year: int

def main(movie: Movie):
    print(movie)

main({'name': "Ad Astra", 'year': 2019})

It is a private repo, so I can’t link the code.

Hello,

First, sorry for the delay in the answer @MichaelOSullivan, this thread somehow slipped under our radar.

Thank you @Aaron_Miller for the reproducer. I created the following ticket to fix this.

Cheers,
Guillaume