From 123e067c5e2e6740807378c73616447e27672c8a Mon Sep 17 00:00:00 2001 From: Jorge Miranda Date: Wed, 2 Aug 2023 16:44:25 +0100 Subject: [PATCH 1/2] Add support for __future__.annotations. --- src/autofaker/generator.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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__ From 47501bb8753d05c5666f12ee8cee5b912e495b4e Mon Sep 17 00:00:00 2001 From: Christian Helle Date: Wed, 2 Aug 2023 21:16:02 +0200 Subject: [PATCH 2/2] Allow SonarCloud builds to fail This will eventually happen for PR builds by first-time contributors --- .github/workflows/sonar-cloud.yml | 1 + 1 file changed, 1 insertion(+) 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 }}