question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Returning currency without price

See original GitHub issue

Does it makes sense to return a Price instance with currency set and without a price value?

Actually if we have a substring inside a string that matches with an existing currency, it will be returned even if we are not mentioning the currency:

In [1]: Price.fromstring("STRING WITH NO PRICE BUT HAS A WORD THAT CONTAINS PART OF A CURRENCY NAME: EUROPE")
Out[1]: Price(amount=None, currency='EUR')

This happens because we use regexes to match the currencies inside a string. But this approach would create a problem when single-letter currencies is handled better (#3) .

I can see two options to handle this scenario:

  1. Consider as currency only if the substring is surrounded by whitespaces:
In [2]: Price.fromstring("SOMETHING EUROPE SOMETHING")
Out[2]: Price(amount=None, currency=None)

In [3]: Price.fromstring("SOMETHING EUR SOMETHING")
Out[3]: Price(amount=None, currency='EUR')
  1. Consider as currency only if the entire string matches exactly with the currency name:
In [4]: Price.fromstring("EUR")
Out[4]: Price(amount=None, currency='EUR')

In [5]: Price.fromstring("SOMETHING EUR SOMETHING")
Out[5]: Price(amount=None, currency=None)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Gallaeciocommented, Jul 4, 2019

I think so.

When a real-life scenario comes up where this is troublesome, we can look into improvements to solve or mitigate such issues. For example, ignore specific currency expressions on specific locales (I assume we are getting locale support à la dateparser eventually), such as ignoring “R” on languages where “R” is a common word and they always use a different text when referring to the “R” currency.

1reaction
Gallaeciocommented, Jul 4, 2019

I think option 1 is the way to go. We just need to improve the regular expressions that we use to match currencies so that “Europa” does not count as “EUR”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Where to Exchange Currency Without Paying High Fees
Trading currency at the hotel or even a currency kiosk in an airport or elsewhere in the country can be costly due to...
Read more >
Foreign Exchange | Wells Fargo
Wells Fargo account holders can order foreign currency cash online, at a branch, or at 1-800-626-9430 and have delivery within 2-7 business days....
Read more >
Placing A Foreign Currency Order FAQs - Bank of America
There is no fee for ordering foreign currency online. The bank receives compensation from the purchase and sale of foreign currency banknotes in...
Read more >
Need to return the value with an Currency sign - Stack Overflow
3. double s cannot have currency signs. · After you get the price, convert it to a string and prepend the dollar sign....
Read more >
Foreign Currency and Currency Exchange Rates - IRS
You must express the amounts you report on your U.S. tax return in U.S. dollars. ... If your functional currency is not the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found