Skip to content
Snippets Groups Projects
Commit 46354f4d authored by Patrick Koppenburg's avatar Patrick Koppenburg :leaves:
Browse files

Merge branch 'erodrigu-add-pyupgrade' into 'master'

Modernise code for Python 3.9+

See merge request !927
parents f83b2564 951f3ca4
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!927Modernise code for Python 3.9+
Pipeline #5812787 passed
......@@ -30,6 +30,11 @@ repos:
"--skip",
"DaVinciExamples/python/DaVinciExamples/tupling/option_davinci_tupling_from_xgen.py"
]
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
hooks:
- id: pyupgrade
args: ["--py39-plus"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
......
......@@ -53,7 +53,7 @@ def all_variables(pvs, dtf, mctruth, ptype, candidates=None, ftAlg=None):
functors are listed in order of https://lhcbdoc.web.cern.ch/lhcbdoc/moore/master/selection/thor_functors_reference.html#module-Functors
"""
if ptype not in [_basic, _composite]:
Exception("I want {0} or {1}. Got {2}".format(_basic, _composite, ptype))
Exception(f"I want {_basic} or {_composite}. Got {ptype}")
all_vars = FunctorCollection({})
comp = _composite == ptype or _toplevel == ptype # is composite
......@@ -289,11 +289,7 @@ def all_variables(pvs, dtf, mctruth, ptype, candidates=None, ftAlg=None):
all_vars.update({"TX": F.TX})
all_vars.update({"TY": F.TY})
print(
"### For {0} returning variables {1}".format(
ptype, all_vars.functor_dict.keys()
)
)
print(f"### For {ptype} returning variables {all_vars.functor_dict.keys()}")
return all_vars
......@@ -337,7 +333,7 @@ def event_variables(PVs, ODIN, decreports, lines):
if decreports:
evt_vars.update({"TCK": F.TCK(decreports)})
print("### For event returning variables {0}".format(evt_vars.functor_dict.keys()))
print(f"### For event returning variables {evt_vars.functor_dict.keys()}")
return evt_vars
......
......@@ -55,13 +55,11 @@ class check_wrapper:
def check(self):
sorted_set_all = sorted(
set(
[
entry
for entry in self.functorcollection.__all__
if entry not in exclude_functor_collections
]
)
{
entry
for entry in self.functorcollection.__all__
if entry not in exclude_functor_collections
}
)
sorted_set_called = sorted(self.called)
if sorted_set_all != sorted_set_called:
......
......@@ -9,7 +9,7 @@
# or submit itself to any jurisdiction. #
###############################################################################
from typing import Iterable
from collections.abc import Iterable
import pandas as pd
from ROOT import RDataFrame
import math
......
......@@ -39,7 +39,7 @@ def make_tight_d2kk():
)
vertex_code = F.CHI2DOF < 30
print("### Kaons are {0}".format(kaons))
print(f"### Kaons are {kaons}")
filtered_kaons = ParticleRangeFilter(Input=kaons, Cut=F.FILTER(F.PROBNN_K > 0.5))
p = TwoBodyCombiner(
......@@ -52,7 +52,7 @@ def make_tight_d2kk():
CompositeCut=vertex_code,
).OutputParticles
print("### Returning {0}".format(p))
print(f"### Returning {p}")
return p
......@@ -60,7 +60,7 @@ def main(options: Options):
vd0s = make_std_loose_d2kk()
td0s = make_tight_d2kk()
print("### vD0s {0} and tD0s {1}".format(vd0s, td0s))
print(f"### vD0s {vd0s} and tD0s {td0s}")
pdt = PrintDecayTree(name="PrintD0s", Input=vd0s) # keyed container
pdt2 = PrintDecayTree(name="PrintTightD0s", Input=td0s)
......
......@@ -50,7 +50,7 @@ class DVNode(namedtuple("DVNode", ["node", "extra_outputs"])): # noqa
)
if extra_outputs is None:
extra_outputs = []
return super(DVNode, cls).__new__(cls, node, frozenset(extra_outputs))
return super().__new__(cls, node, frozenset(extra_outputs))
@property
def name(self):
......
###############################################################################
# (c) Copyright 2019-2022 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2019-2023 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......@@ -36,7 +36,7 @@ def html_visit_graphviz_wrapped(self, *args, **kwargs):
anchor_index = len(self.body)
anchor_tmp = "REPLACE_ME"
self.body.append('<a href="{}">'.format(anchor_tmp))
self.body.append(f'<a href="{anchor_tmp}">')
try:
html_visit_graphviz(self, *args, **kwargs)
except nodes.SkipNode:
......
......@@ -46,7 +46,7 @@ def GetPageInfo(script):
dict: a dictionary with information to write the documentation page
"""
info = {"title": None, "description": None, "running": None, "yaml": None}
f = open(script, "r")
f = open(script)
active_comment = False
active_key = None
line_start_code = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment