Skip to content

Commit

Permalink
feat: print info that f-string will be fixable in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Nov 20, 2024
1 parent 3dab716 commit b3614c1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/inline_snapshot/_adapter/value_adapter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

import ast
import warnings

from inline_snapshot._code_repr import value_code_repr
from inline_snapshot._unmanaged import Unmanaged
from inline_snapshot._unmanaged import update_allowed
from inline_snapshot._utils import value_to_token
from inline_snapshot.syntax_warnings import InlineSnapshotInfo

from .._change import Replace
from .adapter import Adapter
Expand Down Expand Up @@ -31,6 +35,16 @@ def assign(self, old_value, old_node, new_value):
else:
new_token = value_to_token(new_value)

if isinstance(old_node, ast.JoinedStr):
if not old_value == new_value:
warnings.warn_explicit(
f"inline-snapshot will be able to fix f-strings in the future.\nThe current string value is:\n {new_value!r}",
filename=self.context._source.filename,
lineno=old_node.lineno,
category=InlineSnapshotInfo,
)
return old_value

if not old_value == new_value:
flag = "fix"
elif (
Expand Down
12 changes: 2 additions & 10 deletions src/inline_snapshot/_inline_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
from ._utils import value_to_token


class NotImplementedYet(Exception):
pass


snapshots = {} # type: Dict[Tuple[int, int], SnapshotReference]

_active = False
Expand All @@ -54,10 +50,6 @@ def _return(result):
return result


class InlineSnapshotSyntaxWarning(Warning):
pass


class Flags:
"""
fix: the value needs to be changed to pass the tests
Expand Down Expand Up @@ -140,10 +132,10 @@ def _visible_value(self):
return self._old_value

def _get_changes(self) -> Iterator[Change]:
raise NotImplementedYet()
raise NotImplementedError()

def _new_code(self):
raise NotImplementedYet()
raise NotImplementedError()

def __repr__(self):
return repr(self._visible_value())
Expand Down
4 changes: 4 additions & 0 deletions src/inline_snapshot/syntax_warnings.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class InlineSnapshotSyntaxWarning(Warning):
pass


class InlineSnapshotInfo(Warning):
pass

0 comments on commit b3614c1

Please sign in to comment.