Repository: jaraco/inflect (language: python)

Issue:
Incorrect indefinite article "an" returned when handling uncommon abbreviations
**Version**

`inflect==5.3.0` `python==3.9.6`

**Problem**

`inflect.engine.a()` returns the article "an" instead of "a" for some abbreviations that do not begin with vowel phonemes. Observe:

```py
>>> import inflect
>>> p = inflect.engine()
>>> p.a('JSON code block')
'a JSON code block'
>>> p.a('YAML code block')
'an YAML code block'
>>> p.a('Core ML function')
'an Core ML function'
>>> p.a('TLS connection')
'an TLS connection'
>>> p.a('CSS selector')
'an CSS selector'
```

---

Seems to be caused by the `A_abbrev` regex:

https://github.com/jaraco/inflect/blob/98e19e3eb3ad28f9fa882baaad01674c44b59952/inflect.py#L1806-L1813

which is missing the `^` start-of-line assertion, and so it matches parts of the abbreviations that would otherwise require "an," even thought they are not at the beginning of the word:

```py
>>> A_abbrev.search('TLS connection')
<re.Match object; span=(1, 3), match='LS'>
```

After fixing it:

```py
>>> p.a('JSON code block')
'a JSON code block'
>>> p.a('YAML code block')
'a YAML code block'
>>> p.a('Core ML function')
'a Core ML function'
>>> p.a('TLS connection')
'a TLS connection'
>>> p.a('SSL connection')
'an SSL connection'
>>> p.a('RSA algorithm')
'an RSA algorithm'
```


Discussion / hints:
Seems reasonable. Can you supply a patch?

Fix patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 342e41f..7d37f6d 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,9 @@
+v6.0.3
+======
+
+* #136: A/an support now more correctly honors leading
+  capitalized words and abbreviations.
+
 v6.0.2
 ======
 
diff --git a/inflect/__init__.py b/inflect/__init__.py
index 78d2e33..733aa5d 100644
--- a/inflect/__init__.py
+++ b/inflect/__init__.py
@@ -1854,7 +1854,7 @@ def get_si_pron(thecase, word, gender) -> str:
 
 A_abbrev = re.compile(
     r"""
-(?! FJO | [HLMNS]Y.  | RY[EO] | SQU
+^(?! FJO | [HLMNS]Y.  | RY[EO] | SQU
   | ( F[LR]? | [HL] | MN? | N | RH? | S[CHKLMNPTVW]? | X(YL)?) [AEIOU])
 [FHLMNRSX][A-Z]
 """,


Test patch:
diff --git a/tests/test_an.py b/tests/test_an.py
index 92182aa..7102c30 100644
--- a/tests/test_an.py
+++ b/tests/test_an.py
@@ -19,3 +19,11 @@ def test_an():
     assert p.an("unanimous decision") == "a unanimous decision"
     assert p.an("US farmer") == "a US farmer"
     assert p.an("wild PIKACHU appeared") == "a wild PIKACHU appeared"
+
+
+def test_an_abbreviation():
+    p = inflect.engine()
+
+    assert p.an("YAML code block") == "a YAML code block"
+    assert p.an("Core ML function") == "a Core ML function"
+    assert p.an("JSON code block") == "a JSON code block"