Skip to content

Commit

Permalink
Merge pull request #3717 from Zac-HD/with-urlopen
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD authored Aug 12, 2023
2 parents c7a85b8 + 24c71a6 commit e3848b0
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 100 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch ensures that we always close the download connection in
:class:`~hypothesis.database.GitHubArtifactDatabase`.
6 changes: 3 additions & 3 deletions hypothesis-python/src/hypothesis/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,11 @@ def _get_bytes(self, url: str) -> Optional[bytes]: # pragma: no cover
"Authorization": f"Bearer {self.token}",
},
)
warning_message = None
response_bytes: Optional[bytes] = None
try:
response = urlopen(request)
response_bytes = response.read()
warning_message = None
with urlopen(request) as response:
response_bytes = response.read()
except HTTPError as e:
if e.code == 401:
warning_message = (
Expand Down
6 changes: 3 additions & 3 deletions hypothesis-python/src/hypothesis/extra/_array_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ def broadcastable_shapes(
# We are unsure if gufuncs allow frozen dimensions to be optional, but it's
# easy enough to support here - and so we will unless we learn otherwise.
_DIMENSION = r"\w+\??" # Note that \w permits digits too!
_SHAPE = r"\((?:{0}(?:,{0})".format(_DIMENSION) + r"{0,31})?\)"
_ARGUMENT_LIST = "{0}(?:,{0})*".format(_SHAPE)
_SHAPE = rf"\((?:{_DIMENSION}(?:,{_DIMENSION})" + r"{0,31})?\)"
_ARGUMENT_LIST = f"{_SHAPE}(?:,{_SHAPE})*"
_SIGNATURE = rf"^{_ARGUMENT_LIST}->{_SHAPE}$"
_SIGNATURE_MULTIPLE_OUTPUT = r"^{0}->{0}$".format(_ARGUMENT_LIST)
_SIGNATURE_MULTIPLE_OUTPUT = rf"^{_ARGUMENT_LIST}->{_ARGUMENT_LIST}$"


class _GUfuncSig(NamedTuple):
Expand Down
13 changes: 4 additions & 9 deletions hypothesis-python/src/hypothesis/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,9 @@ class StateMachineMeta(type):
def __setattr__(cls, name, value):
if name == "settings" and isinstance(value, Settings):
raise AttributeError(
(
"Assigning {cls}.settings = {value} does nothing. Assign "
"to {cls}.TestCase.settings, or use @{value} as a decorator "
"on the {cls} class."
).format(cls=cls.__name__, value=value)
f"Assigning {cls.__name__}.settings = {value} does nothing. Assign "
f"to {cls.__name__}.TestCase.settings, or use @{value} as a decorator "
f"on the {cls.__name__} class."
)
return super().__setattr__(name, value)

Expand Down Expand Up @@ -908,10 +906,7 @@ def __init__(self, machine):
)

def __repr__(self):
return "{}(machine={}({{...}}))".format(
self.__class__.__name__,
self.machine.__class__.__name__,
)
return f"{self.__class__.__name__}(machine={self.machine.__class__.__name__}({{...}}))"

def do_draw(self, data):
if not any(self.is_valid(rule) for rule in self.rules):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def calc_is_empty(self, recur):

def __repr__(self):
if not hasattr(self, "_cached_repr"):
self._cached_repr = "{!r}.flatmap({})".format(
self.flatmapped_strategy,
get_pretty_function_description(self.expand),
)
self._cached_repr = f"{self.flatmapped_strategy!r}.flatmap({get_pretty_function_description(self.expand)})"
return self._cached_repr

def do_draw(self, data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,7 @@ def calc_is_cacheable(self, recur):

def __repr__(self):
if not hasattr(self, "_cached_repr"):
self._cached_repr = "{!r}.map({})".format(
self.mapped_strategy,
get_pretty_function_description(self.pack),
)
self._cached_repr = f"{self.mapped_strategy!r}.map({get_pretty_function_description(self.pack)})"
return self._cached_repr

def do_validate(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version 2023062400, Last Updated Sat Jun 24 07:07:01 2023 UTC
# Version 2023081200, Last Updated Sat Aug 12 07:07:01 2023 UTC
AAA
AARP
ABB
Expand Down Expand Up @@ -558,7 +558,6 @@ HOSPITAL
HOST
HOSTING
HOT
HOTELES
HOTELS
HOTMAIL
HOUSE
Expand Down Expand Up @@ -803,7 +802,6 @@ MTR
MU
MUSEUM
MUSIC
MUTUAL
MV
MW
MX
Expand Down Expand Up @@ -844,7 +842,6 @@ NISSAY
NL
NO
NOKIA
NORTHWESTERNMUTUAL
NORTON
NOW
NOWRUZ
Expand Down Expand Up @@ -890,7 +887,6 @@ PARS
PARTNERS
PARTS
PARTY
PASSAGENS
PAY
PCCW
PE
Expand Down Expand Up @@ -1162,7 +1158,6 @@ THEATRE
TIAA
TICKETS
TIENDA
TIFFANY
TIPS
TIRES
TIROL
Expand Down Expand Up @@ -1253,7 +1248,6 @@ VOTING
VOTO
VOYAGE
VU
VUELOS
WALES
WALMART
WALTER
Expand Down
6 changes: 3 additions & 3 deletions hypothesis-python/tests/common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def run():
v = getattr(x, s.name)
# Check if it has a dynamically defined default and if so skip comparison.
if getattr(settings, s.name).show_default:
assert v == s.default, "({!r} == x.{}) != (s.{} == {!r})".format(
v, s.name, s.name, s.default
)
assert (
v == s.default
), f"({v!r} == x.{s.name}) != (s.{s.name} == {s.default!r})"

settings.register_profile(
"default",
Expand Down
5 changes: 3 additions & 2 deletions hypothesis-python/tests/numpy/test_floor_ceil.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def test_our_floor_and_ceil_avoid_numpy_rounding(value):
f = floor(a)
c = ceil(a)

assert type(f) == int
assert type(c) == int
# Check *exact* type - we don't want to allow a subclass of int here
assert type(f) == int # noqa
assert type(c) == int # noqa

# Using math.floor or math.ceil for these values would give an incorrect result.
with warnings.catch_warnings():
Expand Down
20 changes: 10 additions & 10 deletions requirements/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
#
# ./build.sh upgrade-requirements
#
async-timeout==4.0.2
async-timeout==4.0.3
# via redis
attrs==23.1.0
# via hypothesis (hypothesis-python/setup.py)
black @ git+https://github.com/psf/black.git@eedfc3832290b3a32825b3c0f2dfa3f3d7ee9d1c
# via -r requirements/coverage.in
click==8.1.4
click==8.1.6
# via
# -r requirements/coverage.in
# black
coverage==7.2.7
coverage==7.3.0
# via -r requirements/coverage.in
dpcontracts==0.6.0
# via -r requirements/coverage.in
exceptiongroup==1.1.2 ; python_version < "3.11"
# via
# hypothesis (hypothesis-python/setup.py)
# pytest
execnet==2.0.0
execnet==2.0.2
# via pytest-xdist
fakeredis==2.16.0
fakeredis==2.17.0
# via -r requirements/coverage.in
iniconfig==2.0.0
# via pytest
lark==1.1.5
lark==1.1.7
# via -r requirements/coverage.in
libcst==1.0.1
# via -r requirements/coverage.in
mypy-extensions==1.0.0
# via
# black
# typing-inspect
numpy==1.25.0
numpy==1.25.2
# via
# -r requirements/coverage.in
# pandas
Expand All @@ -46,11 +46,11 @@ packaging==23.1
# pytest
pandas==2.0.3
# via -r requirements/coverage.in
pathspec==0.11.1
pathspec==0.11.2
# via black
pexpect==4.8.0
# via -r requirements/test.in
platformdirs==3.8.1
platformdirs==3.10.0
# via black
pluggy==1.2.0
# via pytest
Expand All @@ -70,7 +70,7 @@ pytz==2023.3
# via
# -r requirements/coverage.in
# pandas
pyyaml==6.0
pyyaml==6.0.1
# via libcst
redis==4.6.0
# via fakeredis
Expand Down
34 changes: 17 additions & 17 deletions requirements/fuzzing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
ansi2html==1.8.0
# via dash
async-timeout==4.0.2
async-timeout==4.0.3
# via redis
attrs==23.1.0
# via
Expand All @@ -17,17 +17,17 @@ black @ git+https://github.com/psf/black.git@eedfc3832290b3a32825b3c0f2dfa3f3d7e
# -r requirements/coverage.in
# hypofuzz
# hypothesis
certifi==2023.5.7
certifi==2023.7.22
# via requests
charset-normalizer==3.2.0
# via requests
click==8.1.4
click==8.1.6
# via
# -r requirements/coverage.in
# black
# flask
# hypothesis
coverage==7.2.7
coverage==7.3.0
# via
# -r requirements/coverage.in
# hypofuzz
Expand All @@ -46,15 +46,15 @@ exceptiongroup==1.1.2 ; python_version < "3.11"
# hypothesis
# hypothesis (hypothesis-python/setup.py)
# pytest
execnet==2.0.0
execnet==2.0.2
# via pytest-xdist
fakeredis==2.16.0
fakeredis==2.17.0
# via -r requirements/coverage.in
flask==2.2.5
# via dash
git+https://github.com/Zac-HD/hypofuzz.git
# via -r requirements/fuzzing.in
hypothesis[cli]==6.80.1
hypothesis[cli]==6.82.3
# via hypofuzz
idna==3.4
# via requests
Expand All @@ -64,7 +64,7 @@ itsdangerous==2.1.2
# via flask
jinja2==3.1.2
# via flask
lark==1.1.5
lark==1.1.7
# via -r requirements/coverage.in
libcst==1.0.1
# via
Expand All @@ -82,9 +82,9 @@ mypy-extensions==1.0.0
# via
# black
# typing-inspect
nest-asyncio==1.5.6
nest-asyncio==1.5.7
# via dash
numpy==1.25.0
numpy==1.25.2
# via
# -r requirements/coverage.in
# pandas
Expand All @@ -97,21 +97,21 @@ pandas==2.0.3
# via
# -r requirements/coverage.in
# hypofuzz
pathspec==0.11.1
pathspec==0.11.2
# via black
pexpect==4.8.0
# via -r requirements/test.in
platformdirs==3.8.1
platformdirs==3.10.0
# via black
plotly==5.15.0
plotly==5.16.0
# via dash
pluggy==1.2.0
# via pytest
psutil==5.9.5
# via hypofuzz
ptyprocess==0.7.0
# via pexpect
pygments==2.15.1
pygments==2.16.1
# via rich
pytest==7.4.0
# via
Expand All @@ -128,7 +128,7 @@ pytz==2023.3
# via
# -r requirements/coverage.in
# pandas
pyyaml==6.0
pyyaml==6.0.1
# via libcst
redis==4.6.0
# via fakeredis
Expand All @@ -138,7 +138,7 @@ requests==2.31.0
# hypofuzz
retrying==1.3.4
# via dash
rich==13.4.2
rich==13.5.2
# via hypothesis
six==1.16.0
# via
Expand All @@ -165,7 +165,7 @@ typing-inspect==0.9.0
# via libcst
tzdata==2023.3
# via pandas
urllib3==2.0.3
urllib3==2.0.4
# via requests
werkzeug==2.2.3
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exceptiongroup==1.1.2 ; python_version < "3.11"
# via
# hypothesis (hypothesis-python/setup.py)
# pytest
execnet==2.0.0
execnet==2.0.2
# via pytest-xdist
iniconfig==2.0.0
# via pytest
Expand Down
Loading

0 comments on commit e3848b0

Please sign in to comment.