MCPcopy Create free account
hub / github.com/ipython/traitlets / add_article

Function add_article

traitlets/utils/descriptions.py:145–173  ·  view source on GitHub ↗

Returns the string with a prepended article. The input does not need to begin with a character. Parameters ---------- name : str Name to which to prepend an article definite : bool (default: False) Whether the article is definite or not. Indefinite artic

(name: str, definite: bool = False, capital: bool = False)

Source from the content-addressed store, hash-verified

143
144
145def add_article(name: str, definite: bool = False, capital: bool = False) -> str:
146 """Returns the string with a prepended article.
147
148 The input does not need to begin with a character.
149
150 Parameters
151 ----------
152 name : str
153 Name to which to prepend an article
154 definite : bool (default: False)
155 Whether the article is definite or not.
156 Indefinite articles being 'a' and 'an',
157 while 'the' is definite.
158 capital : bool (default: False)
159 Whether the added article should have
160 its first letter capitalized or not.
161 """
162 if definite:
163 result = "the " + name
164 else:
165 first_letters = re.compile(r"[\W_]+").sub("", name)
166 if first_letters[:1].lower() in "aeiou":
167 result = "an " + name
168 else:
169 result = "a " + name
170 if capital:
171 return result[0].upper() + result[1:]
172 else:
173 return result
174
175
176def repr_type(obj: Any) -> str:

Callers 3

infoMethod · 0.85
describeFunction · 0.85
class_ofFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…