Skip to content

Commit e4e93af

Browse files
authored
Merge pull request #401 from delph-in/change-requests-to-httpx
Change requests to httpx
2 parents abeedb5 + c63897f commit e4e93af

File tree

13 files changed

+47
-50
lines changed

13 files changed

+47
-50
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
### Unreleased
44

5+
### Maintenance
6+
7+
* Removed `requirements.txt`; it was unnecessary and out of date
8+
* Replaced `requests` dependency with `httpx`
9+
510

611
## [v1.10.0]
712

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Questions about PyDelphin can be asked on the [DELPH-IN Discourse
1919
site](https://delphinqa.ling.washington.edu/) in the "PyDelphin Tools"
2020
category.
2121

22-
For bug requests, please provide the following, if possible:
22+
For bug reports, please provide the following, if possible:
2323

2424
* a minimal working example
2525
* version of PyDelphin (and relevant dependencies)

delphin/dmrs/_operations.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"""
55

66
import warnings
7-
from typing import Callable, Dict, List, Optional, cast
7+
from typing import Callable, Optional, cast
88

99
from delphin import dmrs, mrs, scope, variable
1010

11-
_HCMap = Dict[str, mrs.HCons]
12-
_IdMap = Dict[str, int]
11+
_HCMap = dict[str, mrs.HCons]
12+
_IdMap = dict[str, int]
1313

1414

1515
def from_mrs(
@@ -32,7 +32,11 @@ def from_mrs(
3232
DMRSError when conversion fails.
3333
"""
3434
hcmap: _HCMap = {hc.hi: hc for hc in m.hcons}
35-
reps = scope.representatives(m, priority=representative_priority)
35+
# TODO: fix type annotation with scope.representatives overloads?
36+
reps = cast(
37+
dict[str, list[mrs.EP]],
38+
scope.representatives(m, priority=representative_priority)
39+
)
3640
# EP id to node id map; create now to keep ids consistent
3741
id_to_nid: _IdMap = {ep.id: i
3842
for i, ep in enumerate(m.rels, dmrs.FIRST_NODE_ID)}
@@ -83,7 +87,7 @@ def _mrs_get_top(
8387
return top
8488

8589

86-
def _mrs_to_nodes(m: mrs.MRS, id_to_nid: _IdMap) -> List[dmrs.Node]:
90+
def _mrs_to_nodes(m: mrs.MRS, id_to_nid: _IdMap) -> list[dmrs.Node]:
8791
nodes = []
8892
for ep in m.rels:
8993
node_id = id_to_nid[ep.id]
@@ -117,10 +121,10 @@ def _mrs_to_nodes(m: mrs.MRS, id_to_nid: _IdMap) -> List[dmrs.Node]:
117121
def _mrs_to_links(
118122
m: mrs.MRS,
119123
hcmap: _HCMap,
120-
reps: scope.ScopeMap,
124+
reps: dict[str, list[mrs.EP]], # MRS-specific ScopeMap
121125
iv_to_nid: _IdMap,
122126
id_to_nid: _IdMap
123-
) -> List[dmrs.Link]:
127+
) -> list[dmrs.Link]:
124128
links = []
125129
# links from arguments
126130
for src, roleargs in m.arguments().items():

delphin/scope.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Structures and operations for quantifier scope in DELPH-IN semantics.
33
"""
44

5-
from typing import Dict, Iterable, List, Mapping, Optional, Tuple
5+
from typing import Iterable, Mapping, Optional
66

77
# Default modules need to import the PyDelphin version
88
from delphin.__about__ import __version__ # noqa: F401
@@ -29,11 +29,11 @@
2929
ScopeLabel = str
3030
ScopeRelation = str
3131
ScopeMap = Mapping[ScopeLabel, Predications]
32-
DescendantMap = Mapping[Identifier, List[Predication]]
33-
ScopalRoleArgument = Tuple[Role, ScopeRelation, Identifier]
34-
ScopalArgumentStructure = Mapping[Identifier, List[ScopalRoleArgument]]
32+
DescendantMap = Mapping[Identifier, list[Predication]]
33+
ScopalRoleArgument = tuple[Role, ScopeRelation, Identifier]
34+
ScopalArgumentStructure = Mapping[Identifier, list[ScopalRoleArgument]]
3535
# Regarding literal types, see: https://www.python.org/dev/peps/pep-0563/
36-
ScopeEqualities = Iterable[Tuple[ScopeLabel, ScopeLabel]]
36+
ScopeEqualities = Iterable[tuple[ScopeLabel, ScopeLabel]]
3737

3838

3939
# Exceptions
@@ -87,7 +87,7 @@ def scopal_arguments(self, scopes=None) -> ScopalArgumentStructure:
8787
"""
8888
raise NotImplementedError()
8989

90-
def scopes(self) -> Tuple[ScopeLabel, ScopeMap]:
90+
def scopes(self) -> tuple[ScopeLabel, ScopeMap]:
9191
"""
9292
Return a tuple containing the top label and the scope map.
9393
@@ -117,7 +117,7 @@ def conjoin(scopes: ScopeMap, leqs: ScopeEqualities) -> ScopeMap:
117117
>>> {lbl: [p.id for p in ps] for lbl, ps in conjoined.items()}
118118
{'h1': ['e2'], 'h2': ['x4', 'e6']}
119119
"""
120-
scopemap: Dict[ScopeLabel, List[Predication]] = {}
120+
scopemap: dict[ScopeLabel, list[Predication]] = {}
121121
for component in _connected_components(list(scopes), leqs):
122122
chosen_label = next(iter(component))
123123
scopemap[chosen_label] = []
@@ -155,13 +155,13 @@ def descendants(x: ScopingSemanticStructure,
155155
if scopes is None:
156156
_, scopes = x.scopes()
157157
scargs = x.scopal_arguments(scopes=scopes)
158-
descs: Dict[Identifier, List[Predication]] = {}
158+
descs: dict[Identifier, list[Predication]] = {}
159159
for p in x.predications:
160160
_descendants(descs, p.id, scargs, scopes)
161161
return descs
162162

163163

164-
def _descendants(descs: Dict[Identifier, List[Predication]],
164+
def _descendants(descs: dict[Identifier, list[Predication]],
165165
id: Identifier,
166166
scargs: ScopalArgumentStructure,
167167
scopes: ScopeMap) -> None:
@@ -203,7 +203,7 @@ def representatives(x: ScopingSemanticStructure, priority=None) -> ScopeMap:
203203
204204
3. Prefer tensed over untensed eventualities
205205
206-
4. Finally, prefer prefer those appearing first in *x*
206+
4. Finally, prefer those appearing first in *x*
207207
208208
The definition of "tensed" vs "untensed" eventualities is
209209
grammar-specific, but it is used by several large grammars. If a
@@ -233,7 +233,7 @@ def representatives(x: ScopingSemanticStructure, priority=None) -> ScopeMap:
233233
descs = {id: set(d.id for d in ds)
234234
for id, ds in descendants(x, scopes).items()}
235235

236-
reps: Dict[ScopeLabel, List[Predication]] = {
236+
reps: dict[ScopeLabel, list[Predication]] = {
237237
label: [] for label in scopes
238238
}
239239
for label, scope in scopes.items():

delphin/web/client.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from urllib.parse import urljoin
77

8-
import requests
8+
import httpx
99

1010
from delphin import interface
1111

@@ -60,7 +60,7 @@ def interact(self, datum, params=None, headers=None):
6060
A Response containing the results, if the request was
6161
successful.
6262
Raises:
63-
requests.HTTPError: if the status code was not 200
63+
httpx.HTTPError: if the status code was not 200
6464
"""
6565
if params is None:
6666
params = {}
@@ -71,11 +71,10 @@ def interact(self, datum, params=None, headers=None):
7171
hdrs.update(headers)
7272

7373
url = urljoin(self.server, self.task)
74-
r = requests.get(url, params=params, headers=hdrs)
75-
if r.status_code == 200:
76-
return _HTTPResponse(r.json())
77-
else:
78-
r.raise_for_status()
74+
with httpx.Client() as client:
75+
r = client.get(url, params=params, headers=hdrs)
76+
r.raise_for_status()
77+
return _HTTPResponse(r.json())
7978

8079
def process_item(self, datum, keys=None, params=None, headers=None):
8180
"""
@@ -132,7 +131,7 @@ def parse(input, server=DEFAULT_SERVER, params=None, headers=None):
132131
A Response containing the results, if the request was
133132
successful.
134133
Raises:
135-
requests.HTTPError: if the status code was not 200
134+
httpx.HTTPError: if the status code was not 200
136135
"""
137136
return next(parse_from_iterable([input], server, params, headers), None)
138137

@@ -154,7 +153,7 @@ def parse_from_iterable(
154153
Yields:
155154
Response objects for each successful response.
156155
Raises:
157-
requests.HTTPError: for the first response with a status code
156+
httpx.HTTPError: for the first response with a status code
158157
that is not 200
159158
"""
160159
client = Parser(server)
@@ -176,7 +175,7 @@ def generate(input, server=DEFAULT_SERVER, params=None, headers=None):
176175
A Response containing the results, if the request was
177176
successful.
178177
Raises:
179-
requests.HTTPError: if the status code was not 200
178+
httpx.HTTPError: if the status code was not 200
180179
"""
181180
return next(generate_from_iterable([input], server, params, headers), None)
182181

@@ -198,7 +197,7 @@ def generate_from_iterable(
198197
Yields:
199198
Response objects for each successful response.
200199
Raises:
201-
requests.HTTPError: for the first response with a status code
200+
httpx.HTTPError: for the first response with a status code
202201
that is not 200
203202
"""
204203
client = Generator(server)

delphin/web/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def configure(api, parser=None, generator=None, testsuites=None):
3737
:class:`GenerationServer` instances directly.
3838
3939
Args:
40-
api: an instance of :class:`falcon.API`
40+
api: an instance of :class:`falcon.App`
4141
parser: a path to a grammar or a :class:`ParseServer` instance
4242
generator: a path to a grammar or a :class:`GenerationServer`
4343
instance

docs/api/delphin.web.client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ servers that implement the DELPH-IN Web API described here:
1111

1212
.. note::
1313

14-
Requires `requests` (https://pypi.python.org/pypi/requests). This
14+
Requires `httpx` (https://www.python-httpx.org/). This
1515
dependency is satisfied if you install PyDelphin with the ``[web]``
1616
extra (see :doc:`../guides/setup`).
1717

docs/api/delphin.web.server.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ such as the following example:
2929
3030
from delphin.web import server
3131
32-
application = falcon.API()
32+
application = falcon.App()
3333
3434
server.configure(
3535
application,

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
# Example configuration for intersphinx: refer to the Python standard library.
188188
intersphinx_mapping = {
189189
'python': ('https://docs.python.org/3', None),
190-
'requests': ('https://requests.readthedocs.io/en/master/', None),
190+
# 'httpx': ('https://www.python-httpx.org/', None),
191191
'falcon': ('https://falcon.readthedocs.io/en/2.0.0/', None)
192192
}
193193

docs/guides/setup.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Module or Function Dependencies Notes
2828
================================= ============ ===========================
2929
:mod:`delphin.ace` ACE_ Linux and Mac only
3030
:mod:`delphin.highlight` Pygments_
31-
:mod:`delphin.web.client` requests_ ``[web]`` extra
31+
:mod:`delphin.web.client` httpx_ ``[web]`` extra
3232
:mod:`delphin.web.server` Falcon_ ``[web]`` extra
3333
:mod:`delphin.codecs.dmrspenman` Penman_
3434
:mod:`delphin.codecs.edspenman` Penman_
@@ -41,7 +41,7 @@ are not listed in the table above).
4141

4242
.. _ACE: http://sweaglesw.org/linguistics/ace/
4343
.. _Pygments: https://pygments.org/
44-
.. _requests: http://python-requests.org/
44+
.. _httpx: https://www.python-httpx.org/
4545
.. _Falcon: https://falcon.readthedocs.io/
4646
.. _Penman: https://github.com/goodmami/penman
4747
.. _regex: https://bitbucket.org/mrabarnett/mrab-regex/

0 commit comments

Comments
 (0)