> On 21 Jan 2020, at 22:50, Andrew Barnert via Python-ideas
> wrote:
>
> But it seems like nameof(self.age) always has to be just “age”, which you
> already have to type inside the nameof if you want it to be findable, so
> it’ll never be useful. Anywhere you could write `{nameof(self.age)}`
On Tue, Jan 21, 2020 at 02:25:56PM -0500, Ricky Teachey wrote:
> Isn't the name of the class more reliably `type(ins).__qualname__`?
Depends on whether you want the plain old name of the class, or the
qualified name of the class.
> At any rate, I've actually wished for a shortcut to the name of
On Wed, Jan 22, 2020 at 02:39:57PM +0900, Stephen J. Turnbull wrote:
> I see some parallels, but I'm definitely in the camp of "confusingly
> similar" rather than "instructively similar", and I definitely don't
> see a need for a syntax change to enable importing anything inside
> expressions.
+1
> On 22 Jan 2020, at 11:50, Steven D'Aprano wrote:
>
> But what should these things do?
>
>x = y = z = 1
>nameof(1)
Syntax error.
>nameof(z)
"z"
>nameof("Gumby")
Syntax error.
>nameof(mysequence[0])
Syntax error.
> It isn't clear what precisely counts as the name o
On 22/01/2020 12:03, Anders Hovmöller wrote:
He was pretty clear in saying he wanted the same thing as in C#. That no one in
this thread seems to have looked that up is really not his fault in my opinion.
Oh, plenty of people have looked it up. The problem is that it relies
on part of the na
On 1/22/20 7:08 AM, Rhodri James wrote:
On 22/01/2020 12:03, Anders Hovmöller wrote:
He was pretty clear in saying he wanted the same thing as in C#. That
no one in this thread seems to have looked that up is really not his
fault in my opinion.
Oh, plenty of people have looked it up. The pro
> On 22 Jan 2020, at 13:23, Rhodri James wrote:
>
> On 22/01/2020 12:03, Anders Hovmöller wrote:
>> He was pretty clear in saying he wanted the same thing as in C#. That no one
>> in this thread seems to have looked that up is really not his fault in my
>> opinion.
>
> Oh, plenty of people
On Wed, Jan 22, 2020 at 11:57 PM Richard Damon wrote:
> Thus nameof(x) can ONLY be "x" in Python (or an error is x isn't
> something that is a name), as at best x is referring to some object, but
> that object doesn't have a special name to refer to it that is its
> holder. Yes, one example wher
You can achieve this now with my executing library:
https://github.com/alexmojaki/executing
```
import ast
import inspect
import executing
def nameof(_):
frame = inspect.currentframe().f_back
call = executing.Source.executing(frame).node
arg = call.args[0]
if isinstance(arg, ast
> On 22 Jan 2020, at 14:39, Alex Hall wrote:
>
>
> You can achieve this now with my executing library:
> https://github.com/alexmojaki/executing
>
> ```
> import ast
> import inspect
>
> import executing
>
>
> def nameof(_):
> frame = inspect.currentframe().f_back
> call = execut
On 1/22/20 8:05 AM, Anders Hovmöller wrote:
On 22 Jan 2020, at 13:23, Rhodri James wrote:
On 22/01/2020 12:03, Anders Hovmöller wrote:
He was pretty clear in saying he wanted the same thing as in C#. That no one in
this thread seems to have looked that up is really not his fault in my opin
On Tue, Jan 21, 2020 at 12:55 PM wrote:
> Currently, there is no way to add docstrings to fields in dataclasses.
> PEP257 talks about attribute docstrings (a string literal following an
> assignment), but these are visual only and not accessible at runtime. My
> suggestion would be a simple `doc`
The doctrings for fields are usually inside the class object docstring
(formatting of which depending on the docstring style). As CHB said, there
isn't a way to add them to objects.
Maybe there's a way to make this happen, though? Like:
@dataclass
@build_docstring(format="sphinx")
class LameClass
The fact that i.__doc__ doesn't work is actually a strong argument. You would
have to do dataclasses.fields(my_obj)[0].__doc__, which is already complex
enough. At that point using metadata probably makes more sense.
Thank you for your response.
___
Py
On Jan 22, 2020, at 13:01, Christopher Barker wrote:
>
>
>> On Tue, Jan 21, 2020 at 12:55 PM wrote:
>
>> Currently, there is no way to add docstrings to fields in dataclasses.
>> PEP257 talks about attribute docstrings (a string literal following an
>> assignment), but these are visual only
On Wed, Jan 22, 2020, 7:21 PM Andrew Barnert via Python-ideas <
[email protected]> wrote:
> On Jan 22, 2020, at 13:01, Christopher Barker wrote:
>
>
> On Tue, Jan 21, 2020 at 12:55 PM wrote:
>
>> Currently, there is no way to add docstrings to fields in dataclasses.
>> PEP257 talks about
On Tue, Jan 21, 2020, at 16:32, Andrew Barnert via Python-ideas wrote:
> What would the semantics of nameof be in Python? Would it just be
> lambda obj: obj.__name__? Or some fancy inspect-module style chain of
> “try this, then that, then the other”? Or does it need to look at the
> compiled so
17 matches
Mail list logo