Soni L. writes:
> in any case the whole thing I'm arguing for in this thread, is to *draw
> parallels* between module imports and resource imports.
The only parallel I see is that you read a file found on a path.
Modules are *special* because they're the only built-in object that
normally
On Jan 21, 2020, at 14:30, Chris Angelico wrote:
>
> On Wed, Jan 22, 2020 at 9:17 AM Andrew Barnert wrote:
>>
>>> On Jan 21, 2020, at 12:29, Chris Angelico wrote:
>>>
>>> For non-dataclass classes, it would be extremely helpful to have an
>>> easy helper function available:
>>>
>>> class
On Mon, Jan 20, 2020 at 4:15 PM Soni L. wrote:
>
> I generally do that but I was frustrated and exhausted. That is, that
> may have been slightly passive-aggressive... Sorry.
>
and yet you barely trimmed this one ;-)
in any case the whole thing I'm arguing for in this thread, is to *draw
>
On Tue, Jan 21, 2020 at 12:15 PM Christopher Barker
wrote:
> You *may* be able to do something directly with strings, but most likely
> you'll pass it off to something else: a template renderer, JSON parser,
> what have you. And I can’t think of a single instance where you would just
> want the
On Jan 20, 2020, at 16:17, Soni L. wrote:
>
> in any case the whole thing I'm arguing for in this thread, is to *draw
> parallels* between module imports and resource imports. ppl talk about it
> like it would be "confusingly similar" but I argue that it would be
> *non-confusingly* similar
On Jan 19, 2020, at 20:54, Guido van Rossum wrote:
>
> Actually, `bar = foo` is more likely to be detected by mypy, since it is
> probably a type error (unless bar isn't used or is only used in an `Any`
> context). For mypy, flagging bare `foo` is harder, because we would have to
> introduce
Well, mypy is often used primarily as a linter on steroids.
Anyway, agreed with your point!
On Tue, Jan 21, 2020 at 10:22 AM Andrew Barnert wrote:
> On Jan 19, 2020, at 20:54, Guido van Rossum wrote:
> >
> > Actually, `bar = foo` is more likely to be detected by mypy, since it is
> probably a
I have worked with both C# and Python for a while now and there is one feature
of C# I'm missing in the Python language.
This feature is the "nameof" operator.
(https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof).
The place I use this the most in C# is in
On Tue, Jan 21, 2020 at 1:49 PM Johan Vergeer
wrote:
> I have worked with both C# and Python for a while now and there is one
> feature of C# I'm missing in the Python language.
>
> This feature is the "nameof" operator. (
>
On Jan 21, 2020, at 09:13, Christopher Barker wrote:
>
> For (2) — see above— I want the relevant Python object, not just the string
> or bytes. A good example of this is the utilities (img2py I think) that come
> with wxPython: They bundle up a set of images into a Python module that
>
On Wed, Jan 22, 2020 at 5:48 AM Johan Vergeer wrote:
>
> I have worked with both C# and Python for a while now and there is one
> feature of C# I'm missing in the Python language.
>
> This feature is the "nameof" operator.
>
On 1/21/2020 2:25 PM, Chris Angelico wrote:
Hmm. Maybe this should be a recipe in the docs, or something: "how to
make a repr that reconstructs an object".
def describe(obj, attrs):
attrs = [f"{a}={getattr(obj, a)!r}" for a in attrs]
return f"{type(obj).__name__}({", ".join(attrs)})"
On Wed, Jan 22, 2020 at 6:43 AM Eric V. Smith wrote:
>
> On 1/21/2020 2:25 PM, Chris Angelico wrote:
> >
> > Hmm. Maybe this should be a recipe in the docs, or something: "how to
> > make a repr that reconstructs an object".
> >
> > def describe(obj, attrs):
> > attrs = [f"{a}={getattr(obj,
Isn't the name of the class more reliably `type(ins).__qualname__`?
At any rate, I've actually wished for a shortcut to the name of an object's
class- of the name of the class object itself- many times in the past.
Mostly when writing reprs and exception messages. Not sure if that is in
line with
On 1/21/20 1:42 PM, Johan Vergeer wrote:
def __repr__(self):
return f"{nameof(Person)}({nameof(self.name)}: {self.name},
{nameof(self.age)}: {self.age})"
I'm trying to understand what you are looking for. Why isn't the above
line just:
return f"Person(name: {self.name},
On 1/21/20 3:11 PM, Ned Batchelder wrote:
On 1/21/20 1:42 PM, Johan Vergeer wrote:
def __repr__(self):
return f"{nameof(Person)}({nameof(self.name)}: {self.name},
{nameof(self.age)}: {self.age})"
I'm trying to understand what you are looking for. Why isn't the
above line
I believe Python 3.8's '=' f-string specifier (
https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging)
combined with __name__ does what you'd want:
return f'{self.__class__.__name__}({self.name=}, {self.age=})'
Outside of the __name__ dance,
Why? That looks like more code to accomplish exactly the same thing.
On Tue, Jan 21, 2020 at 1:49 PM Johan Vergeer
wrote:
> I have worked with both C# and Python for a while now and there is one
> feature of C# I'm missing in the Python language.
>
> This feature is the "nameof" operator. (
>
Currently, the reprlib module [1] offers an "alternate repr()
implementation", and focuses mainly on guarding the length of the
returned string. I propose to broaden its scope slightly and make it
the place to add helper functions for writing __repr__(), and to add
one such function.
A dataclass
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` or `docstring` parameter to
On Jan 21, 2020, at 10:48, Johan Vergeer wrote:
>
> I have worked with both C# and Python for a while now and there is one
> feature of C# I'm missing in the Python language.
>
> This feature is the "nameof" operator.
>
On Jan 21, 2020, at 13:32, Andrew Barnert wrote:
>
> On Jan 21, 2020, at 10:48, Johan Vergeer wrote:
>>
>> def __repr__(self):
>> return f"{nameof(Person)}({nameof(self.name)}: {self.name},
>> {nameof(self.age)}: {self.age})"
>
> What would the semantics of nameof be in Python?
On 1/21/2020 4:32 PM, 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 source code
On 1/21/2020 4:50 PM, Eric V. Smith wrote:
On 1/21/2020 4:32 PM, 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
On 01/21/2020 02:08 PM, Chris Angelico wrote:
Yes, that's exactly what I mean, and exactly why self.__class__ is
used here. If you actually want "Person" even if it's actually a
Martian, you can use __class__.__name__ rather than
self.__class__.__name__ to get that.
Gotcha, thanks. I'm still
On 01/21/2020 11:25 AM, Chris Angelico wrote:
I'm not sure how this compares to what nameof(Person) should return,
but the above idiom (or something like it) is very common in Python,
as it allows repr to acknowledge a subclass. If you create "class
Martian(Person): pass", then a Martian's repr
On Wed, Jan 22, 2020 at 9:04 AM Ethan Furman wrote:
>
> On 01/21/2020 11:25 AM, Chris Angelico wrote:
>
> > I'm not sure how this compares to what nameof(Person) should return,
> > but the above idiom (or something like it) is very common in Python,
> > as it allows repr to acknowledge a
On Jan 21, 2020, at 12:29, Chris Angelico wrote:
>
> For non-dataclass classes, it would be extremely helpful to have an
> easy helper function available:
>
> class Spam:
> def __repr__(self):
> return reprlib.kwargs(self, ["quality", "recipe", "ham"])
>
> The implementation for this
On Wed, Jan 22, 2020 at 9:17 AM Andrew Barnert wrote:
>
> On Jan 21, 2020, at 12:29, Chris Angelico wrote:
> >
> > For non-dataclass classes, it would be extremely helpful to have an
> > easy helper function available:
> >
> > class Spam:
> > def __repr__(self):
> > return
29 matches
Mail list logo