1
0
forked from ScoDoc/ScoDoc

modernized type checking

This commit is contained in:
Emmanuel Viennet 2021-07-11 22:32:01 +02:00
parent def8b1e6a2
commit e08f35cb80
16 changed files with 38 additions and 41 deletions

View File

@ -174,7 +174,7 @@ def scodoc7func(context):
pos_arg_values.append(context)
else:
# XXX Convert to regular string for ScoDoc8/Python 2 #py3
if type(req_args[arg_name]) == str:
if isinstance(req_args[arg_name], str):
pos_arg_values.append(req_args[arg_name].encode("utf-8"))
else:
pos_arg_values.append(req_args[arg_name])
@ -187,7 +187,7 @@ def scodoc7func(context):
elif arg_name in req_args:
# set argument kw optionnel
# XXX Convert to regular string for ScoDoc8/Python 2 #py3
if type(req_args[arg_name]) == str:
if isinstance(req_args[arg_name], str):
kwargs[arg_name] = req_args[arg_name].encode("utf-8")
else:
kwargs[arg_name] = req_args[arg_name]
@ -236,7 +236,7 @@ class ScoDoc7Context(object):
logging.getLogger(__name__).info("populating context %s" % self)
for k in globals_dict:
if (not k.startswith("_")) and (
type(globals_dict[k]) == types.FunctionType
isinstance(globals_dict[k], types.FunctionType)
):
setattr(self, k, globals_dict[k].__get__(self))

View File

@ -27,7 +27,6 @@
"""Calculs sur les notes et cache des resultats
"""
from types import FloatType
import time
import pdb
import inspect
@ -349,7 +348,7 @@ class NotesTable(object):
(self.moy_ue[ue_id][etudid], etudid) for etudid in self.moy_ue[ue_id]
]
ue_eff = len(
[x for x in val_ids if type(x[0]) == FloatType]
[x for x in val_ids if isinstance(x[0], float)]
) # nombre d'étudiants avec une note dans l'UE
val_ids.sort(key=row_key)
ue_rangs[ue_id] = (
@ -845,7 +844,7 @@ class NotesTable(object):
mu["event_date"] = event_date
# - ECTS ? ("pot" pour "potentiels" car les ECTS ne seront acquises qu'apres validation du jury
if (
type(mu["moy"]) == FloatType
isinstance(mu["moy"], float)
and mu["moy"] >= self.parcours.NOTES_BARRE_VALID_UE
):
mu["ects_pot"] = ue["ects"] or 0.0
@ -1182,7 +1181,7 @@ class NotesTable(object):
]
ue_cap["moy_ue"] = moy_ue_cap
if (
type(moy_ue_cap) == FloatType
isinstance(moy_ue_cap, float)
and moy_ue_cap >= self.parcours.NOTES_BARRE_VALID_UE
):
if not cnx:

View File

@ -81,7 +81,6 @@ XXX A vérifier:
"""
import collections
from types import FloatType
import re
import time
import datetime
@ -154,7 +153,7 @@ def code_scodoc_to_apo(code):
def _apo_fmt_note(note):
"Formatte une note pour Apogée (séparateur décimal: ',')"
if not note and type(note) != FloatType:
if not note and isinstance(note, float):
return ""
try:
val = float(note)

View File

@ -238,7 +238,7 @@ class TypeParcours(object):
ue_status
for ue_status in ues_status
if ue_status["coef_ue"] > 0
and type(ue_status["moy"]) == float
and isinstance(ue_status["moy"], float)
and ue_status["moy"] < self.get_barre_ue(ue_status["ue"]["type"])
]

View File

@ -30,7 +30,6 @@
import traceback
import pprint
from types import FloatType
import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb
@ -355,7 +354,7 @@ def do_moduleimpl_moyennes(context, nt, mod):
if etudid in eval_rattr["notes"]:
note = eval_rattr["notes"][etudid]["value"]
if note != None and note != NOTES_NEUTRALISE and note != NOTES_ATTENTE:
if type(R[etudid]) != FloatType:
if isinstance(R[etudid], float):
R[etudid] = note
else:
note_sur_20 = note * 20.0 / eval_rattr["note_max"]

View File

@ -29,9 +29,9 @@
""" Excel file handling
"""
import time, datetime
from types import IntType, FloatType, LongType
from pyExcelerator import *
# #sco8 #py3 XXX TODO A revoir utiliser d'autres modules
# from pyExcelerator import *
import app.scodoc.sco_utils as scu
from app.scodoc import notesdb
@ -226,10 +226,9 @@ class ScoExcelSheet(object):
co = 0
for c in l:
# safety net: allow only str, int and float
if type(c) == LongType:
c = int(c) # assume all ScoDoc longs fits in int !
elif type(c) not in (IntType, FloatType):
c = str(c).decode(scu.SCO_ENCODING)
# #py3 #sco8 A revoir lors de la ré-écriture de ce module
# XXX if type(c) not in (IntType, FloatType):
# c = str(c).decode(scu.SCO_ENCODING)
ws0.write(li, co, c, self.get_cell_style(li, co))
co += 1
@ -263,9 +262,9 @@ def Excel_SimpleTable(titles=[], lines=[[]], SheetName="feuille", titlesStyles=[
for it in l:
cell_style = default_style
# safety net: allow only str, int and float
if type(it) == LongType:
if isinstance(it, LongType): # XXX
it = int(it) # assume all ScoDoc longs fits in int !
elif type(it) not in (IntType, FloatType):
elif type(it) not in (IntType, FloatType): # XXX A REVOIR
it = str(it).decode(scu.SCO_ENCODING)
cell_style = text_style
ws0.write(li, col, it, cell_style)

View File

@ -508,7 +508,7 @@ def retreive_formsemestre_from_request(context, REQUEST):
formsemestre_id = group["formsemestre_id"]
elif group_ids:
if group_ids:
if type(group_ids) == str:
if isinstance(group_ids, str):
group_id = group_ids
else:
# prend le semestre du 1er groupe de la liste:
@ -781,7 +781,10 @@ def _make_listes_sem(context, sem, REQUEST=None, with_absences=True):
query_args = cgi.parse_qs(REQUEST.QUERY_STRING)
if "head_message" in query_args:
del query_args["head_message"]
destination = "%s?%s" % (REQUEST.URL, six.moves.urllib.parse.urlencode(query_args, True))
destination = "%s?%s" % (
REQUEST.URL,
six.moves.urllib.parse.urlencode(query_args, True),
)
destination = destination.replace(
"%", "%%"
) # car ici utilisee dans un format string !

View File

@ -991,7 +991,7 @@ def formsemestre_fix_validation_ues(context, formsemestre_id, REQUEST=None):
moy_ue = ue_status["moy"]
if valid_semestre:
if (
type(moy_ue) == FloatType
isinstance(moy_ue, float)
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
):
code_ue = ADM
@ -1001,7 +1001,7 @@ def formsemestre_fix_validation_ues(context, formsemestre_id, REQUEST=None):
if not decision_sem["assidu"]:
code_ue = AJ
elif (
type(moy_ue) == FloatType
isinstance(moy_ue, float)
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
):
code_ue = ADM

View File

@ -29,7 +29,6 @@
"""
import operator
from types import FloatType, IntType, LongType
from functools import reduce
@ -125,17 +124,17 @@ class NoteVector(object):
return binary_op(x, self.v, operator.floordiv)
def isScalar(x):
return isinstance(x, FloatType) or isinstance(x, IntType) or isinstance(x, LongType)
def is_scalar(x):
return isinstance(x, (float, int))
def binary_op(x, y, op):
if isScalar(x):
if isScalar(y):
if is_scalar(x):
if is_scalar(y):
x, y = [x], [y]
else:
x = [x] * len(y)
if isScalar(y):
if is_scalar(y):
y = [y] * len(x)
if len(x) != len(y):

View File

@ -317,7 +317,7 @@ class DisplayedGroupsInfos(object):
REQUEST=None,
):
# log('DisplayedGroupsInfos %s' % group_ids)
if type(group_ids) == str:
if isinstance(group_ids, str):
if group_ids:
group_ids = [group_ids] # cas ou un seul parametre, pas de liste
else:

View File

@ -779,7 +779,7 @@ def adm_get_fields(titles, formsemestre_id):
def adm_convert_text(v):
if type(v) == float:
if isinstance(v, float):
return "{:g}".format(v) # evite "1.0"
return v

View File

@ -27,7 +27,6 @@
"""Semestres: gestion parcours DUT (Arreté du 13 août 2005)
"""
from types import FloatType
import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb
@ -417,7 +416,7 @@ class SituationEtudParcoursGeneric(object):
self.etudid
)
self.moy_gen = self.nt.get_etud_moy_gen(self.etudid)
self.barre_moy_ok = (type(self.moy_gen) == FloatType) and (
self.barre_moy_ok = (isinstance(self.moy_gen, float)) and (
self.moy_gen >= (self.parcours.BARRE_MOY - scu.NOTES_TOLERANCE)
)
# conserve etat UEs
@ -921,11 +920,11 @@ def formsemestre_validate_ues(
else:
# log('%s: %s: ue_status=%s' % (formsemestre_id,ue_id,ue_status))
if (
type(ue_status["moy"]) == FloatType
isinstance(ue_status["moy"], float)
and ue_status["moy"] >= nt.parcours.NOTES_BARRE_VALID_UE
):
code_ue = ADM
elif type(ue_status["moy"]) != FloatType:
elif isinstance(ue_status["moy"], float):
# aucune note (pas de moyenne) dans l'UE: ne la valide pas
code_ue = None
elif valid_semestre:

View File

@ -835,7 +835,7 @@ def _pvjury_pdf_type(
def _format_pv_cell(x):
"""convert string to paragraph"""
if type(x) == bytes:
if isinstance(x, bytes):
return Paragraph(SU(x), cell_style)
else:
return x

View File

@ -246,7 +246,7 @@ def module_tag_set(context, module_id="", taglist=[], REQUEST=None):
#
if not taglist:
taglist = []
elif type(taglist) == bytes:
elif isinstance(taglist, bytes):
taglist = taglist.split(",")
taglist = [t.strip() for t in taglist]
log("module_tag_set: module_id=%s taglist=%s" % (module_id, taglist))

View File

@ -132,7 +132,7 @@ def fmt_note(val, note_max=None, keep_numeric=False):
return "EXC" # excuse, note neutralise
if val == NOTES_ATTENTE:
return "ATT" # attente, note neutralisee
if type(val) == float or type(val) == int:
if isinstance(val, float) or isinstance(val, int):
if note_max != None and note_max > 0:
val = val * 20.0 / note_max
if keep_numeric:
@ -434,7 +434,7 @@ def unescape_html_dict(d):
indices = list(range(len(d)))
for k in indices:
v = d[k]
if type(v) == bytes:
if isinstance(v, bytes):
d[k] = unescape_html(v)
elif isiterable(v):
unescape_html_dict(v)

View File

@ -63,7 +63,7 @@ class ApoEtapeVDI(object):
"""
if other is None:
return -1
if type(other) == str:
if isinstance(other, str):
other = ApoEtapeVDI(other)
if self.vdi and other.vdi: