On 1/11/2022 3:44 PM, Brett Cannon wrote:
On Tue, Jan 11, 2022 at 10:40 AM Gregory P. Smith <g...@krypto.org> wrote:
On Tue, Jan 11, 2022 at 10:29 AM Guido van Rossum
<gu...@python.org> wrote:
I personally think F-strings should not be usable as
docstrings. If you want a dynamically calculated docstring you
should assign it dynamically, not smuggle it in using a
string-like expression. We don't allow "blah {x}
blah".format(x=1) as a docstring either, not "foo %s bar" % x.
Agreed. If we wanted to remove the wart of constant f-strings
happening to work as an implementation detail in this context,
that /could/ be made into a warning. But that kind of check may
be best left to a linter for /all/ of these dynamic situations
that don't wind up populating __doc__.
Agreed on not supporting it and linters catching such a mistake.
Just to be clear, we don't support this.
>>> class C: 'foo'
...
>>> C.__doc__ == 'foo'
True
>>> class C: f'foo'
...
>>> C.__doc__ == 'foo'
False
>>> C.__doc__ is None
True
And there's a test to make sure constant f-strings are not doc strings:
https://github.com/python/cpython/blob/dce642f24418c58e67fa31a686575c980c31dd37/Lib/test/test_fstring.py#L406
Eric
-Brett
-gps
On Tue, Jan 11, 2022 at 8:12 AM Antoine Pitrou
<anto...@python.org> wrote:
On Tue, 11 Jan 2022 10:58:03 -0500
"Eric V. Smith" <e...@trueblade.com> wrote:
> Constant f-strings (those without substitutions) as doc
strings used to
> work, since the compiler turns them into normal strings.
>
> I can't find exactly where it was removed, but there was
definitely
> discussion about it. See
https://bugs.python.org/issue28739 for at least
> part of the discussion.
Ah, sorry for the misunderstanding. While the example I
showed doesn't
have any substitutions, I'm interested in the non-trivial
(non-constant)
case actually :-)
Regards
Antoine.
>
> Eric
>
> On 1/11/2022 8:41 AM, Antoine Pitrou wrote:
> > Hello,
> >
> > Currently, a f-string is not recognized as a docstring:
> >
> >>>> class C: f"foo"
> >>>> C.__doc__
> >>>>
> > This means you need to use a (admittedly easy) workaround:
> >
> >>>> class C: __doc__ = f"foo"
> >>>> C.__doc__
> > 'foo'
> >
> > Shouldn't the former be allowed for convenience?
> >
> > Regards
> >
> > Antoine.
> >
> >
> > _______________________________________________
> > Python-Dev mailing list -- python-dev@python.org
> > To unsubscribe send an email to
python-dev-le...@python.org
> >
https://mail.python.org/mailman3/lists/python-dev.python.org/
> > Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/UALMEMQ4QW7W4HE2PIBARWYBKFWJZFB4/
> > Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/37YAHCREZYZFSV4BRDKUEQAX4ZF4JTI6/
Code of Conduct: http://python.org/psf/codeofconduct/
--
--Guido van Rossum (python.org/~guido <http://python.org/~guido>)
/Pronouns: he/him //(why is my pronoun here?)/
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/35R3DCNPIQJ7ZCHTLP64IP2XZCK7QSLJ/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/QFGCXW25TZOMEN2DRVLDQ4XQQSYNNTI7/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list --python-dev@python.org
To unsubscribe send an email topython-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived
athttps://mail.python.org/archives/list/python-dev@python.org/message/J5EMBDNY52ZHZPPUZSRUOCUYF4RCSRZH/
Code of Conduct:http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/AYA4ROZZZRG6GBUMUPD5UXL5NZBSZY6A/
Code of Conduct: http://python.org/psf/codeofconduct/