-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
f-string types #811
Comments
must |
hmmmmmm, ts only allows |
ehh, are we talking about python? |
>>> def f[T: str](t: T) -> f"asdf{T}":
... return f"asdf{t}"
...
>>> f.__annotations__
{'t': T, 'return': 'asdfT'} maybe you can hack around this by monkeypatching |
yeah, just referencing prior art I think ts kinda went with the idea of static string values are allowed, and when there is class A:
def __format__(self, spec) -> f"A({str})": ...
def f(a: A) -> f"asdf {A}": # same as f"asdf A({str})"
return f"asdf {a}" does that mean: class object:
def __str__(self) -> f"<{self.__module__}.{self.__class__.__name__} object at {str}>" |
don't think that would work for |
ah I must've read over the "ts" in the comment I was referencing there, mea culpa
Yea, good point...
Yea I suppose that makes sense. But now that I see this, I realize that this could indeed become very complicated. >>> class StringSpy(str):
... def __str__(self):
... return super().__str__() + " sabotage"
... def __format__(self, spec):
... return StringSpy(super().__format__(spec))
...
>>> f"{StringSpy('nuclear reactor')}"
'nuclear reactor sabotage'
>>> type(_)
<class '__main__.StringSpy'> So I can see why TS went about it the way they did. I guess that later on
I haven't yet read it, but at first glance https://peps.python.org/pep-0750/ looks like it might be able to help with this. |
but that's nonsense anyway, that should return |
but shouldn't it then be def __str__[ModuleT: str, ClassNameT: str](
self: HasModule[ModuleT] & HasClass[HasName[ClassNameT]],
) -> f"<{ModuleT}.{ClassNameT} object at {str}>" |
no, it should be |
The text was updated successfully, but these errors were encountered: