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

Add context manager/decorator to set context gfyear (+ misc. cleanup) #2

Merged
merged 33 commits into from
Dec 24, 2016

Conversation

Mortal
Copy link
Contributor

@Mortal Mortal commented Dec 22, 2016

  • Omdøb prefix, postfix, kprefix funktioner
  • Erstat "" + ... med assert isinstance(..., str)
  • Tilføj get_gfyear funktion til at oversætte gfyear=None til nuværende context gfyear
  • Tilføj override context manager + decorator til at ændre context gfyear
  • Implementér parse

@coveralls
Copy link

Coverage Status

Coverage increased (+3.3%) to 75.748% when pulling 544eb41 on pull_2 into 95701f4 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+3.3%) to 75.748% when pulling 544eb41 on pull_2 into 95701f4 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+7.7%) to 80.151% when pulling 1de4e0f on pull_2 into 95701f4 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+7.7%) to 80.151% when pulling 1de4e0f on pull_2 into 95701f4 on master.

Copy link
Member

@neic neic left a 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
Copy link
Member

@neic neic Dec 22, 2016

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).

Copy link
Contributor Author

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):
Copy link
Member

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?

Copy link
Contributor Author

@Mortal Mortal Dec 23, 2016

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):
Copy link
Member

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.

Copy link
Contributor Author

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_periodog parse_bestfu_alias havde jeg tænkt helt skulle erstattes helt af parse. De er en del af filen af historisk interesse.

Copy link
Member

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?

Copy link
Contributor Author

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):
Copy link
Member

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.

Copy link
Contributor Author

@Mortal Mortal Dec 23, 2016

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.

@coveralls
Copy link

coveralls commented Dec 23, 2016

Coverage Status

Coverage increased (+18.04%) to 90.476% when pulling 1b19a5a on pull_2 into 95701f4 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+18.04%) to 90.476% when pulling 940871f on pull_2 into 95701f4 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+18.04%) to 90.476% when pulling 940871f on pull_2 into 95701f4 on master.

@coveralls
Copy link

coveralls commented Dec 23, 2016

Coverage Status

Coverage increased (+18.09%) to 90.529% when pulling 9d9e775 on pull_2 into 95701f4 on master.

Copy link
Member

@neic neic left a 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):
Copy link
Member

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):
Copy link
Member

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?

Copy link
Contributor Author

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.)

Copy link
Member

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):
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@neic neic merged commit 44bf78d into master Dec 24, 2016
@neic neic mentioned this pull request Dec 24, 2016
@neic neic deleted the pull_2 branch January 15, 2017 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants