Repository: joke2k/faker
Pull request #1848 (2023-04-22 05:52:53)

add a separate basic number format for US
issue ticket: https://github.com/joke2k/faker/issues/1847

### What does this change

Adds a 'basic phone number' type to en_US to comply with some form requirements, as well as a unit test.

### What was wrong

Some forms do not allow for phone formats with extensions or country codes. As a result, the faker get_phone function for en_US doesn't work for all cases. 

### How this fixes it

Adds a function that allows the user to only use 'basic' ten-digit phone numbers and standard formatting. 



Patch:
diff --git a/.bumpversion.cfg b/.bumpversion.cfg
index 56902152..8fa57ba9 100644
--- a/.bumpversion.cfg
+++ b/.bumpversion.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 18.4.0
+current_version = 18.5.1
 files = VERSION faker/__init__.py docs/conf.py
 commit = True
 tag = True
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5223fe01..df636a63 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,14 @@
 ## Changelog
 
-### [v18.4.0- 2023-04-06](https://github.com/joke2k/faker/compare/v18.3.4...v18.4.0)
+### [v18.5.1 - 2023-04-24](https://github.com/joke2k/faker/compare/v18.5.1...v18.5.1)
+
+* Fix release.
+
+### [v18.5.0 - 2023-04-24](https://github.com/joke2k/faker/compare/v18.4.0...v18.5.0)
+
+* Add `de_DE` `swift_location_codes`. Thanks @MiloniAtal.
+
+### [v18.4.0 - 2023-04-06](https://github.com/joke2k/faker/compare/v18.3.4...v18.4.0)
 
 * Add currency symbols for all listed currencies. Thanks @evoludigit.
 
diff --git a/VERSION b/VERSION
index 5b9720f0..82f73fb7 100644
--- a/VERSION
+++ b/VERSION
@@ -1,1 +1,1 @@
-18.4.0
+18.5.1
diff --git a/docs/conf.py b/docs/conf.py
index 5f9f1901..4203f397 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -51,9 +51,9 @@ copyright = "2014, Daniele Faraglia"
 # built documents.
 #
 # The short X.Y version.
-version = "18.4.0"
+version = "18.5.1"
 # The full version, including alpha/beta/rc tags.
-release = "18.4.0"
+release = "18.5.1"
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/faker/__init__.py b/faker/__init__.py
index 09f055a4..bb673856 100644
--- a/faker/__init__.py
+++ b/faker/__init__.py
@@ -2,6 +2,6 @@ from faker.factory import Factory
 from faker.generator import Generator
 from faker.proxy import Faker
 
-VERSION = "18.4.0"
+VERSION = "18.5.1"
 
 __all__ = ("Factory", "Generator", "Faker")
diff --git a/faker/providers/phone_number/en_US/__init__.py b/faker/providers/phone_number/en_US/__init__.py
index bb0b77df..ac1367e8 100644
--- a/faker/providers/phone_number/en_US/__init__.py
+++ b/faker/providers/phone_number/en_US/__init__.py
@@ -37,3 +37,14 @@ class Provider(PhoneNumberProvider):
         "001-###-###-####x####",
         "001-###-###-####x#####",
     )
+
+    basic_formats = (
+        # basic 10-digit phone number format with no extensions
+        "##########",
+        "###-###-####",
+        "(###)###-####",
+    )
+
+    def basic_phone_number(self) -> str:
+        pattern: str = self.random_element(self.basic_formats)
+        return self.numerify(self.generator.parse(pattern))


Test patch:
diff --git a/tests/providers/test_phone_number.py b/tests/providers/test_phone_number.py
index 8fd54ec3..1bb38daf 100644
--- a/tests/providers/test_phone_number.py
+++ b/tests/providers/test_phone_number.py
@@ -364,3 +364,18 @@ class TestFrFr:
         for _ in range(num_samples):
             phone_number = faker.phone_number()
             assert any([re.match(pattern, phone_number) for pattern in patterns])
+
+
+class TestEnUs:
+    """Test En_US phone provider methods"""
+
+    def test_basic_phone_number(self, faker, num_samples):
+        pattern_no_whitespaces: Pattern = re.compile(
+            r"\d{9}",
+        )
+        pattern_dashes: Pattern = re.compile(r"\d{3}-\d{3}-\d{4}")
+        pattern_parens: Pattern = re.compile(r"\(\d{3}\)\d{3}-\d{4}")
+        patterns = [pattern_no_whitespaces, pattern_dashes, pattern_parens]
+        for _ in range(num_samples):
+            phone_number = faker.basic_phone_number()
+            assert any([re.match(pattern, phone_number) for pattern in patterns])