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.

Can we have a "non formatted" postcode for pt_BR localization?

See original GitHub issue
  • Faker version: 3.0.0
  • OS: Windows 10 pro (x64)

I’m using Faker to generate postcode using the pt_BR localization. The example on address section shows a numeric sequence containing 8 numbers and that was what I expect.

fake.postcode()
# '35285968'

Anyway, I’m getting some problems in my tests because the output of this function sometimes returns a formatted postcode. Example:

fake.postcode()
# '35285968'    -- cool :D

fake.postcode()
# '35285-968'    -- sad :(

Expected behavior

I would like to generate postcode exactly hows the documentation says, just numbers, without any formatting. As a temporary solution, I’m using a replace to remove any - present, but I would like to have a cleaner solution using just Faker. Maybe this “formatted” version can be specified by an argument in the postcode function.

Actual behavior

Getting a non deterministic postcode, I don’t know which type of postalcode format I will get.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
maleficecommented, Dec 31, 2019

I understand where @reebr might be coming from, because in some systems, postcodes like this are only ever stored in “raw” form, i.e. no dashes, whitespaces, and what-have-you that only serve as visual aids for humans. The visual aids might only be for presentation purposes, e.g. part of the GUI/physical forms to make them easy to fill out or formatted only when displayed to end users, so formatted postcodes can be out of scope for certain use cases.

Perhaps we can do something like this (with better variable names) for similar provider methods as @dunossauro suggested. This way, it will still be backward compatible, and there is an option to only generate the raw forms.

Class Provider:

    postcode_raw_templates = ( '########', )

    postcode_all_templates = postcode_raw_templates + ( '#####-###', )

    def postcode(self, formatted=True):
        templates = self.postcode_all_templates if formatted else self.postcode_raw_templates 
        return self.bothify(self.random_element(templates)).upper()
1reaction
fcurellacommented, Dec 27, 2019

What’s the most common case use in Brazil? Do postcodes ever get printed without the hyphen?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Portuguese Brazil and Portuguese P… - Apple Developer
Hello,. I am using Xcode 8.3.2 and we made our app to support for Portuguese Portugal (PT-PT) localization and it's working fine for...
Read more >
Postal code and region issues
Postal code problem: Hello, when I try to add my debit card to account and add postal code, it says "Incorrectly formatted postcode"....
Read more >
Incorrectly formatted postal code how do I fix it
I'm trying to buy borderlands the handsome collection on my Xbox one but my postal code Is incorrectly formatted what is the correct...
Read more >
GeoIP2 and GeoLite City and Country Databases
For the following countries, we return partial postal codes with the number of characters indicated below: United States: 5; Canada: 3; United Kingdom:...
Read more >
Localizing Components | Adyen Docs
Learn how to customize the text displayed in a Component, or create your own localization. If you integrated with our JavaScript Components, you...
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