Skip to content
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

It's time for f-strings #91

Closed
prjemian opened this issue Jan 4, 2021 · 4 comments · Fixed by #115
Closed

It's time for f-strings #91

prjemian opened this issue Jan 4, 2021 · 4 comments · Fixed by #115
Labels
Milestone

Comments

@prjemian
Copy link
Contributor

prjemian commented Jan 4, 2021

Saw that and decided to wait until after this PR since that goes beyond the scope of the PR. Let's apply f-strings to the overall code base in a separate issue.

Originally posted by @prjemian in #85 (comment)

@prjemian prjemian added the task label Jan 4, 2021
@prjemian prjemian added this to the v0.3.16 milestone Jan 4, 2021
@prjemian
Copy link
Contributor Author

prjemian commented Jan 6, 2021

For example:

hklpy/hkl/sample.py

Lines 395 to 405 in 9892f20

def _repr_info(self):
repr = [
"name={!r}".format(self.name),
"lattice={!r}".format(self.lattice),
"ux={!r}".format(self.ux),
"uy={!r}".format(self.uy),
"uz={!r}".format(self.uz),
"U={!r}".format(self.U),
"UB={!r}".format(self.UB),
"reflections={!r}".format(self.reflections),
]

where '{!r}'.format(value) is explained: https://stackoverflow.com/questions/33097143/what-is-the-difference-between-r-and-r-in-python

@prjemian
Copy link
Contributor Author

prjemian commented Jan 6, 2021

Here:

(bluesky_2021_1) prjemian@poof ~/.../Bluesky/hklpy $ git grep ".format(" | grep -v /archive/
hkl/diffract.py:        logger.debug('pseudo to real: {}'.format(solutions))
hkl/engine.py:            return '{} (internally: {})'.format(self._name, name)
hkl/engine.py:        repr = ['name={!r}'.format(self.name),
hkl/engine.py:                'limits={!r}'.format(self.limits),
hkl/engine.py:                'value={!r}'.format(self.value),
hkl/engine.py:                'fit={!r}'.format(self.fit),
hkl/engine.py:                'inverted={!r}'.format(self.inverted),
hkl/engine.py:            repr.append('units={!r}'.format(self.user_units))
hkl/engine.py:            repr.append('units={!r}'.format(self.default_units))
hkl/engine.py:        return '{}({})'.format(self.__class__.__name__,
hkl/engine.py:        return '{}({})'.format(self.__class__.__name__,
hkl/engine.py:        repr = ['{!r}'.format(self.positions),
hkl/engine.py:                'units={!r}'.format(self._engine.units),
hkl/engine.py:        return '{}({})'.format(self.__class__.__name__,
hkl/engine.py:        repr = ['parameters={!r}'.format(self.parameters),
hkl/engine.py:                'pseudo_axes={!r}'.format(dict(self.pseudo_axes)),
hkl/engine.py:                'mode={!r}'.format(self.mode),
hkl/engine.py:                'modes={!r}'.format(self.modes),
hkl/engine.py:                'units={!r}'.format(self.units),
hkl/engine.py:        return '{}({})'.format(self.__class__.__name__,
hkl/sample.py:                'Lattice parameter "{}" unset or invalid' "".format(k)
hkl/sample.py:            "name={!r}".format(self.name),
hkl/sample.py:            "lattice={!r}".format(self.lattice),
hkl/sample.py:            "ux={!r}".format(self.ux),
hkl/sample.py:            "uy={!r}".format(self.uy),
hkl/sample.py:            "uz={!r}".format(self.uz),
hkl/sample.py:            "U={!r}".format(self.U),
hkl/sample.py:            "UB={!r}".format(self.UB),
hkl/sample.py:            "reflections={!r}".format(self.reflections),
hkl/sample.py:        return "{}({})".format(
hkl/sample.py:            "reflection_measured_angles={!r}".format(
hkl/sample.py:            "reflection_theoretical_angles={!r}".format(
hkl/sample.py:        return "{}({})".format(self.__class__.__name__, ", ".join(info))
hkl/util.py:          'disabled ({})'.format(ex), file=sys.stderr)
hkl/util.py:                return '({}: {})'.format(ex.__class__.__name__, ex)

@danielballan
Copy link
Member

This issue title made me smile. 👍

@prjemian
Copy link
Contributor Author

Standard f-strings are OK but do not use the newer syntax that came with py3.7, allowing f"{obj = }" which is self-descriptive printing.

prjemian added a commit that referenced this issue Apr 16, 2021
prjemian added a commit that referenced this issue Apr 16, 2021
prjemian added a commit that referenced this issue Apr 16, 2021
prjemian added a commit that referenced this issue Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants