diff --git a/.github/workflows/sonar-cloud.yml b/.github/workflows/sonar-cloud.yml index 3db8266..544319d 100644 --- a/.github/workflows/sonar-cloud.yml +++ b/.github/workflows/sonar-cloud.yml @@ -39,6 +39,7 @@ jobs: - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master + continue-on-error: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/src/autofaker/generator.py b/src/autofaker/generator.py index 8321afb..399d6ef 100644 --- a/src/autofaker/generator.py +++ b/src/autofaker/generator.py @@ -43,12 +43,23 @@ def create_datetime(type_name, field_name: str = None, use_fake_data: bool = Fal @staticmethod def _get_type_name(t) -> str: + PRIMITIVE_TYPES = { + "int", "float", "str", "complex", "range", "bytes", "bytearray" + } + try: return t.__name__ except Exception: attributes = dir(t) if "_name" in attributes: return t._name + # If __future__.annotations was imported by the user, then the type + # will be a str. Thus, asserting the type with type() will fail, + # because it will always be a string. This is because, annotations + # transforms any type into a string object. Therefore, if the type + # is a string, assess if it is the name of a known primitive type. + elif type(t) == str and t in PRIMITIVE_TYPES: + return t return type(t).__name__