Skip to content

Commit

Permalink
add dot for local imports
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Apr 6, 2024
1 parent b8bfb0f commit 1ceaaac
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/Generator/Python.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private function getImports(TypeAbstract $origin): array

foreach ($refs as $ref) {
[$ns, $name] = TypeUtil::split($ref);
$imports[] = 'from ' . $this->normalizer->file($name) . ' import ' . $this->normalizer->class($name);
$imports[] = 'from .' . $this->normalizer->file($name) . ' import ' . $this->normalizer->class($name);
}

return $imports;
Expand Down
10 changes: 5 additions & 5 deletions tests/Generator/resource/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Web:
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from typing import List
from location import Location
from .location import Location


# An simple author element with some description
Expand All @@ -48,10 +48,10 @@ class Meta(Dict[str, str]):
from typing import List
from typing import Dict
from typing import Union
from meta import Meta
from author import Author
from location import Location
from web import Web
from .meta import Meta
from .author import Author
from .location import Location
from .web import Web


# An general news entry
Expand Down
84 changes: 42 additions & 42 deletions tests/Generator/resource/python/python_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CommonType:

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from common_type import CommonType
from .common_type import CommonType


# Represents an any type
Expand All @@ -26,13 +26,13 @@ class AnyType(CommonType):
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from typing import Union
from common_type import CommonType
from boolean_type import BooleanType
from number_type import NumberType
from string_type import StringType
from reference_type import ReferenceType
from generic_type import GenericType
from any_type import AnyType
from .common_type import CommonType
from .boolean_type import BooleanType
from .number_type import NumberType
from .string_type import StringType
from .reference_type import ReferenceType
from .generic_type import GenericType
from .any_type import AnyType


# Represents an array type. An array type contains an ordered list of a specific type
Expand All @@ -48,7 +48,7 @@ class ArrayType(CommonType):
from dataclasses_json import dataclass_json, config
from typing import List
from typing import Union
from common_type import CommonType
from .common_type import CommonType


# Represents a scalar type
Expand All @@ -61,7 +61,7 @@ class ScalarType(CommonType):

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from scalar_type import ScalarType
from .scalar_type import ScalarType


# Represents a boolean type
Expand Down Expand Up @@ -95,7 +95,7 @@ class GenericType:
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from typing import List
from reference_type import ReferenceType
from .reference_type import ReferenceType


# Represents an intersection type
Expand All @@ -108,16 +108,16 @@ class IntersectionType:
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from typing import Union
from common_type import CommonType
from boolean_type import BooleanType
from number_type import NumberType
from string_type import StringType
from array_type import ArrayType
from union_type import UnionType
from intersection_type import IntersectionType
from reference_type import ReferenceType
from generic_type import GenericType
from any_type import AnyType
from .common_type import CommonType
from .boolean_type import BooleanType
from .number_type import NumberType
from .string_type import StringType
from .array_type import ArrayType
from .union_type import UnionType
from .intersection_type import IntersectionType
from .reference_type import ReferenceType
from .generic_type import GenericType
from .any_type import AnyType


# Represents a map type. A map type contains variable key value entries of a specific type
Expand All @@ -131,7 +131,7 @@ class MapType(CommonType):

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from scalar_type import ScalarType
from .scalar_type import ScalarType


# Represents a number type (contains also integer)
Expand Down Expand Up @@ -159,7 +159,7 @@ class ReferenceType:

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from scalar_type import ScalarType
from .scalar_type import ScalarType


# Represents a string type
Expand All @@ -176,17 +176,17 @@ class StringType(ScalarType):
from typing import List
from typing import Dict
from typing import Union
from common_type import CommonType
from map_type import MapType
from array_type import ArrayType
from boolean_type import BooleanType
from number_type import NumberType
from string_type import StringType
from any_type import AnyType
from intersection_type import IntersectionType
from union_type import UnionType
from reference_type import ReferenceType
from generic_type import GenericType
from .common_type import CommonType
from .map_type import MapType
from .array_type import ArrayType
from .boolean_type import BooleanType
from .number_type import NumberType
from .string_type import StringType
from .any_type import AnyType
from .intersection_type import IntersectionType
from .union_type import UnionType
from .reference_type import ReferenceType
from .generic_type import GenericType


# Represents a struct type. A struct type contains a fix set of defined properties
Expand All @@ -203,9 +203,9 @@ class StructType(CommonType):
from dataclasses_json import dataclass_json, config
from typing import Dict
from typing import Union
from struct_type import StructType
from map_type import MapType
from reference_type import ReferenceType
from .struct_type import StructType
from .map_type import MapType
from .reference_type import ReferenceType


# The root TypeSchema
Expand All @@ -220,11 +220,11 @@ class TypeSchema:
from dataclasses_json import dataclass_json, config
from typing import List
from typing import Union
from discriminator import Discriminator
from number_type import NumberType
from string_type import StringType
from boolean_type import BooleanType
from reference_type import ReferenceType
from .discriminator import Discriminator
from .number_type import NumberType
from .string_type import StringType
from .boolean_type import BooleanType
from .reference_type import ReferenceType


# Represents an union type. An union type can contain one of the provided types
Expand Down
6 changes: 3 additions & 3 deletions tests/Generator/resource/python/python_import.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from student_map import StudentMap
from student import Student
from .student_map import StudentMap
from .student import Student
@dataclass_json
@dataclass
class Import:
Expand All @@ -10,7 +10,7 @@ class Import:

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from student import Student
from .student import Student
@dataclass_json
@dataclass
class MyMap(Student):
6 changes: 3 additions & 3 deletions tests/Generator/resource/python/python_import_ns.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from student_map import StudentMap
from student import Student
from .student_map import StudentMap
from .student import Student
@dataclass_json
@dataclass
class Import:
Expand All @@ -10,7 +10,7 @@ class Import:

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from student import Student
from .student import Student
@dataclass_json
@dataclass
class MyMap(My.Import.Student):
10 changes: 5 additions & 5 deletions tests/Generator/resource/python/python_oop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from human import Human
from .human import Human
@dataclass_json
@dataclass
class Human:
Expand All @@ -9,16 +9,16 @@ class Human:

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from human import Human
from .human import Human
@dataclass_json
@dataclass
class Student(Human):
matricle_number: str = field(default=None, metadata=config(field_name="matricleNumber"))

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from map import Map
from student import Student
from .map import Map
from .student import Student
@dataclass_json
@dataclass
class StudentMap(Map[Student]):
Expand All @@ -35,7 +35,7 @@ class Map:

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from student_map import StudentMap
from .student_map import StudentMap
@dataclass_json
@dataclass
class RootSchema:
Expand Down
8 changes: 4 additions & 4 deletions tests/Generator/resource/python/python_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class Creature:

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from creature import Creature
from .creature import Creature
@dataclass_json
@dataclass
class Human(Creature):
first_name: str = field(default=None, metadata=config(field_name="firstName"))

from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from creature import Creature
from .creature import Creature
@dataclass_json
@dataclass
class Animal(Creature):
Expand All @@ -24,8 +24,8 @@ class Animal(Creature):
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from typing import Union
from human import Human
from animal import Animal
from .human import Human
from .animal import Animal
@dataclass_json
@dataclass
class Union:
Expand Down

0 comments on commit 1ceaaac

Please sign in to comment.