Skip to content

Commit

Permalink
🐛 use isinstance() or is instead of ==
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 committed Jul 2, 2024
1 parent 4dd9b6c commit c160492
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ormdantic/generator/_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def _get_value(
)
if model_field.allow_none and optionals_use_none:
return None
if type_ == str or issubclass(type_, pydantic.types.ConstrainedStr):
if isinstance(type_, type(str)) or issubclass(type_, pydantic.types.ConstrainedStr):
return RandomStrValue(model_field)
if type_ in [int, float] or isinstance(type_, pydantic.types.ConstrainedNumberMeta):
return RandomNumberValue(model_field)
if type_ == bool:
if isinstance(type_, type(bool)):
return random.random() > 0.5
if issubclass(type_, types.NoneType):
return None
Expand Down
4 changes: 2 additions & 2 deletions ormdantic/generator/_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ def _get_result_schema(

@staticmethod
def _sql_type_to_py(model_type: type[ModelType], column: str, value: Any) -> Any:
if model_type.__fields__[column].type_ == dict:
if isinstance(model_type.__fields__[column].type_, type(dict)):
return {} if value is None else json.loads(value)
if model_type.__fields__[column].type_ == list:
if isinstance(model_type.__fields__[column].type_, type(list)):
return [] if value is None else json.loads(value)
if value is None:
return None
Expand Down
4 changes: 2 additions & 2 deletions ormdantic/generator/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _get_column(
) -> Column[Any] | None:
outer_origin = get_origin(field.outer_type_)
origin = get_origin(field.type_)
if outer_origin and outer_origin == list:
if outer_origin and outer_origin is list:
return self._get_column_from_type_args(
field_name, field, **kwargs
) # pragma: no cover
Expand All @@ -91,7 +91,7 @@ def _get_column(
return self._get_column_from_type_args(field_name, field, **kwargs)
else:
raise TypeConversionError(field.type_) # pragma: no cover
if get_origin(field.outer_type_) == dict:
if get_origin(field.outer_type_) is dict:
return Column(field_name, JSON, **kwargs)
if field.type_ is uuid.UUID:
col_type = (
Expand Down
2 changes: 1 addition & 1 deletion ormdantic/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get(self, table_data: OrmTable[ModelType]) -> dict[str, Relationship]:
)

continue
if get_origin(field.outer_type_) == list or field.type_ == ForwardRef(
if get_origin(field.outer_type_) is list or field.type_ == ForwardRef(
f"{related_table.model.__name__}"
):
raise UndefinedBackReferenceError(
Expand Down

0 comments on commit c160492

Please sign in to comment.