-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add context manager/decorator to set context gfyear (+ misc. cleanup) #2
Conversation
1 similar comment
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeg havde forestillet mig et lille offentligt API af kun prefix()
, kprefix()
, postfix()
, parse()
, set_gfyear()
, måske get_gfyear()
samt nogle string literals til type
. Hvis de er kodet rigtigt tror jeg at de er kraftige nok til at løse de fleste problemer vi støder på.
_validate(titletupel, gfyear) | ||
def get_gfyear(argument_gfyear=None): | ||
if argument_gfyear is None: | ||
r = gfyear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det var ikke meningen at gfyear
skulle være defineret nogen steder i tktitler
. gfyear=2016
i linje ca. 9 var bare WIP til uformelle test. Jeg mener at enten skal man give funktionerne gfyear
som argument, eller sætte med override()
. I django vil man typisk sætte override(config.GFYEAR)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeg har ændret det så der kommer en ValueError hvis man ikke har sat et context gfyear.
@@ -42,14 +83,14 @@ def unicode_superscript(n): | |||
return 'T%sO%s' % (sup_fn(age - 3), root) | |||
|
|||
|
|||
def kprefix(titletupel, gfyear=gfyear, type=PREFIXTYPE_NORMAL): | |||
def ktk_prefix(titletupel, gfyear=gfyear, type=PREFIXTYPE_NORMAL): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Burde den ikke hedde tk_kprefix
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
return re.sub(r'[^0-9A-ZÆØÅ]', lambda mo: tr(mo.group(0)), s) | ||
|
||
|
||
def parse_prefix(prefix): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skal parse_prefix
, parse_postfix
, parse_relative
(og normalize
?) være offentlige? parse
skulle kunne tage sig af det hele og så er APIet vi skal vedligeholde mindre.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeg synes godt vi kan have en offentlig parse_relative
funktion da der ellers ikke er nogen nem måde at... parse relative titler på. Jeg er enig i at resten ikke bør være offentlige.
@@ -158,7 +277,7 @@ def _multireplace(string, replacements): | |||
return regexp.sub(lambda match: replacements[match.group(0)], string) | |||
|
|||
|
|||
def get_period(prefix, postfix, gfyear): | |||
def get_period(prefix, postfix, gfyear=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_period
og parse_bestfu_alias
havde jeg tænkt helt skulle erstattes helt af parse
. De er en del af filen af historisk interesse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det er fint med de nye get_period()
, men det viser vel at parse()
nemt erstatte den. Kan det ikke være op til brugeren af biblioteket at skrive den ene linje hvis det er netop period
de skal bruge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ja, lad os fjerne get_period og parse_bestfu_alias.
return wrapped | ||
|
||
|
||
def override(gfyear): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er override
det rigtige navn? Jeg havde forestillet mig noget i stil med set_gfyear
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ulempen ved navnet set_gfyear
er at man kunne forvente at man kan sætte et gfyear ved blot at kalde set_gfyear
. Det virker mærkeligt at følgende ikke duer:
set_gfyear(2013)
print(parse('GFUHI'))
Men set_gfyear
er nok stadig et bedre navn end override
.
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Der er efterhånden mere arbejde i det her PR, end master
. Jeg merger, så kan vi arbejde videre på det i master
eller lave et nyt PR.
@@ -158,7 +277,7 @@ def _multireplace(string, replacements): | |||
return regexp.sub(lambda match: replacements[match.group(0)], string) | |||
|
|||
|
|||
def get_period(prefix, postfix, gfyear): | |||
def get_period(prefix, postfix, gfyear=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det er fint med de nye get_period()
, men det viser vel at parse()
nemt erstatte den. Kan det ikke være op til brugeren af biblioteket at skrive den ene linje hvis det er netop period
de skal bruge?
|
||
|
||
def parse_bestfu_alias(alias, gfyear): | ||
def parse_bestfu_alias(alias, gfyear=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er parse_bestfu_alias()
ikke meget specifik til mailsystements problemer? Vil en mere generelt løsning ikke være en funktion der tager et alias
, root
eller title
og returnerer en kind
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jo, lad os fjerne get_period og parse_bestfu_alias. Måske skal tktitler have en funktion der kan fortælle om noget er en BEST-titel eller FU-titel, men det er ikke sikkert. (Vi kan også godt forsvare at simplificere mailsystemet og fjerne dets behov for at klassificere om en titel er BEST eller FU.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se #7.
|
||
|
||
def _validate(titletupel, gfyear): | ||
root, period = titletupel | ||
def parse_relative(input_alias): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hvad er brugsscenariet for parse_relative()
uden for tktitler
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det virker som en naturlig subrutine for parse
, og det kan blive nyttigt hvis vi f.eks. vil lave en mere intelligent håndtering af EFUIT-titler (hvor det f.eks. kan gælde at GEFUIT14 er den samme som EFUIT12).
Funktionen parse
er nok den mest anvendelige, men parse_relative
er en lidt mindre lossy parsing af aliaset. Man kunne forestille sig at lave en lossless parser (så enhver streng der repræsenterer en titel, såsom "K2TOGFUET1516", parses til en struktur der indeholder nok information til at rekonstruere den præcis samme streng), og ud fra denne vil parse_relative
være en simpel nedkogning af parserens output, og parse
vil ligeledes (som nu) være en nedkogning af parse_relative
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diskutionen er flyttet til #6.
prefix
,postfix
,kprefix
funktioner"" + ...
medassert isinstance(..., str)
get_gfyear
funktion til at oversættegfyear=None
til nuværende context gfyearoverride
context manager + decorator til at ændre context gfyearparse