-
Notifications
You must be signed in to change notification settings - Fork 460
Number Spelling #114
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
Number Spelling #114
Conversation
|
@blagasz hey, thanks for taking the time to create a PR! Sorry for taking so long to respond. We're trying to get the project up to speed again, could you rebase your commits onto current master? There seem to be conflicts. |
|
Yes, I'll get down to it soon. Happy to hear from you :) Szabolcs
|
|
Hi @sils1297, I think I managed to rebase first time in my life :) |
|
@blagasz hey, thanks :) This PR seems to hold some merge commits and other commits related to how you did the rebase due to conflicts I presume. This makes it hard to review it properly and is not really clean with respect to the history of the project. You seem to be new to git (or at least not that much into the cool stuff it offers ;)) so let me explain how I think this can be solved best :) It's probably best to reset I'm assuming you have the remote
If at any time anything goes wrong - git is your friend and has a history of all recent actions. You can use I hope that helps a bit. If you need anything else, ping me. |
|
Hi @sils1297, thanks for the quick tutorial, I have a long way to go with git :) |
|
@erickwilder can you take a look at this one? |
|
Sorry about that, it was about the git juggling to clear the commit, not Would you like me to recommit with a better commit message? On 2 August 2015 at 13:28, Lasse Schuirmann notifications@github.com
|
|
@blagasz yes, please :) |
|
@blagasz really good commit messages are an art, if you plan to work on open source projects you'll probably learn it sooner or later, don't be frustrated about them or people letting you amend the commit message again and again - you're not the only one struggling with this. Good messages are hard to do and it takes some time to learn to do it properly. |
|
@sils1297 thanks for your support and explanation. I'm not frustrated as I know that everyone is doing this for the greater good! I tried to do my best and any further feedback is very welcome. |
|
@blagasz hey, can you add |
babel/number_spelling.py
Outdated
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.
I didn't get why you're not using super() here and let Python's inheritance system do it's job.
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.
@erickwilder I personally prefer explicity in those cases, I see only two uses of super in Babel so we'll probably want to agree on some style on this. The style guide has no information on this.
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.
@sils1297
I don't see super() as an implicit construct of the language. Also, using super() makes easier to do future refactoring that involves changes in the inheritance tree, makes easier to deal with mixins and other very useful patterns.
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.
@erickwilder the thing is super provides only one advantage, that is you don't have to do another renaming when you rename the baseclass. However super has some caveeats especially when using it for multiple inheritance because you have to make clear which arguments are passed where and such things. That being said, super is complex, I'm sure there are many people out there who don't understand it fully (especially in multiple inheritance cases, I also count me to this group of people btw.) while providing only a very small advantage that is neglectible for many users doing renamings via IDEs. We had some discussions about super usage in general at coala and decided collectively against it. I know that opinions on this are split, your call.
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.
What I see is that super() itself is not complex. Multiple inheritance on the other hand is. I can't blame super() for multiple inheritance complexities (kinda like blame the gun by killing someone, not the killer).
If you're gonna change the way we call parent class methods, this should be done consistently across the library and I think that is is not the subject of this pull request. Just to not extend this discussion, I do think that we can use super() here (it's already used, minimally but still used as yourself pointed out) and on a separate thread we can discuss/change the way we handle how to deal with methods overwritten by child classes.
@sils1297 seems reasonable?
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.
Just for the record. super() without arguments only works in Python 3. Python 2 requires two arguments for super().
Highly recommended talk: Super considered super! by Raymond Hettinger
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.
Ok, I will incorporate all the changes. Should I make a new pull request or
still modify the current commit.
I have nothing against super, I decided to use the simple way to make it
simple, but I could add super no problem.
I also add the factoring of the locale specific code and some loading
mechanism.
I'll leave out decimals global context.
Get rid of unused files.
Get back to you as soon as I have the time to finish all that.
Szabolcs
On 4 Aug 2015 22:09, "Isaac Jurado" notifications@github.com wrote:
In babel/number_spelling.py
#114 (comment):
self.value = sum(d.value_dec(10)_*e for e,d in enumerate(self.digits)) # might use int
- def len(self):
return len(self.digits)
- def iter(self):
for digit in self.digits:yield digit+class DigitContext(ContextBase):
- """
- Represent one digit of a number and its context
- """
- def init(self, value, number, side, group, index):
ContextBase.**init**(self)Just for the record. super() without arguments only works in Python 3.
Python 2 requires two arguments for super().Highly recommended talk: Super considered super! by Raymond Hettinger
https://www.youtube.com/watch?v=EiOglTERPEo—
Reply to this email directly or view it on GitHub
https://github.com/mitsuhiko/babel/pull/114/files#r36235049.
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.
On Tue, Aug 4, 2015 at 10:20 PM, blagasz notifications@github.com wrote:
In babel/number_spelling.py:
self.value = sum(d.value_dec(10)_*e for e,d in enumerate(self.digits)) # might use int
- def len(self):
return len(self.digits)
- def iter(self):
for digit in self.digits:yield digit+class DigitContext(ContextBase):
- """
- Represent one digit of a number and its context
- """
- def init(self, value, number, side, group, index):
ContextBase.**init**(self)Ok, I will incorporate all the changes. Should I make a new pull
request or still modify the current commit.
Since @sils1297 and @erickwilder must be having a hard time sweeping all
the staled pull requests, I believe it is easier for them to just
overwrite the current pull request.
At least, that is what I try to do. A combination of git commit --amend or git rebase -i, followed by git push -f.
Isaac Jurado
"The noblest pleasure is the joy of understanding"
Leonardo da Vinci
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.
babel/number_spelling.py
Outdated
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.
This approach is not optimal since it changes the global (per thread) decimal context, which can break user code that relies on decimal context stability, in case a user changes it.
The best way to solve this is to use a decimal context manager. For example:
https://github.com/etanol/babel/commit/7ced0273020427cad3bc321001b64f769cf2f85d
Current coverage is
|
babel/number_spelling/__init__.py
Outdated
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.
I still think that exceptions should be in their own module, just like babel.exceptions does.
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.
Agreed, this also forces good naming as its not file local.
|
It is already there in the |
I don't see any text for that |
|
Sorry I haven't staged that... On 24 September 2015 at 17:37, Lasse Schuirmann notifications@github.com
|
|
@sils1297 I pushed everything now, sorry for the fuss! |
|
Rebased and line removed :) |
|
Cool, thanks :) This is growing very good, many revisions -> high quality :) |
|
Oh @etanol could you please take at least a short look at this? You might have valuable additions. |
|
@sils1297 I had this PR merged in my custom branch. However, it seems to have changed slightly since then. I will take a look to the new |
|
@blagasz hey, so I begin to like this code more and more. I think it would be good to have a few more tests for some corner cases. The patch coverage (https://codecov.io/github/python-babel/babel/compare/46a234e...7fbf2c5) shows that there are some cases like some exceptions and a break statement and so on missing, I'd love to see a few more tests for those to make this even more future proof. Those exceptions e.g. should be rather easy to test. |
|
And well there's the conflict again probably because of the CHANGES file so this'll probably reoccur. Maybe wait with the rebase a bit if it's cumbersome for you. |
|
Leaving marked as scheduled for review because I (or somebody else) still needs another deep look at this code and I can't do that right now. |
|
@sils1297 I was trying to improve the coverage and hope you'll will still like the code after a deeper look. I'm working on the Chinese simplified spelling right now, but I will put it in a separate pull. Also I am planning to write a short tutorial for the framework to help collaboration to produce implementations for other locals quickly. |
|
@blagasz tests fail. We'll wait with review until this is repaired as this is not eligible for merge as long as any CI fails. |
|
Yes, sorry, I know about the problem, some of the new tests fail on 3.* and On 29 September 2015 at 14:28, Lasse Schuirmann notifications@github.com
|
New code almost exclusively resides in babel/numbers/_spelling/. A generic helper structure is created and a reference implementation for Hungarian is provided (locale_hu.py). A draft implementation for English (British) is also given (locale_en.py). The babel/numbers.py became a subpackage and modified to give an interface for new code through the spell_number function. Test suite restructered and amended at tests/numbers/ and tests/test_dates.py was modified due to changes in pytz. Fixes #179
|
@sils1297 all set :) |
|
I'm a strong -1 on pulling this in. The reason for this is that Babel ultimately only allows two sources of information in the library: It either has to come from the olson database or CLDR. Historically there have been only very few exceptions to this rule and they were made for very specific reasons. The number spelling is specified in the |
|
@blagasz I do tend to agree with @mitsuhiko . It is ultimately my fault to not have this stopped earlier. Still the experience you gained might be very helpful understanding and implementing spelling support using CLDR. Are you still interested in working on #179 ? |
|
@sils1297 and @mitsuhiko no hard feelings at all, but the strong -1 from Armin was a tough one :) I completely agree with Armin and I was myself a little bit surprised when he said two years ago, that my approach "Sounds like something that can find its way into Babel". I was wondering about the CLDR support and every other possibilities then and I came up with my solution as the only viable alternative. The CLDR rbnf rules sounded interesting but it was insufficient and unimplemented in CLDR two years ago, I checked out the new version and it seems to have improved a lot, now it seems something implementable. It is also my fault that I did not checked that earlier as a long time passed since I started my implementation. Maybe I was in love with my own code :) Anyway, I started to read the docs for the rule based formatting and I am happy to implement the engine (or transform an existing implementation into Python). I am busier these days, but try to have some advancement in that soon. Personally I gained a lot by this experience (failure) and I am happy to help in any way in the future. |
|
@blagasz you can accept the invitation for our org on https://github.com/python-babel so I can assign you to the bug. Many thanks for sticking with us. |
A pure Python engine for parsing RBNF rules. The rules are incomplete in many cases, fractional number spelling is hardly supported. Based on an earlier discussion: python-babel#114 and referenced in python-babel#179
A pure Python engine for parsing RBNF rules. The rules are incomplete in many cases, fractional number spelling is hardly supported. Based on an earlier discussion: python-babel#114 and referenced in python-babel#179
A pure Python engine for parsing RBNF rules. The rules are incomplete in many cases, fractional number spelling is hardly supported. Based on an earlier discussion: python-babel#114 and referenced in python-babel#179
Reinstantiated pull request to make it a clear changeset.
The spelling framework tries to be as generic as possible, but still structured upon my original non-generic implementation of the Hungarian spelling. The Hungarian language in general and the spelling in particular is very complicated, so I hope that the generic helper structure that is suitable for an easy implementation of the Hungarian spelling would be also suitable for all the other languages.